Browse Source

Enhance code coverage

master
Lucidiot 2 years ago
parent
commit
0134ed4641
No known key found for this signature in database GPG Key ID: AE3F7205692FA205
  1. 12
      urbantz/tests/test_delivery.py
  2. 6
      urbantz/tests/test_full.py
  3. 20
      urbantz/tests/test_utils.py
  4. 2
      urbantz/utils.py

12
urbantz/tests/test_delivery.py

@ -2,6 +2,7 @@ from unittest import TestCase
from unittest.mock import patch, call
from datetime import datetime
from urbantz import Delivery
from urbantz.delivery import Location
from urbantz.exceptions import APIError
@ -81,3 +82,14 @@ class TestDelivery(TestCase):
excinfo.exception,
APIError({'message': 'API returned an empty payload'}),
)
def test_empty_eta(self):
self.delivery.eta_margin = None
self.delivery.eta_rounding = None
self.delivery.arrival_time = None
self.assertIsNone(self.delivery.eta)
def test_empty_location(self):
loc = Location()
with self.assertRaises(AttributeError):
loc.coordinates

6
urbantz/tests/test_full.py

@ -19,7 +19,8 @@ class TestFull(TestCase):
def setUpClass(cls):
super().setUpClass()
with open(os.path.join(FOLDER, 'test_payload.json')) as f:
cls.delivery = Delivery.fromJSON(json.load(f))
cls.payload = json.load(f)
cls.delivery = Delivery.fromJSON(cls.payload)
def test_types(self):
self.assertIsNone(self.delivery.tracking_code)
@ -144,6 +145,8 @@ class TestFull(TestCase):
])
self.assertEqual(len(self.delivery.items), 1)
item = self.delivery.items[0]
self.assertEqual(repr(item), '<Item cafe1>')
self.assertEqual(item.toJSON(), self.payload['items'][0])
self.assertFalse(item.damage_confirmed)
self.assertListEqual(item.damage_pictures, [])
self.assertEqual(item.status, "DELIVERED")
@ -200,3 +203,4 @@ class TestFull(TestCase):
datetime(2019, 2, 3, 7, 56, 47, 814000),
]
)
self.assertEqual(self.delivery.toJSON(), self.payload)

20
urbantz/tests/test_utils.py

@ -80,3 +80,23 @@ class TestUtils(TestCase):
self.assertIn('last_name', d)
del d.last_name
self.assertNotIn('lastName', d)
with self.assertRaises(AttributeError):
del d.last_name
with self.assertRaises(KeyError):
del d['lastName']
def test_dictobject_edge_case(self):
d = DictObject(self.test_data)
def errored_delitem(*args, **kwargs):
raise KeyError
d.__delitem__ = errored_delitem
del d.lastName
self.assertEqual(d.lastName, 'Norris')
def test_dictobject_reverse(self):
self.assertEqual(
DictObject(self.test_data).toJSON(),
self.test_data,
)

2
urbantz/utils.py

@ -50,7 +50,7 @@ class DictObject(JSONSerializable, dict):
return
except KeyError:
pass
super().__delattr__(self, name)
super().__delattr__(name)
def __delitem__(self, name):
try:

Loading…
Cancel
Save