def it_creates_a_loan_request(self):
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.create_loan_request(
         self.an_account, 10000)
     self.a_person.input_area | should | contain('1234567-8')
 def it_moves_the_loan_to_an_account(self):
     # prepares the person Node
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     # prepares a Loan
     loan_request = LoanRequest(self.an_account, 7000, self.a_credit_analyst_decorator)
     self.a_credit_analyst_decorator.decorated.output_area[self.an_account.number] = loan_request
     self.a_credit_analyst_decorator.create_loan(loan_request)
     # should go wrong
     passing_a_wrong_key = "wrong key"
     (self.a_credit_analyst_decorator.move_loan_to_account, passing_a_wrong_key, self.an_account) | should | throw(
         KeyError
     )
     passing_a_non_account = "I am not an account"
     (
         self.a_credit_analyst_decorator.move_loan_to_account,
         self.an_account.number,
         passing_a_non_account,
     ) | should | throw(ContractError)
     # prepares the account
     a_machine = Machine()
     self.an_account.decorate(a_machine)
     # should work
     loan_key = self.a_credit_analyst_decorator.register
     self.a_credit_analyst_decorator.move_loan_to_account(loan_key, self.an_account)
     self.an_account.decorated.input_area | should | include(loan_key)
     self.an_account.balance | should | equal_to(7000)
     self.an_account.client | should | be(self.a_client)
 def it_decorates_a_person(self):
     #should fail
     (self.a_credit_analyst_decorator.decorate, self.a_person) |should| throw(AssociationError)
     #should work
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorated |should| be(self.a_person)
     self.a_credit_analyst_decorator.decorated |should| have(2).decorators
 def it_decorates_a_person(self):
     #should fail
     (self.a_credit_analyst_decorator.decorate,
      self.a_person) | should | throw(AssociationError)
     #should work
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorated | should | be(self.a_person)
     self.a_credit_analyst_decorator.decorated | should | have(2).decorators
 def it_decorates_a_person(self):
     # should fail
     decorate, _, _ = self.a_credit_analyst_decorator.decorate(self.a_person)
     decorate | should | equal_to(False)
     # should work
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorated | should | be(self.a_person)
     self.a_person | should | have(2).decorators
 def it_analyses_a_loan_request(self):
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     # Stub removed, from now on Node really transfers resources internally
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.an_account.average_credit = 5000
     # should approve
     self.a_credit_analyst_decorator.create_loan_request(self.an_account, 10000)
     self.a_credit_analyst_decorator.analyse(self.an_account.number)
     self.a_credit_analyst_decorator.decorated.output_area["1234567-8"].approved | should | equal_to(True)
     # should refuse
     self.a_credit_analyst_decorator.create_loan_request(self.an_account, 50000)
     self.a_credit_analyst_decorator.analyse(self.an_account.number)
     self.a_credit_analyst_decorator.decorated.output_area["1234567-8"].approved | should | equal_to(False)
 def it_creates_a_loan(self):
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     loan_request = LoanRequest(self.an_account, 7000, self.a_credit_analyst_decorator)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorated.output_area[self.an_account.number] = loan_request
     #creates a machine to be decorated by the account - will need to check its processing_area
     a_machine = Machine()
     self.an_account.decorate(a_machine)
     #creates the loan
     self.a_credit_analyst_decorator.create_loan(loan_request)
     #loan key is the analyst's register
     self.a_credit_analyst_decorator.decorated.output_area.values() |should| have_at_least(1).loan
     self.a_credit_analyst_decorator.decorated.output_area |should| include(self.a_credit_analyst_decorator.register)
 def it_creates_a_loan(self):
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     loan_request = LoanRequest(self.an_account, 7000, self.a_credit_analyst_decorator)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorated.output_area[self.an_account.number] = loan_request
     #creates a machine to be decorated by the account - will need to check its processing_area
     a_machine = Machine()
     self.an_account.decorate(a_machine)
     #creates the loan
     self.a_credit_analyst_decorator.create_loan(loan_request)
     #given that I am using datetime to generate the key, I cannot access the newly
     #created loan through its key
     self.a_credit_analyst_decorator.decorated.output_area.values() |should| have_at_least(1).loan
