I have a test set up as this:
Suppose I have a class like this, where in the middle I may or may not update a class variable:
class Supplier():
cache_dict = {}
@classmethod
def get_available_suppliers(cls):
...
if cls.cache_dict.get('time') < end_date:
cls.cache_dict = cls._fetch_new_cache(...)
...
return available_suppliers
In my test I want to assert that variable did get or did not get updated. How should I go about testing that? Here's what I have so far, but doesn't seem to work.
def test_cache_refreshed(self):
self.mock_cache_dict = mock.patch('Suppliers.cache_list' new_callable= mock.PropertyMock).start()
self.mock_cache_dict.return_value = {'time': '2018/01/01' ...}
Config.get_available_suppliers()
#line below does not work, still have the same return_value as before
self.assertEqual(self.mock_cache_dict.return_value, {'time': '2018/01/08' ...})
#this way does not work either, as it's comparing PropertyMock to a datetime.
self.assertEqual(self.mock_cache_dict, {'time': '2018/01/08'...})
Please let me know how I should do this.
Aucun commentaire:
Enregistrer un commentaire