Example #1
0
 def test_get_by_natural_key(self):
     """
     Tests the get_by_natural_key method for an existing BottleField.
     """
     field = BottleField(field_name='test_field', field_type='CharField')
     field.save()
     saved_field = BottleField.objects.get_by_natural_key('test_field')
     self.assertEqual(saved_field, field)
Example #2
0
 def test_missing_embedded_doc(self):
     """
     Tests the clean method field_type is EmbeddedDocument but embedded_doc
     is undefined.
     """
     bottlefield = BottleField(field_name='test_field',
                               field_type='EmbeddedDocument')
     with six.assertRaisesRegex(self, ValidationError, 'An embedded doc must ' \
         + 'be defined for an EmbeddedDocument field.'):
         bottlefield.clean()
Example #3
0
 def test_misdefined_field_type(self):
     """
     Tests the clean method when an embedded_coc is defined by field_type
     is not EmbeddedDocument.
     """
     bottlefield = BottleField(
         field_name='test_field',
         field_type='CharField',
         embedded_doc=Bottle.objects.get_by_natural_key('post'))
     with six.assertRaisesRegex(self, ValidationError, 'If an embedded doc ' \
         + 'is defined, the field type must be EmbeddedDocument.'):
         bottlefield.clean()
Example #4
0
 def test_correct_field_type(self):
     """
     Tests the clean method field_type is not an EmbeddedDocument and an
     embedded_doc is undefined.
     """
     bottlefield = BottleField(
         field_name='test_field',
         field_type='CharField',
     )
     try:
         bottlefield.clean()
     except ValidationError:
         self.fail('BottleField raised ValidationError unexpectedly')
Example #5
0
 def test_with_embedded_doc(self):
     """
     Tests the clean method field_type is EmbeddedDocument and an
     embedded_doc is defined.
     """
     bottlefield = BottleField(
         field_name='test_field',
         field_type='EmbeddedDocument',
         embedded_doc=Bottle.objects.get_by_natural_key('post'))
     try:
         bottlefield.clean()
     except ValidationError:
         self.fail('BottleField raised ValidationError unexpectedly')