def test_cache_result_used_if_already_exists(self, cache): # mock an existing entry key = cache.generate_key(Country, only_id=True, code='NZ') cache._XRefResolver__cache[key] = 'oops!' id = cache.resolve(Country, only_id=True, code='NZ') assert id == 'oops!'
def test_results_are_also_stored_in_internal_cache(self, cache): cache.clear_cache() id = cache.resolve(Country, only_id=True, code='NG') key = cache.generate_key(Country, only_id=True, code='NG') assert id != None \ and id == cache._XRefResolver__cache[key]
def test_fails_when_filter_matches_multiple_records(self, cache): with pytest.raises(exc.MultipleResultsFound): id = cache.resolve(State, code='BC')
def test_ok_when_filter_matches_single_record(self, cache): id = cache.resolve(Country, code='NG') assert id != None and type(id) is uuid.UUID
def test_returns_id_when_only_id_TRUE(self, cache): cache.clear_cache() country_id = cache.resolve(Country, only_id=True, code='NG') assert country_id \ and type(country_id) is uuid.UUID
def test_returns_object_when_only_id_FALSE(self, cache): cache.clear_cache() country = cache.resolve(Country, only_id=False, code='NG') assert country is not None \ and country.id != 0 \ and isinstance(country, Country)