示例#1
0
 def test_request_ad_units(self):
     ad_unit_tag_id = generate_id()
     network_1_id = generate_id()
     network_2_id = generate_id()
     self.assertEqual(
         self.adServer.request_ad_units([ad_unit_tag_id],
                                        extra_params={
                                            'contest': 'Europolice'
                                        },
                                        cookies={
                                            network_1_id + '!Inspector':
                                            'Zatapathique',
                                            network_2_id + '!Inspector':
                                            'Muffin'
                                        }).status_code, 200)
     self.assertEqual(self.adServer.session.args['params']['tt'],
                      'composed')
     self.assertEqual(
         json.loads(self.adServer.session.data)['contest'], 'Europolice')
     self.assertEqual(
         len(json.loads(self.adServer.session.data)['adUnits']), 1)
     self.assertEqual(
         self.adServer.session.args['cookies'][network_1_id + '!Inspector'],
         'Zatapathique')
     self.assertEqual(
         self.adServer.session.args['cookies'][network_2_id + '!Inspector'],
         'Muffin')
示例#2
0
 def test_request_ad_unit_objects(self):
     ad_unit_tag_id = generate_id()
     self.assertEqual(
         self.adServer.request_ad_units([{
             'auId': ad_unit_tag_id,
             'targetId': 'one',
             'auml': 'label'
         }, {
             'auId': ad_unit_tag_id,
             'targetId': 'two',
             'auml': 'label'
         }]).status_code, 200)
     self.assertEqual(self.adServer.session.args['params']['tt'],
                      'composed')
     self.assertEqual(
         len(json.loads(self.adServer.session.data)['adUnits']), 2)
     self.assertEqual(
         json.loads(self.adServer.session.data)['adUnits'][0]['auId'],
         ad_unit_tag_id)
     self.assertEqual(
         json.loads(self.adServer.session.data)['adUnits'][0]['targetId'],
         'one')
     self.assertEqual(
         json.loads(self.adServer.session.data)['adUnits'][0]['auml'],
         'label')
     self.assertEqual(
         json.loads(self.adServer.session.data)['adUnits'][1]['auId'],
         ad_unit_tag_id)
     self.assertEqual(
         json.loads(self.adServer.session.data)['adUnits'][1]['targetId'],
         'two')
     self.assertEqual(
         json.loads(self.adServer.session.data)['adUnits'][1]['auml'],
         'label')
示例#3
0
 def test_update_and_query(self):
     self.api.segments.update({
         'id': generate_id(),
         'name': 'Axe',
         'description': 'Herring',
     })
     self.assertEqual(self.api.segments.query()['description'], 'Herring')
示例#4
0
 def test_visitor(self):
     self.assertEqual(
         self.dataServer.visitor(
             folder=generate_id(),
             browser='Ernest Scribbler',
             profile_values={
                 'Wenn ist das Nunstück git und Slotermeyer?':
                 'Ja! Beiherhund das Oder die Flipperwaldt gersput'
             }).status_code, 200)
示例#5
0
 def test_set_and_get_consent(self):
     network_id = generate_id()
     self.assertEqual(
         self.adServer.set_consent(network_id,
                                   consent='PROFILE').status_code, 200)
     self.assertEqual(
         json.loads(
             self.adServer.get_consent(network_id).json_data)['consent'],
         ['PROFILE'])
示例#6
0
 def test_request_ad_unit(self):
     ad_unit_tag_id = generate_id()
     self.assertEqual(
         self.adServer.request_ad_unit(ad_unit_tag_id,
                                       extra_params={
                                           'parrot': 'Norwegian Blue'
                                       }).status_code, 200)
     self.assertEqual(self.adServer.session.args['params']['auId'],
                      ad_unit_tag_id)
     self.assertEqual(self.adServer.session.args['params']['parrot'],
                      'Norwegian Blue')
