-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for decorators. Improved the 'mutate' decorator.
- Loading branch information
1 parent
8192200
commit 6df5898
Showing
4 changed files
with
88 additions
and
6 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
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,60 @@ | ||
from unittest.case import TestCase | ||
|
||
from eventsourcing.domain.model.decorators import mutator | ||
|
||
|
||
class TestDecorators(TestCase): | ||
|
||
def test_mutate_without_arg(self): | ||
# Define an entity class, and event class, and a mutator function. | ||
|
||
class Entity(object): pass | ||
|
||
class Event(object): pass | ||
|
||
@mutator | ||
def mutate_entity(initial, event): | ||
"""Docstring for function mutate().""" | ||
raise NotImplementedError() | ||
|
||
# Check the function looks like the original. | ||
self.assertEqual(mutate_entity.__doc__, "Docstring for function mutate().") | ||
|
||
# Check it is capable of registering event handlers. | ||
@mutate_entity.register(Event) | ||
def mutate_with_event(initial, event): | ||
return Entity() | ||
|
||
# Check it dispatches on type of last arg. | ||
self.assertIsInstance(mutate_entity(None, Event()), Entity) | ||
|
||
# Check it handles unregistered types. | ||
with self.assertRaises(NotImplementedError): | ||
mutate_entity(None, None) | ||
|
||
def test_mutate_with_arg(self): | ||
# Define an entity class, and event class, and a mutator function. | ||
|
||
class Entity(object): pass | ||
|
||
class Event(object): pass | ||
|
||
@mutator(Entity) | ||
def mutate_entity(initial, event): | ||
"""Docstring for function mutate().""" | ||
raise NotImplementedError() | ||
|
||
# Check the function looks like the original. | ||
self.assertEqual(mutate_entity.__doc__, "Docstring for function mutate().") | ||
|
||
# Check it is capable of registering event handlers. | ||
@mutate_entity.register(Event) | ||
def mutate_with_event(initial, event): | ||
return initial() | ||
|
||
# Check it dispatches on type of last arg. | ||
self.assertIsInstance(mutate_entity(None, Event()), Entity) | ||
|
||
# Check it handles unregistered types. | ||
with self.assertRaises(NotImplementedError): | ||
mutate_entity(None, 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