예제 #1
0
 def test_schedule_campaign_with_invalid_token(self, campaign_in_db,
                                               smartlist_first):
     """
     Try to schedule a campaign with invalid AuthToken and API will rasie Unauthorized error (401).
     """
     # data not needed here but just to be consistent with other requests of
     # this resource test
     data = generate_campaign_schedule_data()
     campaign_id = campaign_in_db['id']
     schedule_campaign(campaign_id,
                       data,
                       'invalid_token',
                       expected_status=(codes.UNAUTHORIZED, ))
예제 #2
0
 def test_reschedule_campaign_with_post_method(self, token_first,
                                               campaign_in_db,
                                               smartlist_first,
                                               schedule_a_campaign):
     """
     Test forbidden error. To schedule a task first time, we have to send POST,
     but we will send request using PUT which is for update and will validate error
     """
     data = schedule_a_campaign
     schedule_campaign(campaign_in_db['id'],
                       data,
                       token_first,
                       expected_status=(codes.FORBIDDEN, ))
예제 #3
0
 def test_schedule_campaign_with_invalid_campaign_id(
         self, token_first, campaign_in_db, smartlist_first):
     """
     Try to schedule a campaign that does not exists, it will raise BadRequest (400 in case of 0) or NotFound 404.
     """
     data = generate_campaign_schedule_data()
     # Test with invalid or non-existing id
     non_existing_id = sys.maxint
     invalid_ids = [(0, codes.BAD_REQUEST),
                    (non_existing_id, codes.NOT_FOUND)]
     for _id, status_code in invalid_ids:
         schedule_campaign(_id,
                           data,
                           token_first,
                           expected_status=(status_code, ))
예제 #4
0
 def test_schedule_a_campaign_with_user_from_diff_domain(
         self, token_first, token_second, campaign_in_db,
         candidate_device_first):
     """
     Test with a valid campaign but user is not owner of campaign
     Here we created campaign with user whose Auth token_first is "token_first"
     and we want to schedule this campaign with other user with token_first "token_second"
     :param token_second: auth token for user from different domain
     :param token_first: auth token for first user
     :param campaign_in_db: campaign dict object
     """
     data = generate_campaign_schedule_data()
     schedule_campaign(campaign_in_db['id'],
                       data,
                       token_second,
                       expected_status=(codes.FORBIDDEN, ))
예제 #5
0
    def test_schedule_a_campaign_with_user_from_same_domain(
            self, smartlist_first, campaign_in_db, talent_pool, token_first,
            token_same_domain, candidate_device_first):
        """
        In this test, we will schedule a campaign using different user's auth token, but user is from same domain ,
        as the actual owner of the campaign. So we are expecting that , response will be OK and campaign will be
        scheduled.
        """

        campaign_id = campaign_in_db['id']
        data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
        response = schedule_campaign(campaign_id,
                                     data,
                                     token_same_domain,
                                     expected_status=(codes.OK, ))
        assert 'task_id' in response
        assert 'message' in response
        task_id = response['task_id']
        assert task_id

        # campaign = get_campaign(campaign_in_db['id'], token_first)['campaign']
        # match_schedule_data(data, campaign)

        # There should be a campaign schedule activity
        assert_activity(Activity.MessageIds.CAMPAIGN_SCHEDULE,
                        campaign_in_db['id'], 'push_campaign',
                        token_same_domain)

        retry(get_blasts,
              sleeptime=3,
              attempts=30,
              sleepscale=1,
              retry_exceptions=(AssertionError, ),
              args=(campaign_id, token_first),
              kwargs={'count': 1})
예제 #6
0
    def test_schedule_a_campaign_with_valid_data(self, smartlist_first,
                                                 campaign_in_db, talent_pool,
                                                 token_first,
                                                 candidate_device_first):
        """
        In this test, we will schedule a campaign with all valid data and it should return an OK response and campaign
        should be scheduled.
        """
        data = generate_campaign_schedule_data()
        response = schedule_campaign(campaign_in_db['id'],
                                     data,
                                     token_first,
                                     expected_status=(codes.OK, ))
        assert 'task_id' in response
        assert 'message' in response
        task_id = response['task_id']
        assert task_id

        # There should be a campaign schedule activity
        assert_activity(Activity.MessageIds.CAMPAIGN_SCHEDULE,
                        campaign_in_db['id'], 'push_campaign', token_first)

        # campaign = get_campaign(campaign_in_db['id'], token_first)['campaign']
        # match_schedule_data(data, campaign)
        retry(get_blasts,
              sleeptime=3,
              attempts=20,
              sleepscale=1,
              retry_exceptions=(AssertionError, ),
              args=(campaign_in_db['id'], token_first),
              kwargs={'count': 1})
예제 #7
0
    def test_schedule_compaign_with_invalid_datetime_format(
            self, token_first, campaign_in_db, smartlist_first):
        """
        In this test, we will schedule a campaign with invalid datetime format and  it will raise an error 400.
        """
        data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
        start = datetime.utcnow()
        data['start_datetime'] = str(start)  # Invalid datetime format
        schedule_campaign(campaign_in_db['id'],
                          data,
                          token_first,
                          expected_status=(codes.BAD_REQUEST, ))

        data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
        end = datetime.utcnow()
        data['end_datetime'] = str(end)  # Invalid datetime format
        schedule_campaign(campaign_in_db['id'],
                          data,
                          token_first,
                          expected_status=(codes.BAD_REQUEST, ))
예제 #8
0
def schedule_a_campaign(request, smartlist_first, campaign_in_db, token_first):
    """
    This fixture sends a POST request to Push campaign api to schedule this campaign,
    which will be further used in tests.
    :param request: request object
    :param smartlist_first: smartlist associated with campaign
    :param campaign_in_db: push campaign which is to be scheduled
    :return data: schedule data
    :rtype data: dict
    """
    task_id = None
    data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
    task_id = schedule_campaign(campaign_in_db['id'], data,
                                token_first)['task_id']

    def fin():
        delete_scheduler_task(task_id,
                              token_first,
                              expected_status=(codes.OK, codes.NOT_FOUND))

    request.addfinalizer(fin)
    return data