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

    with mock.patch('requests.post') as requests_mock:
        company = CompanyFactory(name="Original name")
        company.name = "Changed name"
        company.save()

    requests_mock.assert_called_once_with(
        'https://dash.stannp.com/api/v1/letters/create',
        auth=('debug', ''),
        data={
            'test': True,
            'recipient[company_name]': 'Original 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]': 'Original 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
ファイル: 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