def serialize_action_api(self, root_path, domain): # Action index index_path = root_path.add('action') index_data = json.loads(index_path.fetch()) for action_data in index_data: new_url = self.update_url(action_data['implementation_url'], domain) action_data['implementation_url'] = new_url index_path.save(canonical_json_dumps(index_data)) # Individual actions for action in Action.objects.all(): # Action action_path = root_path.add('action', action.name) action_data = json.loads(action_path.fetch()) new_url = self.update_url(action_data['implementation_url'], domain) action_data['implementation_url'] = new_url action_json = canonical_json_dumps(action_data) action_path.save(action_json) # Action implementation action_path.add('implementation', action.implementation_hash).save()
def verify_signatures(self, api_client, expected_count=None): res = api_client.get('/api/v1/recipe/signed/') assert res.status_code == 200 signed_data = res.json() if expected_count is not None: assert len(signed_data) == expected_count for recipe_and_signature in signed_data: recipe = recipe_and_signature['recipe'] expected_signature = recipe_and_signature['signature']['signature'] data = canonical_json_dumps(recipe).encode() actual_signature = fake_sign([data])[0]['signature'] assert actual_signature == expected_signature
def test_it_escapes_quotes_properly(self): data = {'message': 'It "works", I think'} dumped = canonical_json_dumps(data) assert dumped == r'{"message":"It \"works\", I think"}' json.loads(dumped)
def test_it_works_with_euro_signs(self): data = {'USD': '$', 'EURO': '€'} assert canonical_json_dumps(data) == r'{"EURO":"\u20ac","USD":"$"}'
def test_it_works(self): data = {'a': 1, 'b': 2} assert canonical_json_dumps(data) == '{"a":1,"b":2}'
def serialize_client_api(self, root_path): client = self.client() client_data = ClientSerializer(client).data client_json = canonical_json_dumps(client_data) root_path.add('classify_client').save(client_json)
def test_it_works_with_euro_signs(self): data = {"USD": "$", "EURO": "€"} assert canonical_json_dumps(data) == r'{"EURO":"\u20ac","USD":"$"}'
def render(self, data, media_type=None, renderer_context=None): return canonical_json_dumps(data).encode()
def render(self, data, media_type=None, renderer_context=None): return canonical_json_dumps(data).encode()
def test_it_escapes_quotes_properly(self): data = {"message": 'It "works", I think'} dumped = canonical_json_dumps(data) assert dumped == r'{"message":"It \"works\", I think"}' json.loads(dumped)
def test_it_works_with_euro_signs(self): data = {"USD": "$", "EURO": "€"} assert canonical_json_dumps(data) == r'{"EURO":"\u20ac","USD":"$"}'
def test_it_works(self): data = {"a": 1, "b": 2} assert canonical_json_dumps(data) == '{"a":1,"b":2}'