Пример #1
0
 def test_create_new_category(self, category_get):
     category_get.side_effect = Category_model.DoesNotExist
     owner = User_factory.build()
     category = Category_factory.build()
     category = Category_serializer(category).data
     category.pop("owner")
     item = Item_factory.build()
     data = Item_serializer(item).data
     result = Item_serializer(data=data)
     is_valid = result.is_valid()
     self.assertTrue(is_valid, result.errors)
     item = result.save(category=category, owner=owner)
     self.assertTrue(isinstance(item, Item_model))
Пример #2
0
 def test_create(self, category_get):
     category = Category_factory.build()
     category_get.return_value = category
     category = Category_serializer(category).data
     item = Item_factory.build()
     data = Item_serializer(item).data
     result = Item_serializer(data=data)
     is_valid = result.is_valid()
     self.assertTrue(is_valid, result.errors)
     item = result.save(category=category)
     self.assertTrue(isinstance(item, Item_model))
     self.assertEqual(category["name"], item.category.name)
     category_get.assert_called_with(**category)