Skip to content

Commit

Permalink
Merge pull request #35 from mbaechtold/mba/add-more-tests
Browse files Browse the repository at this point in the history
Add more tests (increases test coverage from 57% to 65%).
  • Loading branch information
mbaechtold committed Jul 10, 2016
2 parents 281c9c8 + d82cf8a commit 810c2a0
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
@@ -0,0 +1,6 @@
[run]
source = passbook
branch = 1

[report]
omit = *test*
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -61,4 +61,20 @@ Certificate is available @ http://developer.apple.com/certificationauthority/App

It can be exported from KeyChain into a .pem (e.g. wwdr.pem).

## Testing

You can run the tests with `py.test` or optionally with coverage support
(install `pytest-cov` first):

py.test --cov

You can also generate a HTML report of the coverage:

py.test --cov-report html

You can run the tests against multiple versions of Python by running `tox`
which you need to install first.

## Credits

Developed by [devartis](http://www.devartis.com).
Binary file added passbook/test/static/white_square.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions passbook/test/test_passbook.py
Expand Up @@ -8,19 +8,79 @@
import simplejson as json
from passbook.models import Barcode, BarcodeFormat, Pass, StoreCard

from path import Path
cwd = Path(__file__).parent


def create_shell_pass(barcodeFormat=BarcodeFormat.CODE128):
cardInfo = StoreCard()
cardInfo.addPrimaryField('name', 'John Doe', 'Name')
stdBarcode = Barcode('test barcode', barcodeFormat, 'alternate text')
passfile = Pass(cardInfo, organizationName='Org Name', passTypeIdentifier='Pass Type ID', teamIdentifier='Team Identifier')
passfile.barcode = stdBarcode
passfile.serialNumber = '1234567'
passfile.description = 'A Sample Pass'
return passfile


def test_basic_pass():
passfile = create_shell_pass()
assert passfile.formatVersion == 1
assert passfile.barcode.format == BarcodeFormat.CODE128
assert len(passfile._files) == 0

passfile_json = passfile.json_dict()
assert passfile_json is not None
assert passfile_json['suppressStripShine'] == False
assert passfile_json['formatVersion'] == 1
assert passfile_json['passTypeIdentifier'] == 'Pass Type ID'
assert passfile_json['serialNumber'] == '1234567'
assert passfile_json['teamIdentifier'] == 'Team Identifier'
assert passfile_json['organizationName'] == 'Org Name'
assert passfile_json['description'] == 'A Sample Pass'


def test_manifest_creation():
passfile = create_shell_pass()
manifest_json = passfile._createManifest(passfile._createPassJson())
manifest = json.loads(manifest_json)
assert 'pass.json' in manifest


def test_header_fields():
passfile = create_shell_pass()
passfile.passInformation.addHeaderField('header', 'VIP Store Card', 'Famous Inc.')
pass_json = passfile.json_dict()
assert pass_json['storeCard']['headerFields'][0]['key'] == 'header'
assert pass_json['storeCard']['headerFields'][0]['value'] == 'VIP Store Card'
assert pass_json['storeCard']['headerFields'][0]['label'] == 'Famous Inc.'


def test_secondary_fields():
passfile = create_shell_pass()
passfile.passInformation.addSecondaryField('secondary', 'VIP Store Card', 'Famous Inc.')
pass_json = passfile.json_dict()
assert pass_json['storeCard']['secondaryFields'][0]['key'] == 'secondary'
assert pass_json['storeCard']['secondaryFields'][0]['value'] == 'VIP Store Card'
assert pass_json['storeCard']['secondaryFields'][0]['label'] == 'Famous Inc.'


def test_back_fields():
passfile = create_shell_pass()
passfile.passInformation.addBackField('back1', 'VIP Store Card', 'Famous Inc.')
pass_json = passfile.json_dict()
assert pass_json['storeCard']['backFields'][0]['key'] == 'back1'
assert pass_json['storeCard']['backFields'][0]['value'] == 'VIP Store Card'
assert pass_json['storeCard']['backFields'][0]['label'] == 'Famous Inc.'


def test_auxiliary_fields():
passfile = create_shell_pass()
passfile.passInformation.addAuxiliaryField('aux1', 'VIP Store Card', 'Famous Inc.')
pass_json = passfile.json_dict()
assert pass_json['storeCard']['auxiliaryFields'][0]['key'] == 'aux1'
assert pass_json['storeCard']['auxiliaryFields'][0]['value'] == 'VIP Store Card'
assert pass_json['storeCard']['auxiliaryFields'][0]['label'] == 'Famous Inc.'


def test_code128_pass():
Expand All @@ -47,3 +107,21 @@ def test_pdf_417_pass():
assert thawedJson['barcode']['format'] == BarcodeFormat.PDF417
assert thawedJson['barcodes'][0]['format'] == BarcodeFormat.PDF417


def test_files():
passfile = create_shell_pass()
passfile.addFile('icon.png', open(cwd / 'static/white_square.png', 'rb'))
assert len(passfile._files) == 1
assert 'icon.png' in passfile._files

manifest_json = passfile._createManifest(passfile._createPassJson())
manifest = json.loads(manifest_json)
assert '170eed23019542b0a2890a0bf753effea0db181a' == manifest['icon.png']

passfile.addFile('logo.png', open(cwd / 'static/white_square.png', 'rb'))
assert len(passfile._files) == 2
assert 'logo.png' in passfile._files

manifest_json = passfile._createManifest(passfile._createPassJson())
manifest = json.loads(manifest_json)
assert '170eed23019542b0a2890a0bf753effea0db181a' == manifest['logo.png']
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,2 +1,3 @@
M2Crypto>=0.21.1
pytest
path.py
5 changes: 3 additions & 2 deletions setup.py
@@ -1,7 +1,6 @@
from distutils.core import setup

version = __import__('passbook').__version__
install_requires = open('requirements.txt').readlines(),

setup(
name='Passbook',
Expand All @@ -16,7 +15,9 @@

download_url='http://pypi.python.org/packages/source/P/Passbook/Passbook-%s.tar.gz' % version,

install_requires=install_requires,
install_requires=[
'M2Crypto >= 0.21.1',
],

classifiers = [
'Development Status :: 3 - Alpha',
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Expand Up @@ -2,5 +2,7 @@
envlist = py27

[testenv]
deps=pytest
deps =
pytest
path.py
commands=py.test

0 comments on commit 810c2a0

Please sign in to comment.