Пример #1
0
 def test_update(self):
     category = Category_factory.build()
     data = Category_serializer(category).data
     category_result = Category_serializer(category, data=data)
     is_valid = category_result.is_valid()
     self.assertTrue(is_valid, category_result.errors)
     category = category_result.save()
     self.assertTrue(isinstance(category, Category_model))
Пример #2
0
 def test_create(self):
     owner = User_factory.build()
     category = Category_factory.build()
     data = Category_serializer(category).data
     category_result = Category_serializer(data=data)
     is_valid = category_result.is_valid()
     self.assertTrue(is_valid, category_result.errors)
     category = category_result.save(owner=owner)
     self.assertTrue(isinstance(category, Category_model))
     self.assertEqual(category.owner.username, owner.username)
Пример #3
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))
Пример #4
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)
Пример #5
0
    def test_create_no_send_owner(self):
        """
		Cuano no se manda el owner de la categorua deberia de fallar
		con una exception de KeyError porque los datos no traiana
		el owner
		"""
        category = Category_factory.build()
        data = Category_serializer(category).data
        category_result = Category_serializer(data=data)
        is_valid = category_result.is_valid()
        self.assertTrue(is_valid, category_result.errors)
        with self.assertRaises(KeyError):
            category_result.save()
Пример #6
0
 def test_validate(self):
     category = Category_factory.build()
     data = Category_nested_serializer(category).data
     result = Category_nested_serializer(data=data)
     is_valid = result.is_valid()
     self.assertTrue(is_valid, result.errors)