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_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_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_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 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(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)
Exemple #11
0
    def setUp(self):
        from flask_migrate import upgrade
        upgrade()

        # insert the users/roles
        self.admin_role = get_a_role('admin')
        self.superadmin_role = get_a_role('superadmin')
        self.admin_user = insert_a_user(email='*****@*****.**',
                                        role=self.admin_role)
        self.superadmin_user = insert_a_user(email='*****@*****.**',
                                             role=self.superadmin_role)

        # insert the companies/contracts
        self.company_1 = insert_a_company(name='ship', insert_contract=False)
        company_2 = insert_a_company(name='boat', insert_contract=False)

        contract_type = ContractTypeFactory.create(name='test')
        self.contract_type2 = ContractTypeFactory.create(name='test2')

        self.contract1 = ContractBaseFactory.create(
            description='vessel',
            companies=[company_2],
            line_items=[LineItem(description='NAVY')],
            expiration_date=datetime.datetime.today() + datetime.timedelta(1),
            is_archived=False,
            financial_id='123',
            contract_type=contract_type)
        ContractBaseFactory.create(
            description='sail',
            financial_id='456',
            companies=[self.company_1],
            line_items=[LineItem(description='sunfish')],
            is_archived=False,
            expiration_date=datetime.datetime.today() + datetime.timedelta(1),
            contract_type=contract_type)
        ContractBaseFactory.create(
            description='sunfish',
            financial_id='789',
            properties=[
                ContractPropertyFactory.create(key='foo', value='engine')
            ],
            expiration_date=datetime.datetime.today() + datetime.timedelta(1),
            is_archived=False,
            contract_type=contract_type)
        ContractBaseFactory.create(
            description='sunfish',
            financial_id='012',
            properties=[
                ContractPropertyFactory.create(key='foo', value='engine')
            ],
            expiration_date=datetime.datetime.today() - datetime.timedelta(1),
            is_archived=False,
            contract_type=self.contract_type2)

        # db.session.execute('''
        #     REFRESH MATERIALIZED VIEW CONCURRENTLY search_view
        # ''')
        db.session.commit()
 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 insert_a_contract(properties=None, **kwargs):
    contract_data = dict(description="test2") if not kwargs else dict(kwargs)

    contract = ContractBaseFactory.create(**contract_data)

    if properties:
        [i.update({"contract": contract}) for i in properties]
    else:
        properties = [dict(contract=contract, key="foo", value="bar"), dict(contract=contract, key="baz", value="qux")]

    for _property in properties:
        ContractPropertyFactory.create(**_property)
    return contract
    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 insert_a_contract(properties=None, **kwargs):
    contract_data = dict(description='test2', ) if not kwargs else dict(kwargs)

    contract = ContractBaseFactory.create(**contract_data)

    if properties:
        [i.update({'contract': contract}) for i in properties]
    else:
        properties = [
            dict(contract=contract, key='foo', value='bar'),
            dict(contract=contract, key='baz', value='qux')
        ]

    for _property in properties:
        ContractPropertyFactory.create(**_property)
    return contract
    def setUp(self):
        super(TestScoutJobs, self).setUp()
        self.user = UserFactory.create()
        ContractBaseFactory.create(
            expiration_date=datetime.date.today() + datetime.timedelta(30), description="foobar", followers=[self.user]
        )

        ContractBaseFactory.create(expiration_date=datetime.date.today(), description="qux", followers=[self.user])

        ContractBaseFactory.create(
            expiration_date=datetime.date.today() + datetime.timedelta(1), description="qux", followers=[self.user]
        )
def insert_a_contract(properties=None, **kwargs):
    contract_data = dict(
        description='test2',
    ) if not kwargs else dict(kwargs)

    contract = ContractBaseFactory.create(**contract_data)

    if properties:
        [i.update({'contract': contract}) for i in properties]
    else:
        properties = [
            dict(contract=contract, key='foo', value='bar'),
            dict(contract=contract, key='baz', value='qux')
        ]

    for _property in properties:
        ContractPropertyFactory.create(**_property)
    return contract
    def setUp(self):
        from flask_migrate import upgrade
        upgrade()

        # insert the users/roles
        self.admin_role = get_a_role('admin')
        self.superadmin_role = get_a_role('superadmin')
        self.admin_user = insert_a_user(email='*****@*****.**', role=self.admin_role)
        self.superadmin_user = insert_a_user(email='*****@*****.**', role=self.superadmin_role)

        # insert the companies/contracts
        self.company_1 = insert_a_company(name='ship', insert_contract=False)
        company_2 = insert_a_company(name='boat', insert_contract=False)

        contract_type = ContractTypeFactory.create(name='test')
        self.contract_type2 = ContractTypeFactory.create(name='test2')

        self.contract1 = ContractBaseFactory.create(
            description='vessel', companies=[company_2], line_items=[LineItem(description='NAVY')],
            expiration_date=datetime.datetime.today() + datetime.timedelta(1), is_archived=False,
            financial_id='123', contract_type=contract_type
        )
        ContractBaseFactory.create(
            description='sail', financial_id='456', companies=[self.company_1],
            line_items=[LineItem(description='sunfish')], is_archived=False,
            expiration_date=datetime.datetime.today() + datetime.timedelta(1),
            contract_type=contract_type
        )
        ContractBaseFactory.create(
            description='sunfish', financial_id='789',
            properties=[ContractPropertyFactory.create(key='foo', value='engine')],
            expiration_date=datetime.datetime.today() + datetime.timedelta(1), is_archived=False,
            contract_type=contract_type
        )
        ContractBaseFactory.create(
            description='sunfish', financial_id='012',
            properties=[ContractPropertyFactory.create(key='foo', value='engine')],
            expiration_date=datetime.datetime.today() - datetime.timedelta(1), is_archived=False,
            contract_type=self.contract_type2
        )

        # db.session.execute('''
        #     REFRESH MATERIALIZED VIEW CONCURRENTLY search_view
        # ''')
        db.session.commit()
    def setUp(self):
        super(TestScoutJobs, self).setUp()
        self.user = UserFactory.create()
        ContractBaseFactory.create(expiration_date=datetime.date.today() +
                                   datetime.timedelta(30),
                                   description='foobar',
                                   followers=[self.user])

        ContractBaseFactory.create(expiration_date=datetime.date.today(),
                                   description='qux',
                                   followers=[self.user])

        ContractBaseFactory.create(expiration_date=datetime.date.today() +
                                   datetime.timedelta(1),
                                   description='qux',
                                   followers=[self.user])
 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()},
        )