def setUp(self):
     self.a_client_decorator = ClientDecorator()
     self.a_client = Person()
     self.a_client_decorator.decorate(self.a_client)
     self.a_bank_account_decorator = BankAccountDecorator(self.a_client, '1234 5 - 6')
     #test doubles won't work given type checking rules, using classic
     self.a_machine = Machine()
class CreditAnalystDecoratorSpec(unittest.TestCase):

    def setUp(self):
        self.a_credit_analyst_decorator = CreditAnalystDecorator('12345-6')
        #test doubles won't work given type checking rules, using classic
        self.a_person = Person()
        self.an_account = BankAccountDecorator('1234567-8')

    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_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_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)
        #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_changes_its_loan_limit(self):
        self.a_credit_analyst_decorator.change_loan_limit(100000)
        self.a_credit_analyst_decorator.loan_limit |should| be(100000)
class bankAccountDecoratorSpec(unittest.TestCase):
    def setUp(self):
        self.a_bank_account_decorator = BankAccountDecorator('12345-6')
        #test doubles won't work given type checking rules, using classic
        self.a_machine = Machine()

    def it_decorates_a_machine(self):
        #should work
        self.a_bank_account_decorator.decorate(self.a_machine)
        self.a_bank_account_decorator.decorated | should | be(self.a_machine)
        self.a_bank_account_decorator.decorated | should | have(1).decorators
        #should fail
        non_machine = 'I am not a machine'
        (self.a_bank_account_decorator.decorate,
         non_machine) | should | throw(AssociationError)
class bankAccountDecoratorSpec(unittest.TestCase):

    def setUp(self):
        self.a_bank_account_decorator = BankAccountDecorator('12345-6')
        #test doubles won't work given type checking rules, using classic
        self.a_machine = Machine()

    def it_decorates_a_machine(self):
        #should work
        self.a_bank_account_decorator.decorate(self.a_machine)
        self.a_bank_account_decorator.decorated |should| be(self.a_machine)
        self.a_bank_account_decorator.decorated |should| have(1).decorators
        #should fail
        non_machine = 'I am not a machine'
        (self.a_bank_account_decorator.decorate, non_machine) |should| throw(AssociationError)
 def it_check_associations_with_bank_account_and_credit_analyst(self):
     a_client = Person()
     a_client_decorator = ClientDecorator()
     a_client_decorator.decorate(a_client)
     an_account = BankAccountDecorator(a_client, '12345-6')
     #set the rule base
     RuleManager.rule_base = BankSystemRuleBase()
     #
     an_account = BankAccountDecorator(a_client, '12345-6')
     an_analyst = CreditAnalystDecorator('abcde-f')
     (LoanRequest, 'I am not an account', 123,
      an_analyst) | should | throw(AssociationError)
     (LoanRequest, an_account, 123,
      'I am not an analyst') | should | throw(AssociationError)
     (LoanRequest, an_account, 123,
      an_analyst) | should_not | throw(AssociationError)
 def setUp(self):
     #set the rule base
     RuleManager.rule_base = BankSystemRuleBase()
     #
     self.a_credit_analyst_decorator = CreditAnalystDecorator('12345-6')
     #test doubles won't work given type checking rules, using classic
     self.a_person = Person()
     self.an_account = BankAccountDecorator('1234567-8')
def and_an_individual_customer_with_account_number_account_number_asks_for_a_personal_loan(
        step, account_number):
    world.a_machine = Machine()
    a_client = Person()
    a_client_decorator = ClientDecorator()
    a_client_decorator.decorate(a_client)
    world.account = BankAccountDecorator(a_client, account_number)
    world.account.average_credit = 2501
    world.account.decorate(world.a_machine)
Example #8
0
 def it_check_association_with_loan_request(self):
     a_client_decorator = ClientDecorator()
     a_client = Person()
     a_client_decorator.decorate(a_client)
     #set the rule base
     RuleManager.rule_base = BankSystemRuleBase()
     #
     (Loan, 'I am not a loan request') | should | throw(AssociationError)
     a_credit_analyst_decorator = CreditAnalystDecorator('12345-6')
     an_account = BankAccountDecorator(a_client, '1234567-8')
     a_loan_request = LoanRequest(an_account, 7000,
                                  a_credit_analyst_decorator)
     (Loan, a_loan_request) | should_not | throw(AssociationError)
 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)
class BankAccountDecoratorSpec(unittest.TestCase):

    def setUp(self):
        self.a_bank_account_decorator = BankAccountDecorator('12345-6')
        #test doubles won't work given type checking rules, using classic
        self.a_machine = Machine()

    def it_decorates_a_machine(self):
        #should work
        self.a_bank_account_decorator.decorate(self.a_machine)
        self.a_bank_account_decorator.decorated |should| be(self.a_machine)
        self.a_bank_account_decorator.decorated |should| have(1).decorators
        #should fail
        decorate, _, _ = self.a_bank_account_decorator.decorate('I am not a machine')
        decorate |should| equal_to(False)

    def it_registers_a_credit(self):
        self.a_bank_account_decorator.balance = 100
        self.a_bank_account_decorator.register_credit(50)
        self.a_bank_account_decorator.balance |should| equal_to(150)

    def it_sends_a_message_to_the_account_holder(self):
        message = 'This is a message'
        self.a_bank_account_decorator.send_message_to_account_holder(message) |should| equal_to(message)
