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
def test_delete_invalid(): campaign = Campaign(**sample_campaign_data()) with pytest.raises(Exception): campaign.delete() campaign.id = 0 with pytest.raises(Exception): campaign.delete()
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)
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
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
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']
def test_delete_unknown(): campaign = Campaign(**sample_campaign_data()) campaign.id = 1289 with pytest.raises(ErrorCampaignNotFound): campaign.delete()