Skip to content

Commit

Permalink
Created Employee decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
ratem committed Apr 14, 2011
1 parent 344be30 commit 0e2686a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bank_system/decorators/employee_decorator.py
@@ -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)

26 changes: 26 additions & 0 deletions bank_system/spec/employee_decorator_spec.py
@@ -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')

0 comments on commit 0e2686a

Please sign in to comment.