示例#1
0
    def test_get_related_resource(self):
        gfk_field = GenericForeignKeyField(
            {
                Note: NoteResource,
                Quote: QuoteResource
            }, 'nofield')

        definition_1 = Definition.objects.create(
            word='toast', content="Cook or brown (food, esp. bread or cheese)")

        # Test that you can not link to a model that does not have a resource
        with self.assertRaises(TypeError):
            gfk_field.get_related_resource(definition_1)

        note_1 = Note.objects.create(
            title='All aboard the rest train',
            content='Sometimes it is just better to lorem ipsum')

        self.assertTrue(
            isinstance(gfk_field.get_related_resource(note_1), NoteResource))
示例#2
0
    def test_get_related_resource(self):
        gfk_field = GenericForeignKeyField({
            Note: NoteResource,
            Quote: QuoteResource
        }, 'nofield')

        definition_1 = Definition.objects.create(
            word='toast',
            content="Cook or brown (food, esp. bread or cheese)"
        )

        # Test that you can not link to a model that does not have a resource
        with self.assertRaises(TypeError):
            gfk_field.get_related_resource(definition_1)

        note_1 = Note.objects.create(
            title='All aboard the rest train',
            content='Sometimes it is just better to lorem ipsum'
        )

        self.assertTrue(isinstance(gfk_field.get_related_resource(note_1), NoteResource))