Пример #1
0
def test_company_referral_activity_without_team_and_contact(api_client):
    """
    Get a list of company referrals and test the returned JSON is valid as per:
    https://www.w3.org/TR/activitystreams-core/
    """
    recipient = AdviserFactory(dit_team=None)
    company_referral = CompanyReferralFactory(recipient=recipient, contact=None)
    response = hawk.get(api_client, get_url('api-v3:activity-stream:company-referrals'))
    assert response.status_code == status.HTTP_200_OK
    assert response.json() == {
        '@context': 'https://www.w3.org/ns/activitystreams',
        'summary': 'Company Referral Activities',
        'type': 'OrderedCollectionPage',
        'id': 'http://testserver/v3/activity-stream/company-referral',
        'partOf': 'http://testserver/v3/activity-stream/company-referral',
        'previous': None,
        'next': None,
        'orderedItems': [
            {
                'id': f'dit:DataHubCompanyReferral:{company_referral.id}:Announce',
                'type': 'Announce',
                'published': format_date_or_datetime(company_referral.modified_on),
                'generator': {'name': 'dit:dataHub', 'type': 'Application'},
                'object': {
                    'id': f'dit:DataHubCompanyReferral:{company_referral.id}',
                    'type': ['dit:CompanyReferral'],
                    'startTime': format_date_or_datetime(company_referral.created_on),
                    'dit:subject': company_referral.subject,
                    'dit:status': str(company_referral.status),
                    'attributedTo': [
                        {
                            'id': f'dit:DataHubCompany:{company_referral.company.pk}',
                            'dit:dunsNumber': company_referral.company.duns_number,
                            'dit:companiesHouseNumber': company_referral.company.company_number,
                            'type': ['Organization', 'dit:Company'],
                            'name': company_referral.company.name,
                        },
                        {
                            'id': f'dit:DataHubAdviser:{company_referral.created_by.pk}',
                            'type': ['Person', 'dit:Adviser'],
                            'dit:emailAddress':
                                company_referral.created_by.contact_email
                                or company_referral.created_by.email,
                            'name': company_referral.created_by.name,
                            'dit:team': {
                                'id': f'dit:DataHubTeam:{company_referral.created_by.dit_team.pk}',
                                'type': ['Group', 'dit:Team'],
                                'name': company_referral.created_by.dit_team.name,
                            },
                            'dit:DataHubCompanyReferral:role': 'sender',
                        },
                        {
                            'id': f'dit:DataHubAdviser:{company_referral.recipient.pk}',
                            'type': ['Person', 'dit:Adviser'],
                            'dit:emailAddress':
                                company_referral.recipient.contact_email
                                or company_referral.recipient.email,
                            'name': company_referral.recipient.name,
                            'dit:DataHubCompanyReferral:role': 'recipient',
                        },
                    ],
                    'url': company_referral.get_absolute_url(),
                },
            },
        ],
    }
Пример #2
0
def test_company_referral_activity(api_client):
    """
    Get a list of company referrals and test the returned JSON is valid as per:
    https://www.w3.org/TR/activitystreams-core/
    """
    start = datetime.datetime(year=2012,
                              month=7,
                              day=12,
                              hour=15,
                              minute=6,
                              second=3)
    with freeze_time(start) as frozen_datetime:
        company_referral = CompanyReferralFactory()
        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
    assert response.json() == {
        '@context':
        'https://www.w3.org/ns/activitystreams',
        'summary':
        'Company Referral Activities',
        'type':
        'OrderedCollectionPage',
        'next':
        'http://testserver/v3/activity-stream/company-referral' +
        '?cursor=2012-07-12T15%3A06%3A03.000000%2B00%3A00' +
        f'&cursor={str(company_referral.id)}',
        'orderedItems': [
            {
                'id':
                f'dit:DataHubCompanyReferral:{company_referral.id}:Announce',
                'type': 'Announce',
                'published':
                format_date_or_datetime(company_referral.modified_on),
                'generator': {
                    'name': 'dit:dataHub',
                    'type': 'Application'
                },
                'object': {
                    'id':
                    f'dit:DataHubCompanyReferral:{company_referral.id}',
                    'type': ['dit:CompanyReferral'],
                    'startTime':
                    format_date_or_datetime(company_referral.created_on),
                    'dit:subject':
                    company_referral.subject,
                    'dit:status':
                    str(company_referral.status),
                    'attributedTo': [
                        {
                            'id':
                            f'dit:DataHubCompany:{company_referral.company.pk}',
                            'dit:dunsNumber':
                            company_referral.company.duns_number,
                            'dit:companiesHouseNumber':
                            company_referral.company.company_number,
                            'type': ['Organization', 'dit:Company'],
                            'name': company_referral.company.name,
                        },
                        {
                            'id':
                            f'dit:DataHubAdviser:{company_referral.created_by.pk}',
                            'type': ['Person', 'dit:Adviser'],
                            'dit:emailAddress':
                            company_referral.created_by.contact_email
                            or company_referral.created_by.email,
                            'name':
                            company_referral.created_by.name,
                            'dit:team': {
                                'id':
                                f'dit:DataHubTeam:{company_referral.created_by.dit_team.pk}',
                                'type': ['Group', 'dit:Team'],
                                'name':
                                company_referral.created_by.dit_team.name,
                            },
                            'dit:DataHubCompanyReferral:role':
                            'sender',
                        },
                        {
                            'id':
                            f'dit:DataHubAdviser:{company_referral.recipient.pk}',
                            'type': ['Person', 'dit:Adviser'],
                            'dit:emailAddress':
                            company_referral.recipient.contact_email
                            or company_referral.recipient.email,
                            'name':
                            company_referral.recipient.name,
                            'dit:team': {
                                'id':
                                f'dit:DataHubTeam:{company_referral.recipient.dit_team.pk}',
                                'type': ['Group', 'dit:Team'],
                                'name':
                                company_referral.recipient.dit_team.name,
                            },
                            'dit:DataHubCompanyReferral:role':
                            'recipient',
                        },
                        {
                            'id':
                            f'dit:DataHubContact:{company_referral.contact.pk}',
                            'type': ['Person', 'dit:Contact'],
                            'url': company_referral.contact.get_absolute_url(),
                            'dit:emailAddress': company_referral.contact.email,
                            'dit:jobTitle': company_referral.contact.job_title,
                            'name': company_referral.contact.name,
                        },
                    ],
                    'url':
                    company_referral.get_absolute_url(),
                },
            },
        ],
    }