コード例 #1
0
ファイル: test_signals.py プロジェクト: cr3test/directory-api
def test_sends_verification_letter_post_save(settings):
    settings.FEATURE_VERIFICATION_LETTERS_ENABLED = True

    with mock.patch('requests.post') as requests_mock:
        company = CompanyFactory()

    company.refresh_from_db()
    assert company.verification_code

    requests_mock.assert_called_once_with(
        'https://dash.stannp.com/api/v1/letters/create',
        auth=('debug', ''),
        data={
            'test': True,
            'recipient[company_name]': company.name,
            'recipient[country]': company.country,
            'recipient[date]': datetime.date.today().strftime('%d/%m/%Y'),
            'recipient[address1]': company.address_line_1,
            'recipient[full_name]': company.postal_full_name,
            'recipient[city]': company.locality,
            'recipient[company]': company.name,
            'recipient[postcode]': company.postal_code,
            'recipient[title]': company.postal_full_name,
            'recipient[address2]': company.address_line_2,
            'recipient[verification_code]': company.verification_code,
            'template': 'debug'
        },
    )
コード例 #2
0
def test_send_letter(mock_stannp_client):
    company = CompanyFactory(verification_code='test')
    send_verification_letter(company)
    mock_stannp_client.send_letter.assert_called_with(recipient={
        'postal_full_name':
        company.postal_full_name,
        'address_line_1':
        company.address_line_1,
        'address_line_2':
        company.address_line_2,
        'locality':
        company.locality,
        'country':
        company.country,
        'postal_code':
        company.postal_code,
        'po_box':
        company.po_box,
        'custom_fields': [('full_name', company.postal_full_name),
                          ('company_name', company.name),
                          ('verification_code', company.verification_code),
                          ('date', datetime.date.today().strftime('%d/%m/%Y')),
                          ('company', company.name)]
    },
                                                      template='debug')
    company.refresh_from_db()
    assert company.is_verification_letter_sent
    assert company.date_verification_letter_sent == timezone.now()
コード例 #3
0
def test_retrieve_missing_company_date(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'
    }
    call_command('retrieve_missing_company_details')
    company.refresh_from_db()
    assert company.date_of_creation == datetime.date(2016, 12, 16)
コード例 #4
0
def test_companies_house_non_active_status(mock_get_companies_house_profile):
    company = CompanyFactory(date_of_creation=None, number=123)
    mock_get_companies_house_profile.return_value = {
        'company_status': 'dissolved',
    }
    call_command('retrieve_companies_house_company_status')
    company.refresh_from_db()
    assert company.companies_house_company_status == 'dissolved'
コード例 #5
0
ファイル: test_signals.py プロジェクト: cr3test/directory-api
def test_does_not_overwrite_verification_code_if_already_set(settings):
    settings.FEATURE_VERIFICATION_LETTERS_ENABLED = True

    with mock.patch('requests.post'):
        company = CompanyFactory(verification_code='test')

    company.refresh_from_db()
    assert company.verification_code == 'test'
コード例 #6
0
def test_retrieve_company_status_handles_error(
        mock_get_companies_house_profile):
    company = CompanyFactory(number=123)

    mock_get_companies_house_profile.side_effect = Exception()

    call_command('retrieve_companies_house_company_status')
    company.refresh_from_db()
    assert company.companies_house_company_status == ''
コード例 #7
0
def test_companies_house_missing_status_on_update(
        mock_get_companies_house_profile):
    company = CompanyFactory(date_of_creation=None,
                             number=123,
                             companies_house_company_status='active')
    mock_get_companies_house_profile.return_value = {}
    call_command('retrieve_companies_house_company_status')
    company.refresh_from_db()
    assert company.companies_house_company_status == ''
コード例 #8
0
def test_ignores_sole_traders(mock_get_companies_house_profile):
    company_one = CompanyFactory(date_of_creation=None, number=123)
    company_two = CompanyFactory(company_type=company_types.SOLE_TRADER)

    mock_get_companies_house_profile.return_value = {
        'date_of_creation': '2016-12-16'
    }
    call_command('retrieve_missing_company_details')

    company_one.refresh_from_db()
    company_two.refresh_from_db()

    assert company_one.date_of_creation == datetime.date(2016, 12, 16)
    assert company_two.date_of_creation is None
コード例 #9
0
def test_ignores_sole_traders(mock_get_companies_house_profile):
    company_one = CompanyFactory(number=123)
    company_two = CompanyFactory(company_type=company_types.SOLE_TRADER)

    mock_get_companies_house_profile.return_value = {
        'company_status': 'active'
    }
    call_command('retrieve_companies_house_company_status')

    company_one.refresh_from_db()
    company_two.refresh_from_db()

    assert company_one.companies_house_company_status == 'active'
    assert company_two.companies_house_company_status == ''
コード例 #10
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
コード例 #11
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 == ''
コード例 #12
0
    def test_upload_expertise_companies_form_success(self):

        company_1 = CompanyFactory(name='Test 1', )
        company_2 = CompanyFactory(number='74897421', )
        company_3 = CompanyFactory(
            name='Test 3',
            number='23242314',
            expertise_products_services={},
        )
        CompanyFactory(
            name='Test 4',
            number='',
        )
        CompanyFactory(name='Test 4', )

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

        response = self.client.post(reverse('admin:upload_company_expertise'),
                                    {
                                        'csv_file': open(file_path, 'rb'),
                                    })

        company_1.refresh_from_db()
        company_2.refresh_from_db()
        company_3.refresh_from_db()

        assert company_1.expertise_products_services == ({
            'Finance': ['Raising capital'],
            'Management Consulting': ['Workforce development'],
            'Human Resources': ['Sourcing and hiring', 'Succession planning'],
            'Publicity': ['Social media'],
            'Business Support': ['Planning consultants']
        })
        assert company_2.expertise_products_services == ({
            'Finance': ['Insurance']
        })
        assert company_3.expertise_products_services == {
            'Legal': ['Immigration'],
            'Business Support': ['Facilities (such as WiFI or electricity)']
        }
        assert response.context['errors'] == [
            '[Row 3] "Unable to find following products & services '
            '[\'Unkown Skill\']"', '[Row 5] "More then one company returned - '
            'Name:Test 4 Number:00000000)"',
            '[Row 6] "Company not found - Name:Test 9999 Number:00000000)"'
        ]
        assert len(response.context['updated_companies']) == 3
コード例 #13
0
ファイル: test_signals.py プロジェクト: cr3test/directory-api
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