Пример #1
0
def campaign_in_db_multiple_smartlists(request, token_first, smartlist_first,
                                       campaign_data, smartlist_same_domain,
                                       candidate_device_first,
                                       candidate_device_same_domain):
    """
    This fixtures creates a campaign which is associated with multiple (two) smartlists.
    :param request:
    :param token_first: at belongs to same users, and one created by other
    user from same domain
    :param smartlist_first: smartlist dict object owned by user_first
    :param smartlist_same_domain: smartlist dict object owned by user_same_domain
    :param campaign_data: dict data to create campaign
    :return: campaign data
    """
    data = campaign_data.copy()
    data['smartlist_ids'] = [
        smartlist_first['id'], smartlist_same_domain['id']
    ]
    campaign_id = create_campaign(data, token_first)['id']
    data['id'] = campaign_id

    def tear_down():
        delete_campaign(campaign_id,
                        token_first,
                        expected_status=(codes.OK, codes.NOT_FOUND))

    request.addfinalizer(tear_down)
    return data
Пример #2
0
def campaigns_for_pagination_test(request, token_first, smartlist_first,
                                  campaign_data):
    """
    This fixture creates a multiple campaigns to test pagination functionality.
    :param request: request object
    :param token_first: authentication token for user_first
    :param smartlist_first: smartlist dict object
    :param campaign_data: data to create campaign
    :return: campaigns count
    """
    campaigns_count = 15
    data = campaign_data.copy()
    data['smartlist_ids'] = [smartlist_first['id']]
    ids = []
    for _ in xrange(campaigns_count):
        id_ = create_campaign(data, token_first)['id']
        ids.append(id_)

    def tear_down():
        data = {'ids': ids}
        delete_campaigns(data,
                         token_first,
                         expected_status=(codes.OK, codes.MULTI_STATUS))

    request.addfinalizer(tear_down)
    return campaigns_count
Пример #3
0
def campaign_with_two_candidates_with_no_push_device_associated(
        request, token_first,
        smartlist_with_two_candidates_with_no_device_associated,
        campaign_data):
    """
    This fixtures creates a campaign which is associated with one smartlist having two candidates. One candidate
    has a push device but other does not.
    :param request:
    :param token_first: at belongs to same users, and one created by other
    user from same domain
    :param smartlist_with_two_candidates_with_no_device_associated: smartlist dict object owned by user_first
    :param campaign_data: dict data to create campaign
    :return: campaign data
    """
    data = campaign_data.copy()
    data['smartlist_ids'] = [
        smartlist_with_two_candidates_with_no_device_associated['id']
    ]
    campaign_id = create_campaign(data, token_first)['id']
    data['id'] = campaign_id

    def tear_down():
        delete_campaign(campaign_id,
                        token_first,
                        expected_status=(codes.OK, codes.NOT_FOUND))

    request.addfinalizer(tear_down)
    return data
Пример #4
0
 def test_campaign_creation_with_smartlist_of_other_domain(self, token_first, campaign_data, smartlist_second):
     """
     Try to create campaign with smartlist of other domain, API should raise 403 (forbidden).
     """
     smartlist_id = smartlist_second['id']
     data = campaign_data.copy()
     data['smartlist_ids'] = [smartlist_id]
     response = create_campaign(data, token_first, expected_status=(codes.FORBIDDEN,))
Пример #5
0
 def test_create_campaign_with_valid_data(self, token_first, campaign_data, smartlist_first):
     """
     Here we will send a valid data to create a campaign and we are expecting 201 (created)
     :param string token_first: auth token
     :param dict campaign_data: data to create campaign
     :param dict smartlist_first: Smartlist object
     """
     # Success case. Send a valid data and campaign should be created (201)
     data = campaign_data.copy()
     data['smartlist_ids'] = [smartlist_first['id']]
     response = create_campaign(data, token_first, expected_status=(codes.CREATED,))
     _id = response['id']
     assert response['message'] == 'Push campaign was created successfully'
     assert response['headers']['Location'] == PushCampaignApiUrl.CAMPAIGN % _id
     assert_activity(Activity.MessageIds.CAMPAIGN_CREATE, _id, 'push_campaign', token_first)
     # To delete this in finalizer, add id and token
     campaign_data['id'] = _id
     campaign_data['token'] = token_first
Пример #6
0
def campaign_in_db(request, token_first, smartlist_first, campaign_data):
    """
    This fixture creates a campaign in database by hitting push campaign service api
    :param request: request object
    :param token_first: authentication token for user_first
    :param smartlist_first: smartlist dict object
    :param campaign_data: data to create campaign
    :return: campaign dict object
    """
    previous_count = len(get_campaigns(token_first)['campaigns'])
    data = campaign_data.copy()
    data['smartlist_ids'] = [smartlist_first['id']]
    campaign_id = create_campaign(data, token_first)['id']
    data['id'] = campaign_id
    data['previous_count'] = previous_count

    def tear_down():
        delete_campaign(campaign_id,
                        token_first,
                        expected_status=(codes.OK, codes.NOT_FOUND))

    request.addfinalizer(tear_down)
    return data
Пример #7
0
def campaign_in_db_second(request, token_second, user_second, smartlist_second,
                          campaign_data):
    """
    This fixture creates a push campaign in database for sample_user
    user_second fixture is required here to add ROLLS for user.
    :param request:
    :param token_second: token for user_second
    :param smartlist_second: test smartlist associated to user_second
    :param campaign_data: dictionary containing campaign data
    :return: campaign data
    """
    data = campaign_data.copy()
    data['smartlist_ids'] = [smartlist_second['id']]
    campaign_id = create_campaign(data, token_second)['id']
    data['id'] = campaign_id

    def tear_down():
        delete_campaign(campaign_id,
                        token_second,
                        expected_status=(codes.OK, codes.NOT_FOUND))

    request.addfinalizer(tear_down)
    return data
Пример #8
0
 def test_create_campaign_with_invalid_token(self, campaign_data):
     """
     Send request with invalid token and 401 status code is expected
     :param campaign_data: dictionary data for campaign
     """
     create_campaign(campaign_data, 'invalid_token', expected_status=(codes.UNAUTHORIZED,))