Exemplo n.º 1
0
def test_new_companies_in_sector_records_notification(settings):
    settings.NEW_COMPANIES_IN_SECTOR_FREQUENCY_DAYS = 3

    days_ago_three = datetime.utcnow() - timedelta(days=3)
    buyer_one = BuyerFactory.create(sector='AEROSPACE')
    CompanyFactory(sectors=['AEROSPACE'], date_published=days_ago_three)

    mail.outbox = []  # reset after emails sent by signals
    notifications.new_companies_in_sector()

    assert len(mail.outbox) == 1

    notification_record = AnonymousEmailNotification.objects.first()
    assert AnonymousEmailNotification.objects.count() == 1
    assert notification_record.email == buyer_one.email
    assert notification_record.category == constants.NEW_COMPANIES_IN_SECTOR
Exemplo n.º 2
0
def test_companies_publish_form_doesnt_allow_numbers_that_dont_exist():
    # all don't exist
    data = {'company_numbers': '12345678,23456789,34567890'}
    form = PublishByCompanyHouseNumberForm(data=data)

    assert form.is_valid() is False
    msg = COMPANY_DOESNT_EXIST_MSG + '12345678, 23456789, 34567890'
    assert form.errors['company_numbers'] == [msg]

    # some exist, some don't
    company = CompanyFactory()
    data = {'company_numbers': '{num},23456789'.format(num=company.number)}
    form = PublishByCompanyHouseNumberForm(data=data)

    assert form.is_valid() is False
    msg = COMPANY_DOESNT_EXIST_MSG + '23456789'
    assert form.errors['company_numbers'] == [msg]
Exemplo n.º 3
0
def test_new_companies_in_sector_exclude_unsbscribed(mock_task, settings):
    settings.NEW_COMPANIES_IN_SECTOR_FREQUENCY_DAYS = 3
    settings.NEW_COMPANIES_IN_SECTOR_SUBJECT = 'test subject'

    days_ago_three = datetime.utcnow() - timedelta(days=3)
    buyer_one = BuyerFactory.create(sector='AEROSPACE')
    buyer_two = BuyerFactory.create(sector='AEROSPACE')
    AnonymousUnsubscribeFactory(email=buyer_two.email)

    CompanyFactory(sectors=['AEROSPACE'], date_published=days_ago_three)

    notifications.new_companies_in_sector()

    assert len(mock_task.delay.call_args_list) == 1
    call_args = mock_task.delay.call_args[1]
    assert call_args['recipient_email'] == buyer_one.email
    assert call_args['from_email'] == settings.FAS_FROM_EMAIL
Exemplo n.º 4
0
def test_new_companies_in_sector_exclude_already_sent_recently(
        mock_task, settings):
    settings.NEW_COMPANIES_IN_SECTOR_FREQUENCY_DAYS = 3
    settings.NEW_COMPANIES_IN_SECTOR_SUBJECT = 'test subject'

    days_ago_three = datetime.utcnow() - timedelta(days=3)
    buyer_one = BuyerFactory.create(sector='AEROSPACE')
    buyer_two = BuyerFactory.create(sector='AEROSPACE')

    notification = AnonymousEmailNotificationFactory(email=buyer_two.email)
    notification.date_sent = days_ago_three
    notification.save()
    CompanyFactory(sectors=['AEROSPACE'], date_published=days_ago_three)
    notifications.new_companies_in_sector()

    assert len(mock_task.delay.call_args_list) == 1
    assert mock_task.delay.call_args[1]['recipient_email'] == buyer_one.email
Exemplo n.º 5
0
def test_new_companies_in_sector_exclude_unsbscribed(settings):
    settings.NEW_COMPANIES_IN_SECTOR_FREQUENCY_DAYS = 3
    settings.NEW_COMPANIES_IN_SECTOR_SUBJECT = 'test subject'

    days_ago_three = datetime.utcnow() - timedelta(days=3)
    buyer_one = BuyerFactory.create(sector='AEROSPACE')
    buyer_two = BuyerFactory.create(sector='AEROSPACE')
    AnonymousUnsubscribeFactory(email=buyer_two.email)

    CompanyFactory(sectors=['AEROSPACE'], date_published=days_ago_three)

    mail.outbox = []  # reset after emails sent by signals
    notifications.new_companies_in_sector()

    assert len(mail.outbox) == 1

    assert mail.outbox[0].to == [buyer_one.email]
    assert mail.outbox[0].from_email == settings.FAS_FROM_EMAIL
