Beispiel #1
0
def test_company_referrals_ordering(api_client):
    """
    Test that the company referrals are ordered by ('modified_on', 'pk')
    """
    company_referrals = []

    with freeze_time() as frozen_datetime:
        company_referrals += CompanyReferralFactory.create_batch(2)

        frozen_datetime.tick(datetime.timedelta(microseconds=1))
        company_referrals += CompanyReferralFactory.create_batch(8)

        frozen_datetime.tick(datetime.timedelta(seconds=1, microseconds=1))
        response = hawk.get(
            api_client, get_url('api-v3:activity-stream:company-referrals'))

    assert response.status_code == status.HTTP_200_OK

    sorted_company_referral_ids = [
        f'dit:DataHubCompanyReferral:{obj.pk}'
        for obj in sorted(company_referrals,
                          key=lambda obj: (obj.modified_on, obj.pk))
    ]
    response_company_referral_ids = [
        item['object']['id'] for item in response.json()['orderedItems']
    ]
    assert sorted_company_referral_ids == response_company_referral_ids
Beispiel #2
0
def _company_factory(
    num_interactions=0,
    num_contacts=0,
    num_investment_projects=0,
    num_orders=0,
    num_referrals=0,
    num_company_list_items=0,
    num_pipeline_items=0,
):
    """
    Factory for a company that has companies, interactions, investment projects and OMIS orders.
    """
    company = CompanyFactory()
    ContactFactory.create_batch(num_contacts, company=company)
    CompanyInteractionFactory.create_batch(num_interactions, company=company)
    CompanyReferralFactory.create_batch(num_referrals,
                                        company=company,
                                        contact=None)
    OrderFactory.create_batch(num_orders, company=company)
    CompanyListItemFactory.create_batch(num_company_list_items,
                                        company=company)
    PipelineItemFactory.create_batch(num_pipeline_items, company=company)

    fields_iter = cycle(INVESTMENT_PROJECT_COMPANY_FIELDS)
    fields = islice(fields_iter, 0, num_investment_projects)
    InvestmentProjectFactory.create_batch(
        num_investment_projects,
        **{field: company
           for field in fields},
    )
    return company
Beispiel #3
0
def company_with_referrals_factory():
    """
    Factory for a company with referrals.

    No company contacts are created to simplify testing.
    """
    company = CompanyFactory()
    CompanyReferralFactory.create_batch(3, company=company, contact=None)
    return company
    def test_doesnt_return_other_users_referrals(self):
        """Test that other users' referrals are not returned."""
        # Create some referrals sent or received by other users
        CompanyReferralFactory.create_batch(2)

        response = self.api_client.get(collection_url)

        assert response.status_code == status.HTTP_200_OK
        response_data = response.json()
        assert response_data['results'] == []
Beispiel #5
0
def unrelated_objects():
    """
    Create some objects not related to a known company.

    This is used in tests below to make sure objects unrelated to the company being merged
    do not affect the counts of objects that will be affected by the merge.
    """
    ContactFactory.create_batch(2)
    CompanyReferralFactory.create_batch(2)
    CompanyInteractionFactory.create_batch(2)
    OrderFactory.create_batch(2)
    InvestmentProjectFactory.create_batch(2)
Beispiel #6
0
def _company_factory(
        num_interactions=0,
        num_contacts=0,
        num_orders=0,
        num_referrals=0,
        num_company_list_items=0,
):
    """Factory for a company that has companies, interactions and OMIS orders."""
    company = CompanyFactory()
    ContactFactory.create_batch(num_contacts, company=company)
    CompanyInteractionFactory.create_batch(num_interactions, company=company)
    CompanyReferralFactory.create_batch(num_referrals, company=company, contact=None)
    OrderFactory.create_batch(num_orders, company=company)
    CompanyListItemFactory.create_batch(num_company_list_items, company=company)
    return company