def test_new_entity(self): uuid = '3d46cd74-a3af-4afd-af94-512b5cee1ef0' product = Product() product.id = uuid product.name = u'Defender' product.category = u'Cars' product.price = 40000.00 state = EntityState(product) data = dict(state.data_for_insert()) assert data['ProductID'] == uuid assert data['ProductName'] == 'Defender' assert data['Category'] == 'Cars' assert data['Price'] == 40000.00 assert state.dirty == [] product.name = 'Toyota Carola' product.price = 32500.00 data = dict(state.data_for_update()) assert data['ProductName'] == 'Toyota Carola' assert data['Category'] == 'Cars' assert data['Price'] == 32500.00
def test_create(self): # Post call ########################################################### def request_callback(request): payload = json.loads(request.body) assert 'OData-Version' in request.headers, 'OData-Version header not in request' assert 'ProductID' not in payload, 'Payload contains primary key' assert '@odata.type' in payload, 'Payload did not contain @odata.type' payload['ProductID'] = 1 resp_body = payload headers = {} return requests.codes.created, headers, json.dumps(resp_body) responses.add_callback( responses.POST, Product.__odata_url__(), callback=request_callback, content_type='application/json', ) ####################################################################### new_product = Product() new_product.name = u'New Test Product' new_product.category = u'Category #1' new_product.price = 34.5 Service.save(new_product) assert new_product.id is not None, 'Product.id is not set'
def test_create_with_primary_key(self): # Post call ########################################################### def request_callback(request): payload = json.loads(request.body) self.assertEqual(payload.get('ProductID'), 55, msg='Did not receive ProductID') resp_body = payload headers = {} return requests.codes.created, headers, json.dumps(resp_body) new_product = Product() new_product.id = 55 new_product.name = u'New Test Product' new_product.category = u'Category #1' new_product.price = 34.5 with responses.RequestsMock() as rsps: rsps.add_callback( rsps.POST, Product.__odata_url__(), callback=request_callback, content_type='application/json', ) Service.save(new_product) assert new_product.id is not None, 'Product.id is not set'