Skip to content

Commit

Permalink
Adding test for the get_tabs method, testing issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
omji committed Aug 9, 2016
1 parent d000f75 commit 6a55c76
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
Binary file modified .coverage
Binary file not shown.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ env:
- DJANGO=1.7
- DJANGO=1.8.3
install:
- pip install -q Django==$DJANGO --use-mirrors
- pip install flake8 --use-mirrors
- pip install -q Django==$DJANGO
- pip install flake8
- pip install coveralls
- pip install -q -e . --use-mirrors
- pip install -q -e .
before_script:
- "flake8 tabbed_admin"
script:
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
],
)
12 changes: 9 additions & 3 deletions tabbed_admin/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@


class Band(models.Model):
STYLE_ROCK = 1
STYLE_FUNK = 2
STYLE_JAZZ = 3
STYLE_OVERRIDE = 4

name = models.CharField(max_length=100)
bio = models.TextField(blank=True, null=True)
style = models.CharField(max_length=100, choices=(
(1, 'Rock'),
(2, 'Funk'),
(3, 'Jazz')
(STYLE_ROCK, 'Rock'),
(STYLE_FUNK, 'Funk'),
(STYLE_JAZZ, 'Jazz'),
(STYLE_OVERRIDE, 'Override')
))
agent = models.CharField(max_length=100, blank=True, null=True)
phone = models.CharField(max_length=100, blank=True, null=True)
Expand Down
26 changes: 26 additions & 0 deletions tabbed_admin/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ class TestBandAdmin(BandAdmin):
for inline in inlines:
self.assertIn(inline, admin.formatted_tabs['inlines'])

def test_get_tabs_overrides_tabs_attribute(self):
"""
Tests if get_tabs method successfully overrides the self.tabs and returns it.
"""
single_tab = [('Overview', BandAdmin.tab_overview)]
class TestBandAdmin(BandAdmin):
def get_tabs(self, request, obj=None):
"""
Returns the tabs attribute.
"""
tabs = self.tabs
if obj is not None and obj.style == Band.STYLE_OVERRIDE:
tabs = single_tab
self.tabs = tabs
return super(TestBandAdmin, self).get_tabs(request, obj)

admin = TestBandAdmin(Band, self.site)
band = Band.objects.create(name="Test band", style=Band.STYLE_JAZZ)
tabs = admin.get_tabs(request, band)
self.assertEqual(len(tabs), 2)
self.assertNotEqual(tabs, single_tab)
band.style = Band.STYLE_OVERRIDE
tabs = admin.get_tabs(request, band)
self.assertEqual(len(tabs), 1)
self.assertEqual(tabs, single_tab)

def test_dynamically_add_fieldsets_inlines_to_tabs(self):
"""
Tests overriding dynamically tabs via get_tabs.
Expand Down

0 comments on commit 6a55c76

Please sign in to comment.