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')
예제 #2
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_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)
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 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.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')
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 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)