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 12, 2017
1 parent 564c4d8 commit 774948f
Show file tree
Hide file tree
Showing 21 changed files with 1,134 additions and 1,108 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/tests/conftest.py
show_missing = true
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
11 changes: 11 additions & 0 deletions autopush/tests/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()
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 774948f

Please sign in to comment.