class bankAccountDecoratorSpec(unittest.TestCase):
    def setUp(self):
        self.a_bank_account_decorator = BankAccountDecorator("12345-6")
        # test doubles won't work given type checking rules, using classic
        self.a_machine = Machine()

    def it_decorates_a_machine(self):
        # should work
        self.a_bank_account_decorator.decorate(self.a_machine)
        self.a_bank_account_decorator.decorated | should | be(self.a_machine)
        self.a_bank_account_decorator.decorated | should | have(1).decorators
        # should fail
        non_machine = "I am not a machine"
        (self.a_bank_account_decorator.decorate, non_machine) | should | throw(AssociationError)

    def it_registers_a_credit(self):
        self.a_bank_account_decorator.balance = 100
        self.a_bank_account_decorator.register_credit(50)
        self.a_bank_account_decorator.balance | should | equal_to(150)

    def it_sends_a_message_to_the_account_holder(self):
        message = "This is a message"
        self.a_bank_account_decorator.send_message_to_account_holder(message) | should | equal_to(message)
 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)
class CreditAnalystDecoratorSpec(unittest.TestCase):
    def setUp(self):
        # set the rule base
        RuleManager.rule_base = BankSystemRuleBase()
        #
        self.a_credit_analyst_decorator = CreditAnalystDecorator("12345-6")
        # test doubles won't work given type checking rules, using classic
        self.a_person = Person()
        self.a_client = Person()
        a_client_decorator = ClientDecorator()
        a_client_decorator.decorate(self.a_client)
        self.an_account = BankAccountDecorator(self.a_client, "1234567-8")

    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_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_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_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_changes_its_loan_limit(self):
        self.a_credit_analyst_decorator.change_loan_limit(100000)
        self.a_credit_analyst_decorator.loan_limit | should | be(100000)
 def setUp(self):
     self.a_credit_analyst_decorator = CreditAnalystDecorator('12345-6')
     #test doubles won't work given type checking rules, using classic
     self.a_person = Person()
     self.an_account = BankAccountDecorator('1234567-8')
 def setUp(self):
     self.a_credit_analyst_decorator = CreditAnalystDecorator('12345-6')
     #test doubles won't work given type checking rules, using classic
     self.a_person = Person()
     self.an_account = BankAccountDecorator('1234567-8')
 def setUp(self):
     self.a_bank_account_decorator = BankAccountDecorator('12345-6')
     #test doubles won't work given type checking rules, using classic
     self.a_machine = Machine()
 def setUp(self):
     self.a_bank_account_decorator = BankAccountDecorator("12345-6")
     # test doubles won't work given type checking rules, using classic
     self.a_machine = Machine()
class CreditAnalystDecoratorSpec(unittest.TestCase):
    def setUp(self):
        self.a_credit_analyst_decorator = CreditAnalystDecorator('12345-6')
        #test doubles won't work given type checking rules, using classic
        self.a_person = Person()
        self.an_account = BankAccountDecorator('1234567-8')

    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_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_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)
        #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_changes_its_loan_limit(self):
        self.a_credit_analyst_decorator.change_loan_limit(100000)
        self.a_credit_analyst_decorator.loan_limit | should | be(100000)
class BankAccountDecoratorSpec(unittest.TestCase):

    def setUp(self):
        self.a_client_decorator = ClientDecorator()
        self.a_client = Person()
        self.a_client_decorator.decorate(self.a_client)
        self.a_bank_account_decorator = BankAccountDecorator(self.a_client, '1234 5 - 6')
        #test doubles won't work given type checking rules, using classic
        self.a_machine = Machine()

    def it_decorates_a_machine(self):
        #should work
        self.a_bank_account_decorator.decorate(self.a_machine)
        self.a_bank_account_decorator.decorated |should| be(self.a_machine)
        self.a_bank_account_decorator.decorated |should| have(1).decorators

    def it_registers_a_credit(self):
        self.a_bank_account_decorator.balance = 100
        self.a_bank_account_decorator.register_credit(50)
        self.a_bank_account_decorator.balance |should| equal_to(150)

    def it_sends_a_message_to_the_account_holder(self):
        message = 'This is a message'
        self.a_bank_account_decorator.send_message_to_account_holder(message) |should| equal_to(message)

    def it_check_the_client(self):
        #should work
        self.a_client |should| have(1).decorators
        self.a_bank_account_decorator.client |should| be(self.a_client)

    def it_realize_a_banking(self):
        self.a_bank_account_decorator.decorate(self.a_machine)
        self.a_bank_account_decorator.deposit(100)
        self.a_bank_account_decorator.draw(25)
        self.a_bank_account_decorator.average_credit |should| be(75)