Skip to content

Commit

Permalink
Merge pull request devartis#7 from NafieAlhilaly/test/add-tests
Browse files Browse the repository at this point in the history
test: add tests and test assets
  • Loading branch information
NafieAlhilaly authored Jul 15, 2022
2 parents bbf29a6 + fd44285 commit f1cf88f
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
python -m pip install --upgrade pip
pip install flake8
flake8 . --ignore=E203,W605,W503 --count --show-source --max-complexity=16 --max-line-length=127 \
--statistics --exclude .git,__pycache__,__init__.py
--statistics --exclude .git,__pycache__,__init__.py,test
unittests:
runs-on: ubuntu-latest
steps:
Expand All @@ -35,5 +35,6 @@ jobs:
shell: bash
run: |
python -m pip install --upgrade pip
pip install pydantic
pip install pytest
pytest
2 changes: 1 addition & 1 deletion wallet/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
max-line-length= 127
ignore = E203,W605,W503
max-complexity= 16
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache,test
9 changes: 5 additions & 4 deletions wallet/Schemas/FieldProps.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from pydantic import BaseModel
from wallet.PassProps.Alignment import Alignment
from typing import Optional, Union


class FieldProps(BaseModel):
key: str
value: str
label: str | None = None
attributed_value: str | None = None
change_message: str | None = None
text_alignment: Alignment | str = Alignment.LEFT
label: Optional[str] = None
attributed_value: Optional[str] = None
change_message: Optional[str] = None
text_alignment: Optional[Union[Alignment, str]] = Alignment.LEFT

class Config:
arbitrary_types_allowed = True
Binary file added wallet/test/test_assets/_sea.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wallet/test/test_assets/_shark-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions wallet/test/test_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from wallet.PassStyles.StoreCard import StoreCard
from wallet.Pass import Pass
from pytest import raises

card = StoreCard()
pass_file = Pass(
**{
"pass_information": card,
"pass_type_identifier": "pass_type_identifier",
"organization_name": "organization_name",
"team_identifier": "team_identifier",
}
)

pass_file.logoText = "Sharks"

# charge_response.id is trackable via the Stripe dashboard
pass_file.serialNumber = "12345"
pass_file.description = "some discription"
pass_file.backgroundColor = "rgb(38, 93, 205)"
pass_file.foregroundColor = "rgb(255, 255, 255)"
pass_file.labelColor = "rgb(189, 189, 189)"

pass_file_as_json = b'{"storeCard": {"headerFields": [], "primaryFields": [], "secondaryFields": [], "backFields": [], "auxiliaryFields": []}, "description": "some discription", "formatVersion": 1, "organizationName": "organization_name", "passTypeIdentifier": "pass_type_identifier", "serialNumber": "12345", "teamIdentifier": "team_identifier", "backgroundColor": "rgb(38, 93, 205)", "foregroundColor": "rgb(255, 255, 255)", "labelColor": "rgb(189, 189, 189)", "logoText": "Sharks"}'
pass_file_manifest = b'{"pass.json": "3642041e506fd6a623a0bb00eb4fb8584e0264f9", "icon.png": "f6d49b2c2c03d2ef82e4d11841b60b58c7f18979", "logo.png": "f6d49b2c2c03d2ef82e4d11841b60b58c7f18979", "strip.png": "bf930d6ba371b42a461655c4b9719398e2068702"}'
shark_icon = "wallet/test/test_assets/_shark-icon.png"
sea_img = "wallet/test/test_assets/_sea.jpg"


def test_add_files_to_pass():

pass_file.add_file("icon.png", open(shark_icon, "rb"))
pass_file.add_file("logo.png", open(shark_icon, "rb"))

pass_file.add_file("strip.png", open(sea_img, "rb"))

files = [file for file in pass_file._files.keys()]

assert files[0] == "icon.png"
assert files[1] == "logo.png"
assert files[2] == "strip.png"


def test_add_bad_files_to_pass():
with raises(FileNotFoundError):
pass_file.add_file("icon.png", open("wallet/test/logo.png", "rb"))
with raises(FileNotFoundError):
pass_file.add_file("icon.png", open("", "rb"))


def test_create_pass_json():
pass_as_json = pass_file._create_pass_json()
assert pass_as_json == pass_file_as_json


def test_create_manifest():
pass_manifest = pass_file._create_manifest(pass_file_as_json)

assert pass_manifest == pass_file_manifest


def test_json_dict():
json_pass = pass_file.json_dict()

assert json_pass == {
"storeCard": {
"headerFields": [],
"primaryFields": [],
"secondaryFields": [],
"backFields": [],
"auxiliaryFields": [],
},
"description": "some discription",
"formatVersion": 1,
"organizationName": "organization_name",
"passTypeIdentifier": "pass_type_identifier",
"serialNumber": "12345",
"teamIdentifier": "team_identifier",
"backgroundColor": "rgb(38, 93, 205)",
"foregroundColor": "rgb(255, 255, 255)",
"labelColor": "rgb(189, 189, 189)",
"logoText": "Sharks",
}

0 comments on commit f1cf88f

Please sign in to comment.