Exemplo n.º 1
0
def test_create_invalid(account_from_address, campaign_data, error_msg):
    data = sample_campaign_data(**campaign_data)
    if 'from_address' not in campaign_data:
        data['from_address']['email'] = account_from_address
    campaign = Campaign(**data)

    with pytest.raises(ErrorCampaignInvalid) as e:
        campaign.create()
    assert e.value.message == error_msg
Exemplo n.º 2
0
def sample_campaign(request, connection, account_from_address):
    data = sample_campaign_data()
    data['from_address']['email'] = account_from_address
    campaign = Campaign(**data)
    campaign.create()

    def _finalizer():
        manually_delete_campaign(connection, campaign)

    request.addfinalizer(_finalizer)

    return campaign
Exemplo n.º 3
0
def test_create_valid(request, connection, account_from_address):
    data = sample_campaign_data()
    data['from_address']['email'] = account_from_address
    campaign = Campaign(**data)
    assert campaign.id is None

    campaign.create()

    def cleanup():
        manually_delete_campaign(connection, campaign)

    request.addfinalizer(cleanup)
    assert campaign.id is not None
    for key, value in data.items():
        if key != 'from_address':
            assert getattr(campaign, key) == value
    assert campaign.from_address == data['from_address']['email']
Exemplo n.º 4
0
def test_delete_invalid():
    campaign = Campaign(**sample_campaign_data())
    with pytest.raises(Exception):
        campaign.delete()

    campaign.id = 0
    with pytest.raises(Exception):
        campaign.delete()
Exemplo n.º 5
0
def test_copy_invalid():
    campaign = Campaign(**sample_campaign_data())
    with pytest.raises(TypeError):
        Campaign.copy(campaign)

    campaign.id = 0
    with pytest.raises(Exception):
        Campaign.copy(campaign)
Exemplo n.º 6
0
def test_create_required_keys(account_from_address, keys_to_use, error_msg):
    data = sample_campaign_data()
    data['from_address']['email'] = account_from_address
    data = {
        key: value
        for key, value in sample_campaign_data().items() if key in keys_to_use
    }

    with pytest.raises(KeyError) as e:
        Campaign(**data)
    assert e.value.message == error_msg
Exemplo n.º 7
0
def test_copy_valid(request, connection, sample_campaign):
    copy = Campaign.copy(sample_campaign.id)

    def cleanup():
        manually_delete_campaign(connection, copy)
    request.addfinalizer(cleanup)

    assert copy.name == 'Copy of {}'.format(sample_campaign.name)
    key_to_check = [
        'subject', 'from_name', 'html_content', 'plain_text_content',
        'reply_action', 'reply_to_address', 'status'
    ]
    for key in key_to_check:
        assert getattr(copy, key) == getattr(sample_campaign, key)
Exemplo n.º 8
0
def test_update_valid(sample_campaign):
    new_data = {
        'name':
        'new name',
        'subject':
        'new subject',
        'from_name':
        'new from name',
        'html_content':
        'new text {}'.format(constants.UNSUB_HTML_STRING),
        'plain_text_content':
        'new text {}'.format(constants.UNSUB_PLAIN_TEXT_STRING)
    }
    sample_campaign._update_values(new_data)
    sample_campaign.update()

    response = Campaign.get_by_id(sample_campaign.id)
    for key, value in new_data.items():
        assert getattr(response, key) == value
Exemplo n.º 9
0
def test_delete_unknown():
    campaign = Campaign(**sample_campaign_data())
    campaign.id = 1289
    with pytest.raises(ErrorCampaignNotFound):
        campaign.delete()
Exemplo n.º 10
0
def test_get_by_id_valid(sample_campaign):

    response = Campaign.get_by_id(sample_campaign.id)
    assert response == sample_campaign
Exemplo n.º 11
0
def test_get_by_id_unknown():
    with pytest.raises(ErrorCampaignNotFound):
        Campaign.get_by_id(12120)
Exemplo n.º 12
0
def test_get_by_id_invalid(id_value):
    with pytest.raises(Exception):
        Campaign.get_by_id(id_value)