Exemplo n.º 6
0
def test_company_case_study_explicit_value(case_study_data):
    request = Mock()
    company = CompanyFactory()
    request.user.supplier.company = company
    serializer = serializers.CompanyCaseStudySerializer(
        data=case_study_data, context={'request': request})

    assert serializer.is_valid()
    data = serializer.validated_data

    assert data['company'] == company
    assert data['website'] == case_study_data['website']
    assert data['testimonial'] == case_study_data['testimonial']
    assert data['testimonial_name'] == case_study_data['testimonial_name']
    assert data['testimonial_job_title'] == (
        case_study_data['testimonial_job_title'])
    assert data['testimonial_company'] == (
        case_study_data['testimonial_company'])
Exemplo n.º 7
0
def test_if_verified_with_preverified_enrolment_in_stream(api_client):
    """If the company verified_with_preverified_enrolment, then it's in the
    activity stream
    """

    CompanyFactory(number=10000000, verified_with_preverified_enrolment=True)

    sender = _auth_sender()
    response = api_client.get(
        _url(),
        content_type='',
        HTTP_AUTHORIZATION=sender.request_header,
        HTTP_X_FORWARDED_FOR='1.2.3.4, 123.123.123.123',
    )
    items = response.json()['orderedItems']

    assert len(items) == 1
    assert get_companies_house_number(items[0]) == '10000000'
Exemplo n.º 8
0
def test_retrieve_missing_company_details(mock_get_date_of_creation):
    mock_get_date_of_creation.return_value = None
    company_with_date = CompanyFactory(date_of_creation=date(2010, 10, 1))
    companies = CompanyFactory.create_batch(2)
    mock_get_date_of_creation.return_value = date(2010, 10, 10)

    call_command('retrieve_missing_company_details')

    assert models.Company.objects.get(
        number=company_with_date.number
    ).date_of_creation == date(2010, 10, 1)

    assert models.Company.objects.get(
        number=companies[0].number
    ).date_of_creation == date(2010, 10, 10)

    assert models.Company.objects.get(
        number=companies[1].number
    ).date_of_creation == date(2010, 10, 10)
Exemplo n.º 9
0
def test_company_case_study_non_required_fields():
    company = CompanyFactory()
    instance = models.CompanyCaseStudy.objects.create(
        title='a title',
        description='a description',
        sector=choices.COMPANY_CLASSIFICATIONS[1][0],
        keywords='good, great',
        company=company,
    )

    assert instance.website == ''
    assert instance.testimonial == ''
    assert instance.testimonial_name == ''
    assert instance.testimonial_job_title == ''
    assert instance.testimonial_company == ''
    assert instance.image_one.name is ''
    assert instance.image_two.name is ''
    assert instance.image_three.name is ''
    assert instance.video_one.name is ''
Exemplo n.º 10
0
def test_new_companies_in_sector_include_already_sent_long_time_ago(settings):
    settings.NEW_COMPANIES_IN_SECTOR_FREQUENCY_DAYS = 3
    settings.NEW_COMPANIES_IN_SECTOR_SUBJECT = 'test subject'

    days_ago_three = datetime.utcnow() - timedelta(days=3)
    days_ago_four = datetime.utcnow() - timedelta(days=4)
    buyer_one = BuyerFactory.create(sector='AEROSPACE')
    notification = AnonymousEmailNotificationFactory(email=buyer_one.email)
    notification.date_sent = days_ago_four
    notification.save()

    CompanyFactory(sectors=['AEROSPACE'], date_published=days_ago_three)

    mail.outbox = []  # reset after emails sent by signals
    notifications.new_companies_in_sector()

    assert len(mail.outbox) == 1

    assert mail.outbox[0].to == [buyer_one.email]
