Esempio n. 1
0
 def test_auto_doc_type_mapping(self):
     person = Person(first_name="Simion", last_name="Baws")
     person.save()
     doc_type = person.get_es_doc_mapping()
     self.assertEqual(doc_type.first_name, person.first_name)
     self.assertEqual(doc_type.last_name, person.last_name)
     self.assertEqual(
         doc_type.full_name,
         u"{0} {1}".format(person.first_name, person.last_name)
     )
Esempio n. 2
0
def test_unique():
    person = Person(name='tim')
    person.save()

    validator = ModelValidator(Person(name='tim'))
    valid = validator.validate({'gender': 'M'})
    assert not valid
    assert validator.errors['name'] == 'must be a unique value'

    validator = ModelValidator(person)
    valid = validator.validate({'gender': 'M'})
    assert valid
    def test_has_no_changes(self):
        justin = Person(first_name='Justin', last_name='Trudeau')
        justin.save()

        serializer = PersonSerializer(justin, data={
            'first_name': 'Justin',
            'last_name': 'Trudeau',
            'partner': ''
        })

        serializer.is_valid()
        self.assertFalse(serializers.has_changes(serializer))
    def test_might_have_changes_returns_true(self):
        justin = Person(first_name='Justin', last_name='Trudeau')
        justin.save()

        serializer = PersonSerializer(justin, data={
            'first_name': 'Justin',
            'last_name': 'Trudeau2',
            'partner': ''
        })

        might_have_changes = serializers.might_have_changes(serializer)
        self.assertTrue(might_have_changes)
    def test_get_diff_data_for_exisiting_object_with_no_changes(self):
        justin = Person(first_name='Justin', last_name='Trudeau')
        justin.save()

        serializer = PersonSerializer(justin, data={
            'first_name': 'Justin',
            'last_name': 'Trudeau',
            'partner': ''
        })

        serializer.is_valid()

        diff = serializers.get_diff_data(serializer)

        self.assertEqual(diff, None)
    def test_export_one_to_many(self):
        hadrien = Person(first_name='Hadrien', last_name='Trudeau')
        xavier = Person(first_name='Xavier', last_name='Trudeau')
        ella_grace = Person(first_name='Ella-Grace', last_name='Trudeau')
        justin = Person(first_name='Justin', last_name='Trudeau')

        hadrien.save()
        xavier.save()
        ella_grace.save()
        justin.save()

        justin.children.add(hadrien)
        justin.children.add(xavier)
        justin.children.add(ella_grace)

        justin.save()

        serializer = PersonSerializer()
        rep = serializer.to_representation(instance=justin)
        children = rep['children']

        self.assertEqual(children, [u'Hadrien', u'Xavier', u'Ella-Grace'])