Ejemplo n.º 1
0
 def it_check_decoration_rules(self):
     a_person = Person()
     a_decorator = SomeDecorator()
     passed, approved_rules, refused_rules = RuleManager.get_instance().check_decoration_rules(SomeDecorator, a_person)
     passed |should| be(True)
     approved_rules |should| contain('''Associated object should be instance of Person''')
     refused_rules |should| be(None)
     SomeDecorator.decoration_rules = ['xxxxx']
     (RuleManager.get_instance().check_decoration_rules, SomeDecorator, a_person) |should| throw(AttributeError)
     #tear down
     SomeDecorator.decoration_rules = ['should_be_instance_of_person']
Ejemplo n.º 2
0
 def __init__(self, account, value, analyst):
     WorkItem.__init__(self)
     self.value = value
     self.approved = False
     self.datetime = datetime.now()
     if not RuleManager.get_instance().check_rule('should_be_instance_of_bank_account', account):
        raise AssociationError('Bank Account instance expected, instead %s passed' % type(account))
     self.account = account
     if not RuleManager.get_instance().check_rule('should_be_instance_of_credit_analyst', analyst):
         raise AssociationError('Credit Analyst instance expected, instead %s passed' % type(analyst))
     self.analyst = analyst
 def __init__(self, account, value, analyst):
     WorkItem.__init__(self)
     self.value = value
     self.approved = False
     self.datetime = datetime.now()
     if not RuleManager.get_instance().check_rule('should_be_instance_of_bank_account', account):
        raise AssociationError('Bank Account instance expected, instead %s passed' % type(account))
     self.account = account
     if not RuleManager.get_instance().check_rule('should_be_instance_of_credit_analyst', analyst):
         raise AssociationError('Credit Analyst instance expected, instead %s passed' % type(analyst))
     self.analyst = analyst
Ejemplo n.º 4
0
 def decorate(self, decoration_candidate):
     passed, approved_rules, refused_rules = RuleManager.get_instance(
     ).check_decoration_rules(self, decoration_candidate)
     if passed:
         self.decorated = decoration_candidate
         decoration_candidate.decorate(self)
     return passed, approved_rules, refused_rules
Ejemplo n.º 5
0
 def it_decorates(self):
     a_decorator = FakeDecorator()
     a_person = Person()
     a_decorator.decorate(a_person)
     a_person.decorators |should| contain("Fake Decorator for testing purposes")
     FakeDecorator.decoration_rules = ['xxxxx']
     (RuleManager.get_instance().check_decoration_rules, a_decorator, a_person) |should| throw(AttributeError)
Ejemplo n.º 6
0
 def __init__(self, account, type_, value, payment_value):
     WorkItem.__init__(self)
     self.bill_list = [
         'House bill', 'Eletricity bill', 'Water bill', 'Credit card bill'
     ]
     self.value = value
     self.datetime = datetime.now()
     self.payment_value = 0
     if type_ in self.bill_list:
         self.type_ = type_
     else:
         raise AssociationError('A Bill is expected , instead %s passed' %
                                (type_))
     if not value == payment_value:
         raise AssociationError(
             'Equal value is expected for the payment, Value payment is %s , payment value is %s'
             % (value, payment_value))
     if not RuleManager.get_instance().check_rule(
             'should_be_instance_of_bank_account', account):
         raise AssociationError(
             'Bank Account instance expected, instead %s passed' %
             type(account))
     self.account = account
     self.account.average_credit -= int(self.value)
     self.account.save_base()
Ejemplo n.º 7
0
 def check_rules(self, node):
     ''' for each decorator, identifies and runs each rule separately '''
     for decorator in self.decorators:
         passed, approved_rules, refused_rules = RuleManager.get_instance().check_decoration_rules(decorator, node)
         if passed:
             self.allowable_decorators.append(decorator)
         else:
             self.non_allowable_decorators.append(decorator)
             self.broken_rules.append(refused_rules)
Ejemplo n.º 8
0
 def it_decorates(self):
     a_decorator = FakeDecorator()
     a_person = Person()
     a_decorator.decorate(a_person)
     a_person.decorators | should | contain(
         "Fake Decorator for testing purposes")
     FakeDecorator.decoration_rules = ['xxxxx']
     (RuleManager.get_instance().check_decoration_rules, a_decorator,
      a_person) | should | throw(AttributeError)
Ejemplo n.º 9
0
 def __init__(self, loan_request):
     WorkItem.__init__(self)
     if not RuleManager.get_instance().check_rule('should_be_instance_of_loan_request', loan_request):
        raise AssociationError('Loan Request instance expected, instead %s passed' % type(loan_request))
     self.loan_request = loan_request
     self.value = self.loan_request.value
     self.account = self.loan_request.account
     self.account.average_credit += float(self.value)
     self.datetime = datetime.now()
     self.account.save_base()
Ejemplo n.º 10
0
 def check_rules(self, node):
     ''' for each decorator, identifies and runs each rule separately '''
     for decorator in self.decorators:
         passed, approved_rules, refused_rules = RuleManager.get_instance(
         ).check_decoration_rules(decorator, node)
         if passed:
             self.allowable_decorators.append(decorator)
         else:
             self.non_allowable_decorators.append(decorator)
             self.broken_rules.append(refused_rules)
Ejemplo n.º 11
0
 def __init__(self, account, type_, value, payment_value):
     WorkItem.__init__(self)
     self.bill_list = ['House bill', 'Eletricity bill', 'Water bill', 'Credit card bill']
     self.value = value
     self.datetime = datetime.now()
     self.payment_value = 0
     if type_ in self.bill_list:
         self.type_ = type_
     else:
         raise AssociationError('A Bill is expected , instead %s passed'%(type_))
     if not value == payment_value:
         raise AssociationError('Equal value is expected for the payment, Value payment is %s , payment value is %s' % (value,payment_value))
     if not RuleManager.get_instance().check_rule('should_be_instance_of_bank_account', account):
        raise AssociationError('Bank Account instance expected, instead %s passed' % type(account))
     self.account = account
     self.account.average_credit -= int(self.value)
     self.account.save_base()
Ejemplo n.º 12
0
 def it_checks_a_rule(self):
     a_person = Person()
     RuleManager.get_instance().check_rule('should_be_instance_of_person', a_person) |should| be(True)
     RuleManager.get_instance().check_rule('should_be_instance_of_machine', a_person) |should| be(False)
     (RuleManager.get_instance().check_rule, 'wrong rule...', a_person) |should| throw(AttributeError)
Ejemplo n.º 13
0
 def it_is_a_singleton(self):
     a_rule_manager = RuleManager()
     another_rule_manager = RuleManager()
     another_rule_manager |should| be(a_rule_manager)
     RuleManager.get_instance() |should| be(a_rule_manager)
Ejemplo n.º 14
0
 def decorate(self, decoration_candidate):
     passed, approved_rules, refused_rules = RuleManager.get_instance().check_decoration_rules(self,decoration_candidate)
     if passed:
        self.decorated = decoration_candidate
        decoration_candidate.decorate(self)
     return passed, approved_rules, refused_rules
Ejemplo n.º 15
0
 def __init__(self, loan_request):
     WorkItem.__init__(self)
     if not RuleManager.get_instance().check_rule('should_be_instance_of_loan_request', loan_request):
        raise AssociationError('Loan Request instance expected, instead %s passed' % type(loan_request))
     self.loan_request = loan_request
     self.datetime = datetime.now()