class AttendantDecoratorSpec(unittest.TestCase):

    def setUp(self):
        self.an_employee_decorator = EmployeeDecorator()
        self.an_attendant_decorator = AttendantDecorator()
        self.an_attendant = Person()

    def it_decorates_a_person(self):
        self.an_employee_decorator.decorate(self.an_attendant)
        self.an_attendant_decorator.decorate(self.an_attendant)
        self.an_attendant_decorator.decorated |should| be(self.an_attendant)
        self.an_attendant |should| have(2).decorators

    def it_gets_a_check(self):
        #Receiving a check
        self.an_employee_decorator.decorate(self.an_attendant)
        self.an_attendant_decorator.decorate(self.an_attendant)
        a_check = Check(id_="123", account_number="1234-5", value=10.0)
        #           Verifing check attributes
        #-------------------------------------------------
        a_check.id_ |should| equal_to("123")
        a_check.account_number |should| equal_to("1234-5")
        a_check.value |should| equal_to(10.0)
        #-------------------------------------------------

    def it_discount_a_check(self):
        #Discounting a check, it should work!
        a_machine = Machine()
        a_client = Person()
        a_client_decorator = ClientDecorator()
        a_client_decorator.decorate(a_client)
        a_bank_account_decorator = BankAccountDecorator(a_client,"1234-5")
        a_bank_account_decorator.decorate(a_machine)
        a_bank_account_decorator.deposit(100)
        a_bank_account_decorator.average_credit |should| equal_to(100)
        a_check = Check(id_="123", account_number="1234-5", value=10)
        self.an_attendant_decorator.discount_check(a_check)
        a_bank_account_decorator.average_credit |should| equal_to(90)
        #It should fail!
        other_bank_account_decorator = BankAccountDecorator(a_client,"1235-5")
        other_bank_account_decorator.average_credit = 100
        other_bank_account_decorator.decorate(a_machine)
        a_check = Check(id_="123", account_number="1235-5", value=110)
        (self.an_attendant_decorator.discount_check, a_check) |should| throw(InsuficientFunds)
        other_bank_account_decorator.average_credit |should| equal_to(100)

    def tearDown(self):
        BankAccountDecorator = []
