forked from ratem/eispatterns
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
Showing
2 changed files
with
57 additions
and
0 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,31 @@ | ||
from should_dsl import should | ||
from domain.base.decorator import Decorator | ||
from domain.node.person import Person | ||
from domain.resource.operation import operation | ||
from domain.supportive.rule import rule | ||
from domain.supportive.association_error import AssociationError | ||
|
||
|
||
class EmployeeDecorator(Decorator): | ||
'''A general purpose Employee decorator''' | ||
def __init__(self): | ||
Decorator.__init__(self) | ||
self.description = "Supplies the basis for representing employes" | ||
|
||
def generate_register(self, register): | ||
''' generates the register number for the employee ''' | ||
self.register = register | ||
|
||
def decorate(self, decorated): | ||
try: | ||
EmployeeDecorator.rule_should_be_person_instance(decorated) | ||
except: | ||
raise AssociationError('Person instance expected, instead %s passed' % type(decorated)) | ||
self.decorated = decorated | ||
|
||
@classmethod | ||
@rule('association') | ||
def rule_should_be_person_instance(self, decorated): | ||
''' Decorated object should be a Person ''' | ||
decorated |should| be_instance_of(Person) | ||
|
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,26 @@ | ||
import unittest | ||
from should_dsl import should | ||
from domain.node.person import Person | ||
from domain.supportive.association_error import AssociationError | ||
from bank_system.decorators.employee_decorator import EmployeeDecorator | ||
|
||
|
||
class EmployeeDecoratorSpec(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.an_employee_decorator = EmployeeDecorator() | ||
#test doubles won't work given type checking rules, using classic | ||
self.a_person = Person() | ||
|
||
def it_decorates_a_person(self): | ||
#should work | ||
self.an_employee_decorator.decorate(self.a_person) | ||
self.an_employee_decorator.decorated |should| be(self.a_person) | ||
#should fail | ||
non_person = 'I am not a person' | ||
(self.an_employee_decorator.decorate, non_person) |should| throw(AssociationError) | ||
|
||
def it_generates_register(self): | ||
self.an_employee_decorator.generate_register('123456-7') | ||
self.an_employee_decorator.register |should| equal_to('123456-7') | ||
|