-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hugo Geoffroy
committed
Jul 4, 2014
1 parent
13c0421
commit 402e92d
Showing
6 changed files
with
403 additions
and
378 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# ~/code/django-crucrudile/django_crucrudile/routes/callback.py | ||
|
||
from nose.tools import assert_true, assert_raises, assert_equal | ||
import mock | ||
|
||
from django_crucrudile.routes import Route, CallbackRoute | ||
|
||
|
||
class CallbackRouteTestCase: | ||
route_class = CallbackRoute | ||
mock_callback = None | ||
|
||
def setUp(self): | ||
self.route_class = type( | ||
'CallbackRoute', | ||
(self.route_class, ), | ||
{'name': "test name"} | ||
) | ||
self.mock_callback = mock.Mock() | ||
self.route = self.route_class( | ||
callback=self.mock_callback, name="name" | ||
) | ||
|
||
def test_subclasses_route(self): | ||
assert_true( | ||
issubclass(self.route_class, Route) | ||
) | ||
|
||
def test_init_requires_callback(self): | ||
assert_raises( | ||
ValueError, # No ``callback``... | ||
self.route_class | ||
) | ||
|
||
callback = mock.Mock() | ||
|
||
assert_equal( | ||
self.route_class(callback=callback).callback, | ||
callback | ||
) | ||
|
||
_route_class = type( | ||
'CallbackRoute', | ||
(self.route_class, ), | ||
{'callback': callback} | ||
) | ||
|
||
assert_equal( | ||
_route_class().callback, | ||
callback | ||
) | ||
|
||
def test_get_callback(self): | ||
assert_equal( | ||
self.route.get_callback(), | ||
self.mock_callback | ||
) |
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,94 @@ | ||
import mock | ||
import abc | ||
from nose.tools import assert_true, assert_false, assert_raises, assert_equal | ||
|
||
|
||
from django_crucrudile.entities.store import( | ||
provides, register_instances, register_class | ||
) | ||
class DecoratorTestMixin: | ||
decorator = None | ||
decorator_blank_args = [None] | ||
decorator_blank_kwargs = {} | ||
|
||
def test_callable(self): | ||
assert_true(callable(self.decorator)) | ||
|
||
def test_returns_callable(self): | ||
assert_true(callable(self.decorator( | ||
*self.decorator_blank_args, | ||
**self.decorator_blank_kwargs | ||
))) | ||
|
||
|
||
class ProvidesTestCase(DecoratorTestMixin): | ||
@property | ||
def decorator(self): | ||
return provides | ||
|
||
def test_calls_register_class(self): | ||
kwargs = {'key': 'value'} | ||
mock_provided_arg = mock.Mock() | ||
mock_router_class = mock.Mock() | ||
|
||
self.decorator(mock_provided_arg, | ||
**kwargs)(mock_router_class) | ||
|
||
assert_true( | ||
mock_router_class.register_class.called | ||
) | ||
|
||
called_args, called_kwargs = list( | ||
mock_router_class.register_class.call_args | ||
) | ||
|
||
assert_equal( | ||
called_args, | ||
(mock_provided_arg,) | ||
) | ||
assert_equal( | ||
called_kwargs, | ||
kwargs | ||
) | ||
|
||
|
||
class RegisterInstancesTestCase(DecoratorTestMixin): | ||
@property | ||
def decorator(self): | ||
return register_instances | ||
|
||
def test_patches_constructor(self): | ||
mock_store = mock.Mock() | ||
mock_store.register = mock_register = mock.Mock() | ||
mock_init = mock.Mock() | ||
mock_entity_class = type( | ||
'MockEntity', | ||
(), | ||
{'__init__': mock_init} | ||
) | ||
|
||
self.decorator(mock_store)(mock_entity_class) | ||
|
||
mock_entity_class() | ||
|
||
assert_true(mock_init.called) | ||
assert_true(mock_register.called) | ||
|
||
|
||
class RegisterClassTestCase(DecoratorTestMixin): | ||
@property | ||
def decorator(self): | ||
return register_class | ||
|
||
def test_calls_register_class(self): | ||
mock_store_class = mock.Mock() | ||
mock_reg_cls = mock_store_class.register_class | ||
mock_entity_class = mock.Mock() | ||
|
||
self.decorator(mock_store_class)(mock_entity_class) | ||
|
||
assert_true(mock_reg_cls.called) | ||
assert_equal( | ||
list(mock_reg_cls.call_args), | ||
[(mock_entity_class,), {}] | ||
) |
Oops, something went wrong.