class AttendantDecoratorSpec(unittest.TestCase):
    def setUp(self):
        self.an_employee_decorator = EmployeeDecorator()
        self.an_attendant_decorator = AttendantDecorator()
        self.an_attendant = Person()

    def it_decorates_a_person(self):
        self.an_employee_decorator.decorate(self.an_attendant)
        self.an_attendant_decorator.decorate(self.an_attendant)
        self.an_attendant_decorator.decorated | should | be(self.an_attendant)
        self.an_attendant | should | have(2).decorators

    def it_gets_a_check(self):
        #Receiving a check
        self.an_employee_decorator.decorate(self.an_attendant)
        self.an_attendant_decorator.decorate(self.an_attendant)
        a_check = Check(id_="123", account_number="1234-5", value=10.0)
        #           Verifing check attributes
        #-------------------------------------------------
        a_check.id_ | should | equal_to("123")
        a_check.account_number | should | equal_to("1234-5")
        a_check.value | should | equal_to(10.0)
        #-------------------------------------------------

    def it_discount_a_check(self):
        #Discounting a check, it should work!
        a_machine = Machine()
        a_client = Person()
        a_client_decorator = ClientDecorator()
        a_client_decorator.decorate(a_client)
        a_bank_account_decorator = BankAccountDecorator(a_client, "1234-5")
        a_bank_account_decorator.decorate(a_machine)
        a_bank_account_decorator.deposit(100)
        a_bank_account_decorator.average_credit | should | equal_to(100)
        a_check = Check(id_="123", account_number="1234-5", value=10)
        self.an_attendant_decorator.discount_check(a_check)
        a_bank_account_decorator.average_credit | should | equal_to(90)
        #It should fail!
        other_bank_account_decorator = BankAccountDecorator(a_client, "1235-5")
        other_bank_account_decorator.average_credit = 100
        other_bank_account_decorator.decorate(a_machine)
        a_check = Check(id_="123", account_number="1235-5", value=110)
        (self.an_attendant_decorator.discount_check,
         a_check) | should | throw(InsuficientFunds)
        other_bank_account_decorator.average_credit | should | equal_to(100)

    def tearDown(self):
        BankAccountDecorator = []
 def it_creates_a_loan(self):
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     loan_request = LoanRequest(self.an_account, 7000,
                                self.a_credit_analyst_decorator)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorated.output_area[
         self.an_account.number] = loan_request
     #creates a machine to be decorated by the account - will need to check its processing_area
     a_machine = Machine()
     self.an_account.decorate(a_machine)
     #creates the loan
     self.a_credit_analyst_decorator.create_loan(loan_request)
     #given that I am using datetime to generate the key, I cannot access the newly
     #created loan through its key
     self.a_credit_analyst_decorator.decorated.output_area.values(
     ) | should | have_at_least(1).loan
 def it_analyses_a_loan_request(self):
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     #Stub removed, from now on Node really transfers resources internally
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.an_account.average_credit = 5000
     #should approve
     self.a_credit_analyst_decorator.create_loan_request(
         self.an_account, 10000)
     self.a_credit_analyst_decorator.analyse(self.an_account.number)
     self.a_credit_analyst_decorator.decorated.output_area[
         '1234567-8'].approved | should | equal_to(True)
     #should refuse
     self.a_credit_analyst_decorator.create_loan_request(
         self.an_account, 50000)
     self.a_credit_analyst_decorator.analyse(self.an_account.number)
     self.a_credit_analyst_decorator.decorated.output_area[
         '1234567-8'].approved | should | equal_to(False)
Exemplo n.º 13
0
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)
        self.an_employee_decorator.decorated | should | have(1).decorators
        #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')
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)
        self.an_employee_decorator.decorated |should| have(1).decorators
        #should fail
        decorate,_,_ = self.an_employee_decorator.decorate('I am not a person')
        decorate |should| equal_to(False)

    def it_generates_register(self):
        self.an_employee_decorator.generate_register('123456-7')
        self.an_employee_decorator.register |should| equal_to('123456-7')
 def setUp(self):
     self.an_employee_decorator = EmployeeDecorator()
     self.an_attendant_decorator = AttendantDecorator()
     self.an_attendant = Person()
 def setUp(self):
     self.an_employee_decorator = EmployeeDecorator()
     self.an_attendant_decorator = AttendantDecorator()
     self.an_attendant = Person()
def given_i_am_a_registered_credit_analyst(step):
    world.a_person = Person()
    an_employee_decorator = EmployeeDecorator()
    an_employee_decorator.decorate(world.a_person)
    world.credit_analyst = CreditAnalystDecorator("09876-5")
    world.credit_analyst.decorate(world.a_person)
 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_creates_a_loan_request(self):
     an_employee_decorator = EmployeeDecorator()
     an_employee_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.decorate(self.a_person)
     self.a_credit_analyst_decorator.create_loan_request(self.an_account, 10000)
     self.a_person.input_area | should | contain("1234567-8")
Exemplo n.º 20
0
 def setUp(self):
     self.an_employee_decorator = EmployeeDecorator()
     #test doubles won't work given type checking rules, using classic
     self.a_person = Person()
def given_i_am_a_registered_credit_analyst(step):
    world.a_person = Person()
    an_employee_decorator = EmployeeDecorator()
    an_employee_decorator.decorate(world.a_person)
    world.credit_analyst = CreditAnalystDecorator('09876-5')
    world.credit_analyst.decorate(world.a_person)