Beispiel #1
0
 def test_update_deleted_campaign(self, token_first, campaign_in_db,
                                  smartlist_first):
     """
     Try to update a campaign that has been delete, API will raise ResourceNotFound (404) error
     :param token_first: auth token
     :param smartlist_first: smartlist object
     :param campaign_in_db: campaign object
     """
     # Test `raise ResourceNotFound('Campaign not found with id %s' % campaign_id)`
     campaign_id = campaign_in_db['id']
     delete_campaign(campaign_id, token_first)
     data = generate_campaign_data()
     data['smartlist_ids'] = [smartlist_first['id']]
     update_campaign(campaign_id,
                     data,
                     token_first,
                     expected_status=(codes.NOT_FOUND, ))
Beispiel #2
0
 def test_update_campaign_from_diff_domain(self, token_second,
                                           campaign_in_db, smartlist_first):
     """
     We will try to update a campaign but user is not owner and from a different domain,
     so we are expecting Forbidden (403) error
     :param token_second: auth token
     :param campaign_in_db: campaign object
     :param smartlist_first: smartlist object
     """
     # Test `raise ForbiddenError`
     data = generate_campaign_data()
     data['smartlist_ids'] = [smartlist_first['id']]
     campaign_id = campaign_in_db['id']
     update_campaign(campaign_id,
                     data,
                     token_second,
                     expected_status=(codes.FORBIDDEN, ))
Beispiel #3
0
 def test_update_campaign_with_invalid_field(self, token_first,
                                             campaign_in_db,
                                             smartlist_first):
     """
     Try to update a campaign with an invalid key in campaign data , API will raise
     InvalidUsage (400) error
     :param token_first: auth token
     :param campaign_in_db: campaign object
     :param smartlist_first: smartlist object
     """
     # Test invalid field
     data = generate_campaign_data()
     data['smartlist_ids'] = [smartlist_first['id']]
     # valid fields for push campaign are ['name', 'body_text', 'smartlist_ids', 'url`]
     data['invalid_field_name'] = 'Any Value'
     campaign_id = campaign_in_db['id']
     update_campaign(campaign_id,
                     data,
                     token_first,
                     expected_status=(codes.BAD_REQUEST, ))
Beispiel #4
0
 def test_update_campaign_with_invalid_id(self, token_first,
                                          smartlist_first):
     """
     Try to update a campaign that does not exist, API will raise ResourceNotFound (404) error
     :param token_first: auth token
     :param smartlist_first: smartlist object
     """
     # Test `raise ResourceNotFound('Campaign not found with id %s' % campaign_id)`
     data = generate_campaign_data()
     data['smartlist_ids'] = [smartlist_first['id']]
     invalid_id = sys.maxint
     update_campaign(invalid_id,
                     data,
                     token_first,
                     expected_status=(codes.NOT_FOUND, ))
     # test with id: 0, it should raise InvalidUsage
     update_campaign(0,
                     data,
                     token_first,
                     expected_status=(codes.BAD_REQUEST, ))
Beispiel #5
0
    def test_put_by_id_with_valid_data(self, token_first, campaign_in_db,
                                       smartlist_first):
        """
        Try to update a campaign with valid data, we are expecting that API will
        update the campaign successfully (200)
        :param token_first: auth token
        :param campaign_in_db: campaign object
        :param smartlist_first: smartlist object
        """
        # Test positive case with valid data
        data = generate_campaign_data()
        data['smartlist_ids'] = [smartlist_first['id']]
        campaign_id = campaign_in_db['id']
        update_campaign(campaign_id,
                        data,
                        token_first,
                        expected_status=(codes.OK, ))

        # Now get campaign from API and compare data.
        json_response = get_campaign(campaign_id, token_first)
        campaign = json_response['campaign']
        # Compare sent campaign dict and campaign dict returned by API.
        compare_campaign_data(data, campaign, ignore_keys=['id'])