Exemplo n.º 11
0
    def test_create_companies_form_existing(self):

        company = CompanyFactory(number=12355434)
        assert company.is_uk_isd_company is False

        file_path = os.path.join(
            settings.BASE_DIR,
            'company/tests/fixtures/valid-companies-upload.csv')

        response = self.client.post(reverse('admin:company_company_enrol'), {
            'generated_for': constants.UK_ISD,
            'csv_file': open(file_path, 'rb'),
        })

        assert response.status_code == 200
        assert Company.objects.count() == 2
        company.refresh_from_db()

        assert company.is_uk_isd_company is True
Exemplo n.º 12
0
def test_retrieve_missing_company_address_po_box(
        mock_get_companies_house_profile):
    company = CompanyFactory(date_of_creation=None, number=123)
    mock_get_companies_house_profile.return_value = {
        'date_of_creation': '2016-12-16',
        'registered_office_address': {
            'address_line_1': '123 fake street',
            'address_line_2': 'Fake land',
            'locality': 'Fakeville',
            'postal_code': 'FAKELAND',
        }
    }
    call_command('retrieve_missing_company_details')
    company.refresh_from_db()
    assert company.date_of_creation == datetime.date(2016, 12, 16)
    assert company.address_line_1 == '123 fake street'
    assert company.address_line_2 == 'Fake land'
    assert company.locality == 'Fakeville'
    assert company.postal_code == 'FAKELAND'
    assert company.po_box == ''
Exemplo n.º 13
0
def test_preverified_claim_company_succcess(authed_client):
    Supplier.objects.all().delete()
    assert Supplier.objects.count() == 0

    company = CompanyFactory()

    url = reverse(
        'enrolment-claim-preverified',
        kwargs={'key': signing.Signer().sign(company.number)}
    )

    response = authed_client.post(url, {'name': 'Foo bar'})

    assert response.status_code == 201
    assert Supplier.objects.count() == 1

    supplier = Supplier.objects.first()
    assert supplier.name == 'Foo bar'
    assert supplier.company == company
    assert supplier.is_company_owner is True
Exemplo n.º 14
0
    def test_company_update_view_with_put(self):
        client = APIClient()
        company = CompanyFactory(
            number='01234567',
            export_status=choices.EXPORT_STATUSES[1][0],
        )
        supplier = Supplier.objects.create(
            sso_id=1,
            company_email='*****@*****.**',
            company=company,
        )

        response = client.put(reverse('company',
                                      kwargs={'sso_id': supplier.sso_id}),
                              VALID_REQUEST_DATA,
                              format='json')

        expected = {
            'email_address': company.email_address,
            'email_full_name': company.email_full_name,
            'employees': company.employees,
            'facebook_url': company.facebook_url,
            'has_valid_address': True,
            'id': str(company.id),
            'is_published': False,
            'is_verification_letter_sent': False,
            'keywords': company.keywords,
            'linkedin_url': company.linkedin_url,
            'logo': None,
            'modified': '2016-11-23T11:21:10.977518Z',
            'po_box': company.po_box,
            'sectors': company.sectors,
            'slug': 'test-company',
            'summary': company.summary,
            'supplier_case_studies': [],
            'twitter_url': company.twitter_url,
            'verified_with_code': False,
        }
        expected.update(VALID_REQUEST_DATA)
        assert response.status_code == status.HTTP_200_OK
        assert response.json() == expected
Exemplo n.º 15
0
    def test_company_update_view_with_patch_ignores_modified(self):
        client = APIClient()
        company = CompanyFactory(
            number='01234567',
            export_status=choices.EXPORT_STATUSES[1][0],
        )
        supplier = Supplier.objects.create(
            sso_id=1,
            company_email='*****@*****.**',
            company=company,
        )
        update_data = {'modified': '2013-03-09T23:28:53.977518Z'}
        update_data.update(VALID_REQUEST_DATA)

        response = client.patch(reverse('company',
                                        kwargs={'sso_id': supplier.sso_id}),
                                update_data,
                                format='json')

        assert response.status_code == status.HTTP_200_OK
        # modified was not effected by the data we tried to pass
        assert response.json()['modified'] == '2016-11-23T11:21:10.977518Z'
Exemplo n.º 16
0
def test_company_generates_slug():
    instance = CompanyFactory(name='Example corp.')
    assert instance.slug == 'example-corp'
