forked from jsocol/django-adminplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial tests and fix a problem.
- Not great test coverage but get some of the specific points. - Fix one issue from the previous restructuring.
- Loading branch information
Showing
5 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
|
||
VERSION = (0, 2, 'dev') | ||
__version__ = '.'.join(map(str, VERSION)) | ||
__all__ = ['AdminSitePlus', 'site'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This module intentionally left blank. Only here for testing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from django.test import TestCase | ||
|
||
from adminplus.sites import AdminSitePlus | ||
|
||
|
||
class AdminPlusTests(TestCase): | ||
def test_decorator(self): | ||
"""register_view works as a decorator.""" | ||
site = AdminSitePlus() | ||
|
||
@site.register_view(r'foo/bar') | ||
def foo_bar(request): | ||
return 'foo-bar' | ||
|
||
urls = site.get_urls() | ||
assert any(u.resolve('foo/bar') for u in urls) | ||
|
||
def test_function(self): | ||
"""register_view works as a function.""" | ||
site = AdminSitePlus() | ||
|
||
def foo(request): | ||
return 'foo' | ||
site.register_view('foo', view=foo) | ||
|
||
urls = site.get_urls() | ||
assert any(u.resolve('foo') for u in urls) | ||
|
||
def test_path(self): | ||
"""Setting the path works correctly.""" | ||
site = AdminSitePlus() | ||
|
||
def foo(request): | ||
return 'foo' | ||
site.register_view('foo', view=foo) | ||
site.register_view('bar/baz', view=foo) | ||
site.register_view('baz-qux', view=foo) | ||
|
||
urls = site.get_urls() | ||
|
||
matches = lambda u: lambda p: p.resolve(u) | ||
foo_urls = filter(matches('foo'), urls) | ||
self.assertEqual(1, len(foo_urls)) | ||
bar_urls = filter(matches('bar/baz'), urls) | ||
self.assertEqual(1, len(bar_urls)) | ||
qux_urls = filter(matches('baz-qux'), urls) | ||
self.assertEqual(1, len(qux_urls)) | ||
|
||
def test_urlname(self): | ||
"""Set URL pattern names correctly.""" | ||
site = AdminSitePlus() | ||
|
||
@site.register_view('foo', urlname='foo') | ||
def foo(request): | ||
return 'foo' | ||
|
||
@site.register_view('bar') | ||
def bar(request): | ||
return 'bar' | ||
|
||
urls = site.get_urls() | ||
matches = lambda u: lambda p: p.resolve(u) | ||
foo_urls = filter(matches('foo'), urls) | ||
self.assertEqual(1, len(foo_urls)) | ||
self.assertEqual('foo', foo_urls[0].name) | ||
|
||
bar_urls = filter(matches('bar'), urls) | ||
self.assertEqual(1, len(bar_urls)) | ||
assert bar_urls[0].name is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters