Example #1
0
    def test_reschedule_campaign_with_missing_fields_in_schedule_data(
            self, token_first, campaign_in_db, smartlist_first,
            schedule_a_campaign):
        """
        Reschedule a campaign without `start_datetime` or `end_datetime` in schedule data
        and it will raise InvalidUsage/BadRequest (400).
        """
        # Test missing start_datetime field which is mandatory to schedule a campaign
        data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
        del data['start_datetime']
        response = reschedule_campaign(campaign_in_db['id'],
                                       data,
                                       token_first,
                                       expected_status=(codes.BAD_REQUEST, ))
        error = response['error']
        assert 'start_datetime' in error['message']

        data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
        del data['end_datetime']
        response = reschedule_campaign(campaign_in_db['id'],
                                       data,
                                       token_first,
                                       expected_status=(codes.BAD_REQUEST, ))
        error = response['error']
        assert 'end_datetime' in error['message']
Example #2
0
 def test_reschedule_campaign_with_valid_data(
         self, token_first, campaign_in_db, talent_pool, candidate_first,
         smartlist_first, schedule_a_campaign, candidate_device_first):
     """
     Reschedule a campaign with valid data and it should return 200 response.
     """
     sleep(15)
     data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
     response = send_request(
         'put', PushCampaignApiUrl.SCHEDULE % campaign_in_db['id'],
         token_first, data)
     assert response.status_code == codes.OK
     response = response.json()
     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)
     retry(get_blasts,
           attempts=30,
           sleepscale=1,
           sleeptime=3,
           retry_exceptions=(AssertionError, ),
           args=(campaign_in_db['id'], token_first),
           kwargs={'count': 2})
Example #3
0
    def test_reschedule_a_campaign_with_user_from_same_domain(
            self, token_first, token_same_domain, campaign_in_db,
            schedule_a_campaign):
        """
        In this test, we will reschedule 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
        rescheduled.
        """
        # schedule_a_campaign fixture schedules a job. So, wait for next 10 seconds for the job to run and increase
        # blast count
        sleep(10)
        data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
        response = reschedule_campaign(campaign_in_db['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)
        retry(get_blasts,
              attempts=30,
              sleepscale=1,
              sleeptime=3,
              retry_exceptions=(AssertionError, ),
              args=(campaign_in_db['id'], token_first),
              kwargs={'count': 2})
Example #4
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})
Example #5
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})
Example #6
0
 def test_unschedule_campaign_with_invalid_token(self, campaign_in_db,
                                                 smartlist_first):
     """
      Try to unschedule a campaign with invalid aut token nd  API will raise 401 error.
     """
     # data not needed here but just to be consistent with other requests of
     # this resource test
     data = generate_campaign_schedule_data()
     unauthorize_test('delete', URL % campaign_in_db['id'], data)
Example #7
0
 def test_schedule_campaign_with_missing_fields_in_schedule_data(
         self, token_first, campaign_in_db, smartlist_first):
     """
     Schedule a campaign without `start_datetime` in schedule data and it will raise InvalidUsage (400).
     """
     # Test missing start_datetime field which is mandatory to schedule a campaign
     data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
     missing_keys_test(URL % campaign_in_db['id'], data,
                       ['start_datetime', 'end_datetime'], token_first)
Example #8
0
 def test_campaign_schedule_with_unexpected_field(self, token_first,
                                                  campaign_in_db):
     """
     Send a POST request to schedule a campaign with data where one field is unexpected/not allowed. API
     will raise InvalidUsage 400
     :param string token_first: auth token
     :param dict campaign_in_db: campaign object
     """
     data = generate_campaign_schedule_data()
     unexpected_field_test('post', URL % campaign_in_db['id'], data,
                           token_first)
Example #9
0
 def test_campaign_schedule_with_past_datetimes(self, token_first,
                                                campaign_in_db):
     """
     Send a POST request to schedule a campaign with data where start datetime is in past. API
     will raise InvalidUsage 400
     :param string token_first: auth token
     :param dict campaign_in_db: campaign object
     """
     data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
     CampaignsTestsHelpers.request_with_past_start_and_end_datetime(
         'post', URL % campaign_in_db['id'], token_first, data)
Example #10
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, ))
Example #11
0
 def test_reschedule_campaign_with_other_user(self, token_second,
                                              campaign_in_db):
     """
     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 reschedule this campaign using different token_first "token_second"
     """
     data = generate_campaign_schedule_data()
     reschedule_campaign(campaign_in_db['id'],
                         data,
                         token_second,
                         expected_status=(codes.FORBIDDEN, ))
Example #12
0
 def test_schedule_campaign_with_put_method(self, token_first,
                                            campaign_in_db,
                                            smartlist_first):
     """
     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 = generate_campaign_schedule_data()
     reschedule_campaign(campaign_in_db['id'],
                         data,
                         token_first,
                         expected_status=(codes.FORBIDDEN, ))
Example #13
0
 def test_reschedule_campaign_with_deleted_smartlist(
         self, token_first, campaign_in_db, talent_pool, candidate_first,
         smartlist_first, schedule_a_campaign, candidate_device_first):
     """
     Reschedule a campaign that has a deleted smartlist associated with it.
     Api should raise InvalidUsage error 400 .
     """
     data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
     campaign_id = campaign_in_db['id']
     # Reschedule a campaign with deleted smarlist. API will raise 400 error.
     CampaignsTestsHelpers.send_request_with_deleted_smartlist(
         'put', URL % campaign_id, token_first, smartlist_first['id'], data)
Example #14
0
 def test_campaign_reschedule_with_unexpected_field(self, token_first,
                                                    campaign_in_db,
                                                    schedule_a_campaign):
     """
     Try to reschedule a campaign with data having invalid field, API will raise InvalidUsage 400
     :param string token_first: auth token
     :param dict campaign_in_db: campaign object
     :param dict schedule_a_campaign: a fixture to schedule a campaign
     """
     data = generate_campaign_schedule_data()
     unexpected_field_test('post', URL % campaign_in_db['id'], data,
                           token_first)
Example #15
0
 def test_campaign_reschedule_with_past_datetimes(self, token_first,
                                                  campaign_in_db,
                                                  schedule_a_campaign):
     """
     Try to reschedule a campaign with start_datetime and end_datetime in past. API will raise Invalid Usage 400
     :param string token_first: auth token
     :param dict campaign_in_db: campaign object
     :param dict schedule_a_campaign: a fixture to schedule a campaign
     """
     data = generate_campaign_schedule_data(frequency_id=Frequency.DAILY)
     CampaignsTestsHelpers.request_with_past_start_and_end_datetime(
         'put', URL % campaign_in_db['id'], token_first, data)
Example #16
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, ))
Example #17
0
 def test_campaign_schedule_with_invalid_frequency_id(
         self, token_first, campaign_in_db):
     """
     Send a POST request to schedule a campaign with data where start datetime is in past. API
     will raise InvalidUsage 400
     :param string token_first: auth token
     :param dict campaign_in_db: campaign object
     """
     url = URL % campaign_in_db['id']
     data = generate_campaign_schedule_data()
     invalid_value_test(url, data, 'frequency_id',
                        CampaignsTestsHelpers.INVALID_FREQUENCY_IDS,
                        token_first)
Example #18
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, ))
Example #19
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, ))
Example #20
0
 def test_campaign_reschedule_with_invalid_frequency_ids(
         self, token_first, campaign_in_db, schedule_a_campaign):
     """
     Try to reschedule a campaign with invalid frequency id like -1, API will raise InvalidUsage 400
     :param string token_first: auth token
     :param dict campaign_in_db: campaign object
     :param dict schedule_a_campaign: a fixture to schedule a campaign
     """
     url = URL % campaign_in_db['id']
     data = generate_campaign_schedule_data()
     invalid_value_test(url,
                        data,
                        'frequency_id',
                        CampaignsTestsHelpers.INVALID_FREQUENCY_IDS,
                        token_first,
                        method='put')
Example #21
0
    def test_reschedule_campaign_with_invalid_campaign_id(
            self, token_first, campaign_in_db, smartlist_first,
            schedule_a_campaign):
        """
        Try to reschedule a campaign that does not exists, it will raise BadRequest (for 0as id) or NotFoundError
        """
        data = generate_campaign_schedule_data()

        # Test with invalid integer id
        # Test for 404, Schedule a campaign which does not exists or id is invalid
        non_existing_id = sys.maxint
        invalid_ids = [(0, codes.BAD_REQUEST),
                       (non_existing_id, codes.NOT_FOUND)]
        for _id, status_code in invalid_ids:
            reschedule_campaign(_id,
                                data,
                                token_first,
                                expected_status=(status_code, ))
Example #22
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