def test_post_with_invalid_data(self): """test case to test create function with invalid data""" # serializer_data3 = json.loads(json.dumps(self.data3)) # for serializerdata3 in serializer_data3: serializer = SecmonDetailsSerializer(data=None) if serializer.valid(self.uuid): with self.assertRaises(TypeError): serializer.create(serializer.data)
def test_post_data(self): """test case to test create function with valid data""" serializer_data1 = json.loads(json.dumps(self.data1)) # for serializerdata1 in serializer_data1: serializer = SecmonDetailsSerializer(data=serializer_data1[0]) if serializer.valid(self.uuid1): serializer.create(serializer.data) else: print("serializer data is not valid") self.assertEqual(serializer_data1[0], serializer.data)
def setUp(self): self.uuid = generate_uuid() # Generate an id except for POST self.uuid1 = generate_uuid() # Generate id for update self.data = [{ 'id': self.uuid, 'scope_name': 'scope1', 'ip_address': '10.42.0.11', 'mac_address': '00:A0:C9:14:C8:29', 'port': 2055, }] self.data1 = [{ 'id': self.uuid1, 'scope_name': 'scope2', 'ip_address': '10.42.0.105', 'mac_address': '00:A0:C9:14:C8:14', 'port': 2254, }] self.data2 = [{ 'id': self.uuid, 'scope_name': 'scope3', 'ip_address': '10.42.0.103', 'mac_address': '00:A0:C9:14:C8:29', 'port': 2156, }] self.data3 = [{}] serializer_data = json.loads(json.dumps(self.data)) # for serializerdata in serializer_data: serializer = SecmonDetailsSerializer(data=serializer_data[0]) if serializer.valid(self.uuid): serializer.create(serializer.data) else: print("serializer is not valid in setup")
def test_invalid_serializer_without_pk(self): """test case to test valid function with invalid serializer without pk """ record = SecmonDetails.get(self.uuid) serializer = SecmonDetailsSerializer(record) self.assertEqual(serializer.valid(None), False)
def test_valid_serializer(self): """test case to test valid function with valid serializer""" serializer_data1 = json.loads(json.dumps(self.data1)) # for serializerdata1 in serializer_data1: serializer = SecmonDetailsSerializer(data=serializer_data1[0]) self.assertEqual(serializer.valid(self.uuid), True)