示例#7
0
    def request_ad_units(self,
                         ad_units,
                         cookies=None,
                         headers=None,
                         extra_params=None,
                         meta_data=None,
                         key_values=None):
        """
        Makes a request for multiple ad units using a composed ad tag.
        :param ad_units: list of ids of the ad unit OR list of ad-unit request objects.
        :param cookies:  optional dictionary of cookies
        :param headers:  optional dictionary of headers
        :param extra_params:  optional dictionary of parameters to include in composed request
        :return:         the python requests response object. Response content can be accessed using response.text
        """
        if not isinstance(
                ad_units, list
        ):  # An accidental string here will create an ad unit for every character.
            raise ValueError("Specified Ad Units must be list")
        if not cookies:
            cookies = {}
        if not meta_data:
            meta_data = {}
        final_headers = {
            'Content-type': 'application/json',
            'Accept-Encoding': 'gzip'
        }
        if headers:
            final_headers.update(headers)
        data = {'adUnits': [], 'metaData': meta_data}

        for ad_unit in ad_units:
            if isinstance(ad_unit, str):
                # Create an ad-unit request from the supplied auId
                ad_unit = {'auId': ad_unit, 'targetId': generate_id()}
                if key_values:
                    ad_unit['kv'] = key_values
            data['adUnits'].append(ad_unit)

        if extra_params:
            data.update(extra_params)

        r = self.session.post(self.__get_base_url(headers) + "/i",
                              data=json.dumps(data),
                              params={'tt': 'composed'},
                              cookies=cookies,
                              headers=final_headers)
        return r
示例#8
0
 def test_post_and_exists(self):
     bruce_id = generate_id()
     self.assertEqual(
         self.api.users.post(bruce_id,
                             data={
                                 'id': bruce_id,
                                 'name': 'Bruce'
                             })['name'], 'Bruce')
     self.assertTrue(self.api.users.exists(bruce_id))
     self.assertEqual(
         self.api.users.post(bruce_id,
                             data={
                                 'id': bruce_id,
                                 'name': 'New Bruce'
                             })['name'], 'New Bruce')
     self.assertTrue(self.api.users.exists(bruce_id))
示例#9
0
    def request_rtb_ad_unit(self,
                            ad_unit,
                            request=None,
                            cookies=None,
                            headers=None):
        """
        Makes a request for an ad unit.
        :param ad_unit:       the ad unit.
        :param request:       optional RTB request. Will be filled with default values if only ad_unit is supplied
        :param cookies:       optional dictionary of cookies
        :param headers:       optional dictionary of headers
        :return:              the python requests response object. Response content can be accessed using response.text
        """
        if not cookies:
            cookies = {}
        if not headers:
            headers = {}
        headers['Accept-Encoding'] = 'gzip'

        impression = {
            "id": 1,
            "instl": 0,
            "tagid": ad_unit['tagId'],
            "bidfloor": 0.0,
            "bidfloorcur": "USD",
            "banner": {
                "w": ad_unit['width'],
                "h": ad_unit['height']
            }
        }

        site = {
            "id": 0,
            "name": "",
            "domain": "",
            "publisher": {
                "id": 0,
                "name": "",
                "domain": ""
            }
        }

        device = {"ua": "", "ip": "127.0.0.1"}

        user = {"id": generate_id(), "buyeruid": generate_id()}

        data = {
            "id": generate_id(),
            "at": 2,
            "bcat": [],
            "badv": [],
            "imp": [impression],
            "site": site,
            "device": device,
            "user": user
        }

        # Override the defaults if something is supplied
        if request is not None:
            data.update(request)

        r = self.session.post(self.__get_base_url(headers) + "/rtb",
                              data=json.dumps(data),
                              cookies=cookies,
                              headers=headers)
        return r
示例#10
0
 def test_page(self):
     self.assertEqual(
         self.dataServer.page('green-midget-cafe.com',
                              folder=generate_id(),
                              browser='Mr Bun',
                              keywords=['spam']).status_code, 200)