def hasJson(self, key, value=''): response = json.loads(self.container.make('Response')) if isinstance(key, dict): for item_key, value in key.items(): if not Dot().dot(item_key, response, False) == value: return False return True return Dot().dot(key, response, False)
def assertHasJson(self, key, value): response = json.loads(self.container.make('Response')) if isinstance(key, dict): for item_key, key_value in key.items(): assert Dot().dot(item_key, response, False) == key_value else: assert Dot().dot(key, response, False) == value, "Key '{}' with the value of '{}' could not find a match in {}".format(key, value, response) return self
def assertJsonContains(self, key, value): response = json.loads(self.container.make('Response')) if not isinstance(response, list): raise ValueError("This method can only be used if the response is a list of elements.") found = False for element in response: if Dot().dot(key, element, False): assert Dot().dot(key, element, False) found = True if not found: raise AssertionError("Could not find a key of: {} that had the value of {}".format(key, value)) return self
def test_dict_dot_works_for_deep_dictionaries(self): dictionary = { 'storage': { 'drivers': { 'disk': { 'location': { 'uploading': 'uploads/' } } } } } self.assertEqual( Dot().dict_dot('storage.drivers.disk.location', dictionary)['uploading'], 'uploads/')
def test_dot_dict(self): assert Dot().dict_dot('async.driver', {'async': { 'driver': 'me' }}, 'you') == 'me'
def test_dict_dot_returns_value(self): assert Dot().dict_dot('s3.test', {'s3': { 'test': 'value' }}, '') == 'value'
def test_dot_dict(self): self.assertEqual( Dot().dict_dot('async.driver', {'async': { 'driver': 'me' }}, 'you'), 'me')
def test_dict_dot_returns_value(self): self.assertEqual( Dot().dict_dot('s3.test', {'s3': { 'test': 'value' }}, ''), 'value')