def test_post_object(httpserver): obj = Object('dummy_type') obj.foo = 'foo' httpserver.expect_request( '/api/v3/dummy_types', method='POST', headers={ 'X-Apikey': 'dummy_api_key' }, data=json.dumps({'data': obj.to_dict()}), ).respond_with_json({ 'data': { 'id': 'dummy_id', 'type': 'dummy_type', 'attributes': { 'foo': 'foo', } } }) with new_client(httpserver) as client: obj = client.post_object('/dummy_types', obj=obj) assert obj.id == 'dummy_id'
def test_patch_object(httpserver): obj = Object('dummy_type', 'dummy_id', {'foo': 1, 'bar': 2}) obj.foo = 2 httpserver.expect_request( '/api/v3/dummy_types/dummy_id', method='PATCH', headers={'X-Apikey': 'dummy_api_key'}, data=json.dumps({'data': obj.to_dict(modified_attributes_only=True)}), ).respond_with_json({ 'data': { 'id': 'dummy_id', 'type': 'dummy_type', 'attributes': { 'foo': 2, } } }) with new_client(httpserver) as client: client.patch_object('/dummy_types/dummy_id', obj=obj)