Exemplo n.º 1
0
    def test_version_previous_to_django(self):
        """
        Tests overriding dynamically tabs via get_tabs.
        """
        added_fieldset = ('Social', {
            'fields': ('website', 'twitter', 'facebook')
        })
        added_inline = InterviewInline

        class TestBandAdmin(BandAdmin):
            def get_tabs(self, request, obj=None):
                tabs = self.tabs
                tab_overview = self.tab_overview + (added_fieldset, )
                tab_ressources = self.tab_ressources + (added_inline, )
                tabs = [('Overview', tab_overview),
                        ('Ressources', tab_ressources)]
                self.tabs = tabs
                return super(TestBandAdmin, self).get_tabs(request, obj)

        original_admin = BandAdmin(Band, self.site)
        self.assertNotIn(added_fieldset, original_admin.get_fieldsets(request))
        self.assertNotIn(added_inline, original_admin.tab_ressources)
        admin = TestBandAdmin(Band, self.site)
        inlines_classes = []
        inlines = admin.get_inline_instances(request)
        for inline in inlines:
            inlines_classes.append(inline.__class__)
        self.assertIn(added_inline, inlines_classes)
        self.assertIn(added_fieldset, admin.get_fieldsets(request))
        self.assertIn(added_fieldset, admin.get_fieldsets(request))
Exemplo n.º 2
0
    def test_dynamically_add_fieldsets_inlines_to_tabs(self):
        """
        Tests overriding dynamically tabs via get_tabs.
        """
        added_fieldset = ('Social', {
            'fields': ('website', 'twitter', 'facebook')
        })
        added_inline = InterviewInline

        class TestBandAdmin(BandAdmin):
            def get_tabs(self, request, obj=None):
                tabs = self.tabs
                tab_overview = self.tab_overview + (added_fieldset, )
                tab_ressources = self.tab_ressources + (added_inline, )
                tabs = [
                    ('Overview', tab_overview),
                    ('Ressources', tab_ressources)
                ]
                self.tabs = tabs
                return super(TestBandAdmin, self).get_tabs(request, obj)

        original_admin = BandAdmin(Band, self.site)
        self.assertNotIn(added_fieldset, original_admin.get_fieldsets(request))
        self.assertNotIn(added_inline, original_admin.tab_ressources)
        admin = TestBandAdmin(Band, self.site)
        inlines_classes = []
        inlines = admin.get_inline_instances(request)
        for inline in inlines:
            inlines_classes.append(inline.__class__)
        self.assertIn(added_inline, inlines_classes)
Exemplo n.º 3
0
 def test_fieldsets_inline_attribute_populated(self):
     """
     Tests if self.inlines and self.fieldsets are correcly populated from
     the self.tabs attribute.
     """
     admin = BandAdmin(Band, self.site)
     self.assertIsNone(admin.fieldsets)
     self.assertEqual(0, len(admin.inlines))
     fieldsets = admin.get_fieldsets(request)
     inlines = admin.get_inline_instances(request)
     self.assertNotEqual(0, len(fieldsets))
     self.assertNotEqual(0, len(inlines))
     self.assertNotEqual(0, len(admin.fieldsets))
     self.assertNotEqual(0, len(admin.inlines))
Exemplo n.º 4
0
 def test_fieldsets_inline_attribute_populated(self):
     """
     Tests if self.inlines and self.fieldsets are correcly populated from
     the self.tabs attribute.
     """
     admin = BandAdmin(Band, self.site)
     self.assertIsNone(admin.fieldsets)
     self.assertEqual(0, len(admin.inlines))
     fieldsets = admin.get_fieldsets(request)
     inlines = admin.get_inline_instances(request)
     self.assertNotEqual(0, len(fieldsets))
     self.assertNotEqual(0, len(inlines))
     self.assertNotEqual(0, len(admin.fieldsets))
     self.assertNotEqual(0, len(admin.inlines))