예제 #1
0
 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 = NetFlowAssociationSerializer(data=None)
     if serializer.valid(self.uuid):
         with self.assertRaises(TypeError):
             serializer.create(serializer.data)
예제 #2
0
 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 = NetFlowAssociationSerializer(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)
예제 #3
0
 def test_update_id(self):
     """test case to test update function with id update"""
     obj = NetFlowAssociation.get(self.uuid)
     serializer_data1 = json.loads(json.dumps(self.data1))
     #        for serializerdata1 in serializer_data1:
     with self.assertRaises(IDUpdateNotPermitted):
         serializer = NetFlowAssociationSerializer(
             obj,
             data=serializer_data1[0],
             partial=True,
             context={'pk': self.uuid1})
         serializer.update(obj, serializer_data1[0])
예제 #4
0
 def test_put_Data(self):
     """test case to test update function with valid data"""
     obj = NetFlowAssociation.get(self.uuid)
     serializer_data2 = json.loads(json.dumps(self.data2))
     #        for serializerdata2 in serializer_data2:
     serializer = NetFlowAssociationSerializer(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)
예제 #5
0
    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,
            'originator_vm_id': '9662b088-74b4-40df-9769-c8f435d7f16f',
            'collector_id': 'Collector:33264640-302f-456c-ac0e-f06cc13a6a47',
            'direction': 'INGRESS',
            'policy_id': '72231461-aae9-4059-a5f1-7934ba969d3c',
            'scope_id': '04df6a37-cf8e-4511-9387-f78325336776',
        }]

        self.data1 = [{
            'id': self.uuid1,
            'originator_vm_id': '2372b088-74b4-40df-9769-c8f435d7f16a',
            'collector_id': 'Collector:56434640-302f-456c-ac0e-f06cc13a6a76',
            'direction': 'BOTH',
            'policy_id': '85671461-aae9-4059-a5f1-7934ba969b4d',
            'scope_id': '12cf6a37-cf8e-4511-9387-f78325336598',
        }]

        self.data2 = [{
            'id': self.uuid,
            'originator_vm_id': '2372b088-74b4-40df-9769-c8f435d7f16a',
            'collector_id': 'Collector:33264640-302f-456c-ac0e-f06cc13a6a47',
            'direction': 'EGRESS',
            'policy_id': '72231461-aae9-4059-a5f1-7934ba969d3c',
            'scope_id': '12cf6a37-cf8e-4511-9387-f78325336598',
        }]

        self.data3 = [{}]

        serializer_data = json.loads(json.dumps(self.data))
        #        for serializerdata in serializer_data:
        serializer = NetFlowAssociationSerializer(data=serializer_data[0])
        if serializer.valid(self.uuid):
            serializer.create(serializer.data)
예제 #6
0
 def test_invalid_serializer_without_pk(self):
     """test case to test valid function with invalid serializer without pk
     """
     record = NetFlowAssociation.get(self.uuid)
     serializer = NetFlowAssociationSerializer(record)
     self.assertEqual(serializer.valid(None), False)
예제 #7
0
 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 = NetFlowAssociationSerializer(data=serializer_data1[0])
     self.assertEqual(serializer.valid(self.uuid), True)