Exemplo n.º 17
0
def public_profile_with_case_studies():
    company = CompanyFactory(is_published=True)
    CompanyCaseStudyFactory(company=company)
    CompanyCaseStudyFactory(company=company)
    return company
Exemplo n.º 18
0
def test_unknown_address_not_send_letters(mock_send_letter, settings):
    settings.FEATURE_VERIFICATION_LETTERS_ENABLED = True
    CompanyFactory()

    mock_send_letter.send_letter.assert_not_called()
Exemplo n.º 19
0
def test_save_to_elasticsearch_unpublished(mock_elasticsearch_company_save):
    CompanyFactory(is_published=False)

    assert mock_elasticsearch_company_save.call_count == 0
Exemplo n.º 20
0
def test_companies_house_missing_company_status_new_company(
        mock_get_companies_house_profile):
    company = CompanyFactory(date_of_creation=None, number=123)
    mock_get_companies_house_profile.return_value = {}
    call_command('retrieve_companies_house_company_status')
    assert company.companies_house_company_status == ''
Exemplo n.º 21
0
def test_letter_sent(mock_send_letter, settings):
    settings.FEATURE_VERIFICATION_LETTERS_ENABLED = True
    company = CompanyFactory(verification_code='test')

    mock_send_letter.assert_called_with(company=company)
Exemplo n.º 22
0
def test_store_date_published_published_company_with_date():
    expected_date = timezone.now()

    company = CompanyFactory(is_published=True, date_published=expected_date)

    assert company.date_published == expected_date
Exemplo n.º 23
0
def test_store_date_published_unpublished_company():
    company = CompanyFactory(is_published=False)

    assert company.date_published is None
Exemplo n.º 24
0
def test_company_model_str():
    company = CompanyFactory()
    assert company.name == str(company)
Exemplo n.º 25
0
def test_automatic_publish_update():
    should_be_published = [
        {
            'description': 'description',
            'email_address': '*****@*****.**',
            'verified_with_code': True,
        },
        {
            'summary': 'summary',
            'email_address': '*****@*****.**',
            'verified_with_code': True,
        },
    ]

    should_be_unpublished = [
        {
            'description': '',
            'summary': '',
            'email_address': '*****@*****.**',
            'verified_with_code': True,
        },
        {
            'description': 'description',
            'summary': 'summary',
            'email_address': '',
            'verified_with_code': True,
        },
        {
            'description': 'description',
            'summary': 'summary',
            'email_address': '*****@*****.**',
            'verified_with_code': False,
        },
    ]

    should_be_force_published = [{
        **item, 'is_published': True
    } for item in should_be_unpublished]

    for kwargs in should_be_published:
        company = CompanyFactory()
        assert company.is_published is False
        for field, value in kwargs.items():
            setattr(company, field, value)
        company.save()
        company.refresh_from_db()
        assert company.is_published is True

    for kwargs in should_be_unpublished:
        company = CompanyFactory()
        assert company.is_published is False
        for field, value in kwargs.items():
            setattr(company, field, value)
        company.save()
        company.refresh_from_db()
        assert company.is_published is False

    for kwargs in should_be_force_published:
        company = CompanyFactory()
        assert company.is_published is False
        for field, value in kwargs.items():
            setattr(company, field, value)
        company.save()
        company.refresh_from_db()
        assert company.is_published is True
Exemplo n.º 26
0
def test_company_unique_rejects_existing(client):
    company = CompanyFactory()
    with pytest.raises(ValidationError):
        validators.company_unique(company.number)
Exemplo n.º 27
0
def test_company_enforces_unique_company_number():
    company = CompanyFactory()
    with pytest.raises(IntegrityError):
        CompanyFactory(number=company.number)
Exemplo n.º 28
0
def test_store_date_published_published_company_without_date():
    company = CompanyFactory(is_published=True, date_published=None)

    assert company.date_published == timezone.now()
Exemplo n.º 29
0
def company():
    return CompanyFactory()
Exemplo n.º 30
0
def test_public_profile_url(settings):
    settings.FAS_COMPANY_PROFILE_URL = 'http://profile/{number}'

    company = CompanyFactory(number='1234567')

    assert company.public_profile_url == 'http://profile/1234567'