Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
feat: move tests to pytest
Browse files Browse the repository at this point in the history
Issue #1039
  • Loading branch information
jrconlin committed Oct 11, 2017
1 parent fbf9ad8 commit a26cc11
Show file tree
Hide file tree
Showing 23 changed files with 1,141 additions and 1,111 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ omit =
autopush/gcdump.py
autopush/webpush_server.py
autopush/tests/test_webpush_server.py
autopush/conftest.py
show_missing = true
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ DEPS =
HERE = $(shell pwd)
PTYPE=pypy
REQS=requirements.txt
TESTER=nose
NOSE_ARGS=--with-coverage --cover-package=autopush
PYTEST_ARGS=--cov=autopush --cov-report=xml
TEST_ARGS=$($(shell echo $(TESTER) | tr a-z A-Z)_ARGS)
ifneq ($(PTYPE), python)
# avoids pycrypto build issues w/ pypy + libgmp-dev or libmpir-dev
export with_gmp=no
Expand All @@ -19,7 +23,7 @@ BUILD_DIRS = bin build deps include lib lib64 lib_pypy lib-python\
src site-packages .tox .eggs .coverage


.PHONY: all build test coverage lint clean clean-env
.PHONY: all build test coverage lint clean clean-env foo

all: build

Expand Down Expand Up @@ -63,7 +67,7 @@ test: $(BIN)/tox ddb
$(BIN)/tox

coverage: $(BIN)/tox
$(BIN)/tox -- --with-coverage --cover-package=autopush
$(BIN)/tox -- $(TEST_ARGS)

lint: $(BIN)/flake8
$(BIN)/flake8 autopush
11 changes: 11 additions & 0 deletions autopush/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from autopush.tests import setUp, tearDown


def pytest_configure(config):
"""Called before testing begins"""
setUp()


def pytest_unconfigure(config):
"""Called after all tests run and warnings displayed"""
tearDown()
2 changes: 1 addition & 1 deletion autopush/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def fetch_messages(
def fetch_timestamp_messages(
self,
uaid, # type: uuid.UUID
timestamp=None, # type: Optional[int]
timestamp=None, # type: Optional[int or str]
limit=10, # type: int
):
# type: (...) -> Tuple[Optional[int], List[WebPushNotification]]
Expand Down
44 changes: 22 additions & 22 deletions autopush/tests/test_cryptokey.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from nose.tools import (eq_, ok_, assert_raises)
import pytest

from autopush.crypto_key import CryptoKey, CryptoKeyException

Expand All @@ -15,47 +15,47 @@ class CryptoKeyTestCase(unittest.TestCase):

def test_parse(self):
ckey = CryptoKey(self.valid_key)
eq_(ckey.get_keyid("p256dh"),
{"keyid": "p256dh",
"dh": "BDw9T0eImd4ax818VcYqDK_DOhcuDswKero"
"YyNkdhYmygoLSDlSiWpuoWYUSSFxi25cyyNTR5k9Ny93DzZc0UI4"})
eq_(ckey.get_label("p256ecdsa"),
assert ckey.get_keyid("p256dh") == {
"keyid": "p256dh",
"dh": "BDw9T0eImd4ax818VcYqDK_DOhcuDswKero"
"YyNkdhYmygoLSDlSiWpuoWYUSSFxi25cyyNTR5k9Ny93DzZc0UI4"}
assert ckey.get_label("p256ecdsa") == (
"BF92zdI_AKcH5Q31_Rr-04bPqOHU_Qg6lAawHbvfQrY"
"xV_vIsAsHSyaiuyfofvxT8ZVIXccykd4V2Z7iJVfreT8")
ok_(ckey.get_keyid("missing") is None)
ok_(ckey.get_label("missing") is None)
assert ckey.get_keyid("missing") is None
assert ckey.get_label("missing") is None

def test_parse_and_get_label(self):
eq_(CryptoKey.parse_and_get_label(self.valid_key, "p256ecdsa"),
assert CryptoKey.parse_and_get_label(self.valid_key, "p256ecdsa") == (
"BF92zdI_AKcH5Q31_Rr-04bPqOHU_Qg6lAawHbvfQrY"
"xV_vIsAsHSyaiuyfofvxT8ZVIXccykd4V2Z7iJVfreT8")
ok_(CryptoKey.parse_and_get_label(self.valid_key, "missing") is None)
ok_(CryptoKey.parse_and_get_label("invalid key", "missing") is None)
assert CryptoKey.parse_and_get_label(self.valid_key, "missing") is None
assert CryptoKey.parse_and_get_label("invalid key", "missing") is None

def test_parse_invalid(self):
with assert_raises(CryptoKeyException) as ex:
with pytest.raises(CryptoKeyException) as ex:
CryptoKey("invalid key")
eq_(ex.exception.message, "Invalid Crypto Key value")
assert ex.value.message == "Invalid Crypto Key value"

def test_parse_different_order(self):
ckey = CryptoKey(self.valid_key)
ckey2 = CryptoKey(','.join(self.valid_key.split(',')[::-1]))
ok_(ckey.get_keyid("p256dh"), ckey2.get_keyid("p256dh"))
ok_(ckey.get_label("p256ecdsa") is not None)
ok_(ckey.get_label("p256ecdsa"), ckey2.get_label("p256ecdsa"))
assert ckey.get_keyid("p256dh") == ckey2.get_keyid("p256dh")
assert ckey.get_label("p256ecdsa") is not None
assert ckey.get_label("p256ecdsa") == ckey2.get_label("p256ecdsa")

def test_parse_lenient(self):
ckey = CryptoKey(self.valid_key.replace('"', ''))
str = ckey.to_string()
ckey2 = CryptoKey(str)
ok_(ckey.get_keyid("p256dh"), ckey2.get_keyid("p256dh"))
ok_(ckey.get_label("p256ecdsa") is not None)
ok_(ckey.get_label("p256ecdsa"), ckey2.get_label("p256ecdsa"))
assert ckey.get_keyid("p256dh") == ckey2.get_keyid("p256dh")
assert ckey.get_label("p256ecdsa") is not None
assert ckey.get_label("p256ecdsa") == ckey2.get_label("p256ecdsa")

def test_string(self):
ckey = CryptoKey(self.valid_key)
str = ckey.to_string()
ckey2 = CryptoKey(str)
ok_(ckey.get_keyid("p256dh"), ckey2.get_keyid("p256dh"))
ok_(ckey.get_label("p256ecdsa") is not None)
ok_(ckey.get_label("p256ecdsa"), ckey2.get_label("p256ecdsa"))
assert ckey.get_keyid("p256dh") == ckey2.get_keyid("p256dh")
assert ckey.get_label("p256ecdsa") is not None
assert ckey.get_label("p256ecdsa") == ckey2.get_label("p256ecdsa")
Loading

0 comments on commit a26cc11

Please sign in to comment.