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 10, 2017
1 parent fbf9ad8 commit c65e511
Show file tree
Hide file tree
Showing 19 changed files with 1,120 additions and 1,107 deletions.
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 c65e511

Please sign in to comment.