Esempio n. 1
0
    def test_campaign_send_to_smartlist_with_two_candidates_with_and_without_push_device(self, token_first,
                                                    campaign_with_two_candidates_with_and_without_push_device):
        """
        - This tests the endpoint /v1/push-campaigns/:id/send
        In this test I want to test the scenario that if a push campaign is being sent to multiple candidates and
        there is one or more but not all candidates that do not have a push device associated with them,
        then it should not raise an InvalidUsage error but sends should be equal to number of candidates
        that have devices associated with them.
        """
        campaign_id = campaign_with_two_candidates_with_and_without_push_device['id']
        send_campaign(campaign_id, token_first, expected_status=(codes.OK,))

        # Assert campaign send activity
        assert_activity(Activity.MessageIds.CAMPAIGN_SEND, campaign_id, 'push_campaign', token_first)

        response = retry(get_blasts, sleeptime=SLEEP_INTERVAL, attempts=RETRY_ATTEMPTS * 2, sleepscale=1,
                         retry_exceptions=(AssertionError,), args=(campaign_id, token_first), kwargs={'count': 1})
        blasts = response['blasts']
        blast_id = blasts[0]['id']

        # There should be only one send because second candidate in smartlist does not have any push device associated
        # with him.
        response = retry(get_blast_sends, sleeptime=SLEEP_INTERVAL, attempts=RETRY_ATTEMPTS * 2, sleepscale=1,
                         retry_exceptions=(AssertionError,), args=(blast_id, campaign_id, token_first),
                         kwargs={'count': 1})
        assert len(response['sends']) == 1
Esempio n. 2
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})
Esempio n. 3
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})
Esempio n. 4
0
 def test_campaigns_delete_with_authorized_ids(self, token_first, campaign_in_db):
     """
     User auth token is valid, data type is valid and ids are valid
     (campaign corresponds to user). Response should be OK.
     :param token_first: auth token
     :param campaign_in_db: campaign created in fixture
     """
     data = {'ids': [campaign_in_db['id']]}
     delete_campaigns(data, token_first, expected_status=(codes.OK,))
     assert_activity(Activity.MessageIds.CAMPAIGN_DELETE, campaign_in_db['id'], 'push_campaign', token_first)
Esempio n. 5
0
    def test_campaigns_delete_with_other_user_with_same_domain(self, token_same_domain, campaign_in_db):
        """
        User auth token is valid, data type is valid and ids are of those campaigns that
        belong to some other user. It should get unauthorized error.
        :param token_same_domain: auth token
        :param campaign_in_db: campaign created by user_first
        """
        data = {'ids': [campaign_in_db['id']]}
        delete_campaigns(data, token_same_domain, expected_status=(codes.OK,))

        # Check campaign creation activity
        assert_activity(Activity.MessageIds.CAMPAIGN_DELETE, campaign_in_db['id'], 'push_campaign', token_same_domain)
Esempio n. 6
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
Esempio n. 7
0
    def test_send_campaign_with_other_user_in_same_domain(self, token_same_domain, campaign_in_db,
                                                          smartlist_first, candidate_device_first):
        """
        User in same domain can send a campaign
        We are expecting 200 status here.
        :param token_same_domain: token for a user that is not owner but in same domain
        :param campaign_in_db: campaign in same domain but created by different user in same domain
        """
        # 200 case: Campaign Sent successfully
        send_campaign(campaign_in_db['id'], token_same_domain, expected_status=(codes.OK,))

        # Assert campaign send activity
        assert_activity(Activity.MessageIds.CAMPAIGN_SEND, campaign_in_db['id'], 'push_campaign', token_same_domain)

        response = retry(get_blasts, sleeptime=3, attempts=20, sleepscale=1, retry_exceptions=(AssertionError,),
                         args=(campaign_in_db['id'], token_same_domain), kwargs={'count': 1})
        blasts = response['blasts']
        blast_id = blasts[0]['id']
        response = retry(get_blast_sends, sleeptime=SLEEP_INTERVAL, attempts=RETRY_ATTEMPTS * 2, sleepscale=1,
                         retry_exceptions=(AssertionError,), args=(blast_id, campaign_in_db['id'], token_same_domain),
                         kwargs={'count': 1})
        assert len(response['sends']) == 1
Esempio n. 8
0
    def test_campaign_send_with_multiple_smartlists(self, token_first,
                                                    campaign_in_db_multiple_smartlists):
        """
        - This tests the endpoint /v1/push-campaigns/:id/send

        User auth token_first is valid, campaign has one smart list associated. Smartlist has one
        candidate.
        """
        campaign_id = campaign_in_db_multiple_smartlists['id']
        send_campaign(campaign_id, token_first, expected_status=(codes.OK,))

        # Assert campaign send activity
        assert_activity(Activity.MessageIds.CAMPAIGN_SEND, campaign_id, 'push_campaign', token_first)

        response = retry(get_blasts, sleeptime=3, attempts=20, sleepscale=1, retry_exceptions=(AssertionError,),
                         args=(campaign_id, token_first), kwargs={'count': 1})
        blasts = response['blasts']
        blast_id = blasts[0]['id']
        response = retry(get_blast_sends, sleeptime=SLEEP_INTERVAL, attempts=RETRY_ATTEMPTS * 2, sleepscale=1,
                         retry_exceptions=(AssertionError,), args=(blast_id, campaign_id, token_first),
                         kwargs={'count': 2})
        assert len(response['sends']) == 2
Esempio n. 9
0
    def test_send_a_camapign_with_valid_data(self, token_first, campaign_in_db,
                                             smartlist_first, candidate_device_first):
        """
        We will try to send a campaign and we are expecting 200 response
        :param token_first: auth token
        :param campaign_in_db: campaign object
        :param smartlist_first: smartlist object
        """
        # 200 case: Campaign Sent successfully
        send_campaign(campaign_in_db['id'], token_first, expected_status=(codes.OK,))

        # Assert campaign send activity
        assert_activity(Activity.MessageIds.CAMPAIGN_SEND, campaign_in_db['id'], 'push_campaign', token_first)

        response = retry(get_blasts, sleeptime=SLEEP_INTERVAL, attempts=RETRY_ATTEMPTS * 2, sleepscale=1,
                         retry_exceptions=(AssertionError,), args=(campaign_in_db['id'], token_first),
                         kwargs={'count': 1})
        blasts = response['blasts']
        blast_id = blasts[0]['id']
        response = retry(get_blast_sends, sleeptime=SLEEP_INTERVAL, attempts=RETRY_ATTEMPTS * 2, sleepscale=1,
                         retry_exceptions=(AssertionError,), args=(blast_id, campaign_in_db['id'], token_first),
                         kwargs={'count': 1})
        assert len(response['sends']) == 1