Skip to content

Commit

Permalink
Merge pull request #165 from readthedocs/add-campaign-type
Browse files Browse the repository at this point in the history
Add campaign_type to the ad decision response
  • Loading branch information
ericholscher committed Jul 6, 2020
2 parents d36d150 + 0e54b28 commit 80b8da2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions adserver/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class AdDecisionView(GeoIpMixin, APIView):
:>json string nonce: A one-time nonce used in the URLs so the ad is never double counted
:>json string display_type: The slug of type of ad (eg. sidebar)
:>json string div_id: The <div> ID where the ad will be inserted
:>json string campaign_type: The type of campaign this as is from (house or paid)
.. http:get:: /api/v1/decision/
Expand Down
1 change: 1 addition & 0 deletions adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ def as_dict(self):
"view_url": view_url,
"nonce": nonce,
"display_type": self.ad_type.slug,
"campaign_type": self.flight.campaign.campaign_type,
}

def cache_key(self, impression_type, nonce):
Expand Down
3 changes: 3 additions & 0 deletions adserver/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def test_campaign_types(self):
self.assertEqual(resp.status_code, 200, resp.content)
resp_json = resp.json()
self.assertEqual(resp_json["id"], "ad-slug", resp_json)
self.assertEqual(resp_json["campaign_type"], PAID_CAMPAIGN)

# Try community only
data["campaign_types"] = [COMMUNITY_CAMPAIGN]
Expand All @@ -424,6 +425,7 @@ def test_campaign_types(self):
self.assertEqual(resp.status_code, 200, resp.content)
resp_json = resp.json()
self.assertEqual(resp_json["id"], "ad-slug", resp_json)
self.assertEqual(resp_json["campaign_type"], COMMUNITY_CAMPAIGN)

# Try multiple campaign types
data["campaign_types"] = [PAID_CAMPAIGN, HOUSE_CAMPAIGN]
Expand All @@ -442,6 +444,7 @@ def test_campaign_types(self):
self.assertEqual(resp.status_code, 200, resp.content)
resp_json = resp.json()
self.assertEqual(resp_json["id"], "ad-slug", resp_json)
self.assertEqual(resp_json["campaign_type"], HOUSE_CAMPAIGN)

# try an invalid campaign type
data["campaign_types"] = [PAID_CAMPAIGN, HOUSE_CAMPAIGN, "unknown"]
Expand Down

0 comments on commit 80b8da2

Please sign in to comment.