def test_products_models_serialize_method(self, product_mock): # Arrange _id = str(uuid4()) id = str(uuid4()) product_mock.query.filter.return_value.first.return_value = [] products = Product( id=_id, active=False, name='Nescau', cost_values=10.15, unit_box=5, weight_unit=0.550, validity="2021-12-31", sku='09ub124ibbi413', description='Descrição...', category_line_id=id, supplier_id=id, on_create=datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), on_update=datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) # Action response = products.serialize() # Assertions self.assertEqual(type(response), dict) self.assertIsInstance(products, Product) self.assertEqual( { 'id': _id, 'active': False, 'name': 'Nescau', 'cost_values': 10.15, 'unit_box': 5, 'weight_unit': 0.550, 'validity': "2021-12-31", 'sku': '09ub124ibbi413', 'description': 'Descrição...', 'category_line_id': id, 'supplier_id': id, 'on_create': datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), 'on_update': datetime.datetime.now().strftime("%Y-%m-%d %H:%M") }, response)
def test_products_should_be_serialized(self): # Arrange product = Product(id='1827169419', name='name', cost_values='cost_values', unit_per_box='123', weight_per_unit='weight_per_unit', shelf_life='shelf_life', sku='sku', description='description') # Action json = product.serialize() # Assert self.assertEqual(json['id'], '1827169419') self.assertEqual(json['name'], 'name') self.assertEqual(json['cost_values'], 'cost_values') self.assertEqual(json['unit_per_box'], 123) self.assertEqual(json['weight_per_unit'], 'weight_per_unit') self.assertEqual(json['shelf_life'], 'shelf_life') self.assertEqual(json['sku'], 'sku') self.assertEqual(json['description'], 'description')