def test_update_id(self): """test case to test update function with id update""" obj = ClassificationObject.get(self.uuid) serializer_data1 = json.loads(json.dumps(self.data1)) # for serializerdata1 in serializer_data1: with self.assertRaises(IDUpdateNotPermitted): serializer = ClassificationObjectSerializer( obj, data=serializer_data1[0], partial=True, context={'pk': self.uuid1}) serializer.update(obj, serializer_data1[0])
def test_put_Data(self): """test case to test update function with valid data""" obj = ClassificationObject.get(self.uuid) serializer_data2 = json.loads(json.dumps(self.data2)) # for serializerdata2 in serializer_data2: serializer = ClassificationObjectSerializer(obj, data=serializer_data2[0], partial=True, context={'pk': self.uuid}) serializer.update(obj, serializer_data2[0]) serializerdata2 = serializer_data2[0] serializerdata2['id'] = self.uuid self.assertEqual(serializerdata2, serializer.data)
def test_get_no_record(self): """Test case to fetch a ClassificationObject with invalid id.""" with self.assertRaises(ResourceNotFound): ClassificationObject.get(generate_uuid())
def test_invalid_serializer_without_pk(self): """test case to test valid function with invalid serializer without pk """ record = ClassificationObject.get(self.uuid) serializer = ClassificationObjectSerializer(record) self.assertEqual(serializer.valid(None), False)
def tearDown(self): record = ClassificationObject.get(self.uuid) record.delete() if self._testMethodName.startswith('test_post_data'): record1 = ClassificationObject.get(self.uuid1) record1.delete()