Exemplo n.º 1
0
 def test_field_validates_valid_data(self):
     nodes = [factory.make_Node() for _ in range(3)]
     # Create other nodes.
     [factory.make_Node() for _ in range(3)]
     field = InstanceListField(model_class=Node, field_name="system_id")
     input_data = [node.system_id for node in nodes]
     self.assertItemsEqual(
         input_data, [node.system_id for node in field.clean(input_data)])
Exemplo n.º 2
0
 def test_field_ignores_duplicates(self):
     nodes = [factory.make_Node() for _ in range(2)]
     # Create other nodes.
     [factory.make_Node() for _ in range(3)]
     field = InstanceListField(model_class=Node, field_name='system_id')
     input_data = [node.system_id for node in nodes] * 2
     self.assertItemsEqual(
         set(input_data),
         [node.system_id for node in field.clean(input_data)])
Exemplo n.º 3
0
 def test_field_rejects_invalid_data(self):
     nodes = [factory.make_Node() for _ in range(3)]
     field = InstanceListField(model_class=Node, field_name='system_id')
     error = self.assertRaises(ValidationError, field.clean,
                               [node.system_id
                                for node in nodes] + ['unknown'])
     self.assertEqual(['Unknown node(s): unknown.'], error.messages)