def test_create_new_contract(self):
        '''Test contract object behaves as expected
        '''
        # test that no additional properties works
        contract_data = dict(description='test')

        contract = ContractBaseFactory.build(**contract_data)
        self.assertEquals(contract.description, 'test')

        # test that additional properties also works
        contract_data_props = dict(description='test2')
        contract_with_props = ContractBaseFactory.build(**contract_data_props)

        prop1 = ContractPropertyFactory.build(contract=contract_with_props)
        prop2 = ContractPropertyFactory.build(contract=contract_with_props)

        self.assertEquals(contract_with_props.description, 'test2')
        self.assertEquals(len(contract_with_props.properties), 2)
        self.assertTrue(prop1 in contract_with_props.properties)
        self.assertTrue(prop2 in contract_with_props.properties)

        # this should fail with non-existing stage
        contract_data_fails = dict(description='test2', current_stage_id=1)
        try:
            ContractBaseFactory.build(**contract_data_fails)
            # this should never work, so break the tests if we get here
            self.assertTrue(False)
        except:
            self.assertTrue(True)
    def setUp(self):
        super(TestContractRenewals, self).setUp()
        self.user1 = UserFactory.build(email='user1')

        self.child_contract = ContractBaseFactory.build(
            expiration_date=datetime.date.today() + datetime.timedelta(1),
            is_archived=False, description='child'
        )

        self.child_contract2 = ContractBaseFactory.build(
            expiration_date=datetime.date.today() + datetime.timedelta(1),
            is_archived=False, parent_id=self.active_contract.id, description='child2'
        )

        self.active_contract.followers = [self.user1]
        self.active_contract.children.append(self.child_contract)
 def test_no_expiration_archived(self):
     '''Test contract that is archived but has no expiration date
     '''
     replaced = ContractBaseFactory.build(
         is_archived=True,
     )
     self.assertEquals(replaced.scout_contract_status, 'archived')
 def test_expired_contract_status(self):
     '''Test contract that is expired
     '''
     expired = ContractBaseFactory.build(
         expiration_date=self.yesterday, is_archived=True,
     )
     self.assertEquals(expired.scout_contract_status, 'expired')
 def test_replaced_contract_status(self):
     '''Test contract that is replaced
     '''
     replaced = ContractBaseFactory.build(expiration_date=self.tomorrow,
                                          is_archived=True,
                                          children=[self.active_contract])
     self.assertEquals(replaced.scout_contract_status, 'replaced')
 def test_archived_contract_status(self):
     '''Test contract that is archived
     '''
     archived = ContractBaseFactory.build(
         expiration_date=self.tomorrow, is_archived=True,
     )
     self.assertEquals(archived.scout_contract_status, 'archived')
    def setUp(self):
        super(TestContractRenewals, self).setUp()
        self.user1 = UserFactory.build(email='user1')

        self.child_contract = ContractBaseFactory.build(
            expiration_date=datetime.date.today() + datetime.timedelta(1),
            is_archived=False,
            description='child')

        self.child_contract2 = ContractBaseFactory.build(
            expiration_date=datetime.date.today() + datetime.timedelta(1),
            is_archived=False,
            parent_id=self.active_contract.id,
            description='child2')

        self.active_contract.followers = [self.user1]
        self.active_contract.children.append(self.child_contract)
 def test_archived_contract_status(self):
     '''Test contract that is archived
     '''
     archived = ContractBaseFactory.build(
         expiration_date=self.tomorrow,
         is_archived=True,
     )
     self.assertEquals(archived.scout_contract_status, 'archived')
 def test_expired_contract_status(self):
     '''Test contract that is expired
     '''
     expired = ContractBaseFactory.build(
         expiration_date=self.yesterday,
         is_archived=True,
     )
     self.assertEquals(expired.scout_contract_status, 'expired')
 def test_replaced_contract_status(self):
     '''Test contract that is replaced
     '''
     replaced = ContractBaseFactory.build(
         expiration_date=self.tomorrow, is_archived=True,
         children=[self.active_contract]
     )
     self.assertEquals(replaced.scout_contract_status, 'replaced')
 def setUp(self):
     super(ContractObjectTestBase, self).setUp()
     self.today = datetime.datetime.today()
     self.tomorrow = datetime.datetime.today() + datetime.timedelta(1)
     self.yesterday = datetime.datetime.today() - datetime.timedelta(1)
     self.active_contract = ContractBaseFactory.build(
         expiration_date=datetime.date.today() + datetime.timedelta(1),
         is_archived=False, parent_id=None, description='test description',
         financial_id=1234
     )
    def setUp(self):
        super(TestContractStageSort, self).setUp()
        now = datetime.datetime.now().replace(second=0, microsecond=0)
        old = now - datetime.timedelta(minutes=1)
        older = now - datetime.timedelta(minutes=2)
        new = now + datetime.timedelta(minutes=1)
        newer = now + datetime.timedelta(minutes=2)

        stage1, stage2 = StageFactory.build(), StageFactory.build()
        flow = FlowFactory.build(stage_order=[stage1.id, stage2.id])
        self.contract = ContractBaseFactory.build(current_stage_id=stage2.id)

        contract_stage1 = ContractStageFactory.build(
            stage=stage1, stage_id=stage1.id, flow=flow
        )
        contract_stage2 = ContractStageFactory.build(
            stage=stage2, stage_id=stage2.id, flow=flow
        )

        self.contract.build_complete_action_log = Mock()

        self.enter_one = ContractStageActionItemFactory.build(
            action_type='entered', taken_at=older, contract_stage=contract_stage1,
            action_detail={'timestamp': older.isoformat()}
        )
        self.exit_one = ContractStageActionItemFactory.build(
            action_type='exited', taken_at=old, contract_stage=contract_stage1,
            action_detail={'timestamp': old.isoformat()}
        )
        self.enter_two = ContractStageActionItemFactory.build(
            action_type='entered', taken_at=old.replace(second=1),
            contract_stage=contract_stage2,
            action_detail={'timestamp': old.isoformat()}
        )

        self.revert_one = ContractStageActionItemFactory.build(
            action_type='reversion', taken_at=now,
            contract_stage=contract_stage1,
            action_detail={'timestamp': now.isoformat()}
        )
        self.exit_one_post_revert = ContractStageActionItemFactory.build(
            action_type='exited', taken_at=new, contract_stage=contract_stage1,
            action_detail={'timestamp': new.isoformat()}
        )
        self.enter_two_post_revert = ContractStageActionItemFactory.build(
            action_type='entered', taken_at=new.replace(second=1),
            contract_stage=contract_stage2,
            action_detail={'timestamp': new.isoformat()}
        )

        self.note = ContractStageActionItemFactory.build(
            action_type='note', taken_at=newer,
            contract_stage=contract_stage2,
            action_detail={'timestamp': newer.isoformat()}
        )
 def setUp(self):
     super(ContractObjectTestBase, self).setUp()
     self.today = datetime.datetime.today()
     self.tomorrow = datetime.datetime.today() + datetime.timedelta(1)
     self.yesterday = datetime.datetime.today() - datetime.timedelta(1)
     self.active_contract = ContractBaseFactory.build(
         expiration_date=datetime.date.today() + datetime.timedelta(1),
         is_archived=False,
         parent_id=None,
         description='test description',
         financial_id=1234)
    def test_transition_last(self, complete):
        _get = Mock(return_value=ContractStage(stage=self.stage1))
        ContractStage.get_one = _get

        self.active_contract.parent = ContractBaseFactory.build(description='test')
        self.active_contract.current_stage_id = self.stage3.id
        self.active_contract.current_stage = self.stage3

        action = self.active_contract.transition(self.user)
        self.assertEquals(_get.call_count, 1)
        self.assertEquals(len(action), 1)
        self.assertEquals(action[0].action_type, 'exited')
        self.assertTrue(complete.called_once)
    def test_transition_last(self, complete):
        _get = Mock(return_value=ContractStage(stage=self.stage1))
        ContractStage.get_one = _get

        self.active_contract.parent = ContractBaseFactory.build(description='test')
        self.active_contract.current_stage_id = self.stage3.id
        self.active_contract.current_stage = self.stage3

        action = self.active_contract.transition(self.user)
        self.assertEquals(_get.call_count, 1)
        self.assertEquals(len(action), 1)
        self.assertEquals(action[0].action_type, 'exited')
        self.assertTrue(complete.called_once)
    def test_create_new_contract(self):
        '''Test contract object behaves as expected
        '''
        # test that no additional properties works
        contract_data = dict(
            description='test'
        )

        contract = ContractBaseFactory.build(**contract_data)
        self.assertEquals(contract.description, 'test')

        # test that additional properties also works
        contract_data_props = dict(
            description='test2'
        )
        contract_with_props = ContractBaseFactory.build(**contract_data_props)

        prop1 = ContractPropertyFactory.build(contract=contract_with_props)
        prop2 = ContractPropertyFactory.build(contract=contract_with_props)

        self.assertEquals(contract_with_props.description, 'test2')
        self.assertEquals(len(contract_with_props.properties), 2)
        self.assertTrue(prop1 in contract_with_props.properties)
        self.assertTrue(prop2 in contract_with_props.properties)

        # this should fail with non-existing stage
        contract_data_fails = dict(
            description='test2',
            current_stage_id=1
        )
        try:
            ContractBaseFactory.build(**contract_data_fails)
            # this should never work, so break the tests if we get here
            self.assertTrue(False)
        except:
            self.assertTrue(True)
 def test_no_expiration_archived(self):
     '''Test contract that is archived but has no expiration date
     '''
     replaced = ContractBaseFactory.build(is_archived=True, )
     self.assertEquals(replaced.scout_contract_status, 'archived')
    def setUp(self):
        super(TestContractStageSort, self).setUp()
        now = datetime.datetime.now().replace(second=0, microsecond=0)
        old = now - datetime.timedelta(minutes=1)
        older = now - datetime.timedelta(minutes=2)
        new = now + datetime.timedelta(minutes=1)
        newer = now + datetime.timedelta(minutes=2)

        stage1, stage2 = StageFactory.build(), StageFactory.build()
        flow = FlowFactory.build(stage_order=[stage1.id, stage2.id])
        self.contract = ContractBaseFactory.build(current_stage_id=stage2.id)

        contract_stage1 = ContractStageFactory.build(stage=stage1, stage_id=stage1.id, flow=flow)
        contract_stage2 = ContractStageFactory.build(stage=stage2, stage_id=stage2.id, flow=flow)

        self.contract.build_complete_action_log = Mock()

        self.enter_one = ContractStageActionItemFactory.build(
            action_type="entered",
            taken_at=older,
            contract_stage=contract_stage1,
            action_detail={"timestamp": older.isoformat()},
        )
        self.exit_one = ContractStageActionItemFactory.build(
            action_type="exited",
            taken_at=old,
            contract_stage=contract_stage1,
            action_detail={"timestamp": old.isoformat()},
        )
        self.enter_two = ContractStageActionItemFactory.build(
            action_type="entered",
            taken_at=old.replace(second=1),
            contract_stage=contract_stage2,
            action_detail={"timestamp": old.isoformat()},
        )

        self.revert_one = ContractStageActionItemFactory.build(
            action_type="reversion",
            taken_at=now,
            contract_stage=contract_stage1,
            action_detail={"timestamp": now.isoformat()},
        )
        self.exit_one_post_revert = ContractStageActionItemFactory.build(
            action_type="exited",
            taken_at=new,
            contract_stage=contract_stage1,
            action_detail={"timestamp": new.isoformat()},
        )
        self.enter_two_post_revert = ContractStageActionItemFactory.build(
            action_type="entered",
            taken_at=new.replace(second=1),
            contract_stage=contract_stage2,
            action_detail={"timestamp": new.isoformat()},
        )

        self.note = ContractStageActionItemFactory.build(
            action_type="note",
            taken_at=newer,
            contract_stage=contract_stage2,
            action_detail={"timestamp": newer.isoformat()},
        )