Skip to content

Commit

Permalink
Merge pull request #745 from readthedocs/davidfischer/remove-campaign…
Browse files Browse the repository at this point in the history
…-publishers

Stop using deprecated campaign.publishers
  • Loading branch information
davidfischer committed May 11, 2023
2 parents 87b8df3 + e4301fc commit e580fa8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
7 changes: 1 addition & 6 deletions adserver/decisionengine/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ def get_candidate_flights(self):
campaign__campaign_type__in=self.campaign_types,
)
.filter(
# Deprecated: remove after publisher groups are rolled out and configured in production
# At that point, only filter by publisher groups
models.Q(campaign__publishers=self.publisher)
| models.Q(
campaign__publisher_groups__in=self.publisher.publisher_groups.all()
)
campaign__publisher_groups__in=self.publisher.publisher_groups.all()
)
.exclude(campaign__exclude_publishers=self.publisher)
)
Expand Down
2 changes: 1 addition & 1 deletion adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class Campaign(TimeStampedModel, IndestructibleModel):
help_text=_("Ads for this campaign will not be shown on these publishers"),
)

# Deprecated and scheduled for removal
# Deprecated and no longer used. Will be removed in future releases
publishers = models.ManyToManyField(
Publisher,
related_name="campaigns",
Expand Down
14 changes: 8 additions & 6 deletions adserver/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ def setUp(self):
slug="campaign-slug",
advertiser=self.advertiser1,
publisher_groups=[self.publisher_group],
# Deprecated - will be removed
publishers=[self.publisher],
)
self.flight = get(
Flight, live=True, campaign=self.campaign, sold_clicks=1000, cpc=1.0
Expand Down Expand Up @@ -524,7 +522,7 @@ def test_publishers(self):
self.assertEqual(resp.json(), {})

# Allow this publisher on the campaign
self.campaign.publishers.add(self.publisher2)
self.publisher_group.publishers.add(self.publisher2)
resp = self.client.post(
self.url, json.dumps(data), content_type="application/json"
)
Expand Down Expand Up @@ -588,10 +586,14 @@ def test_publisher_groups(self):

def test_campaign_types(self):
community_campaign = get(
Campaign, publishers=[self.publisher], campaign_type=COMMUNITY_CAMPAIGN
Campaign,
publisher_groups=[self.publisher_group],
campaign_type=COMMUNITY_CAMPAIGN,
)
house_campaign = get(
Campaign, publishers=[self.publisher], campaign_type=HOUSE_CAMPAIGN
Campaign,
publisher_groups=[self.publisher_group],
campaign_type=HOUSE_CAMPAIGN,
)

data = {
Expand Down Expand Up @@ -1005,7 +1007,7 @@ def setUp(self):
super().setUp()

self.user.publishers.add(self.publisher2)
self.campaign.publishers.add(self.publisher2)
self.publisher_group.publishers.add(self.publisher2)

self.page_url = "http://example.com"

Expand Down
22 changes: 17 additions & 5 deletions adserver/tests/test_decision_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ..models import Campaign
from ..models import Flight
from ..models import Publisher
from ..models import PublisherGroup
from ..utils import GeolocationData
from ..utils import get_ad_day

Expand All @@ -32,8 +33,11 @@ def setUp(self):
self.publisher = get(
Publisher, slug="test-publisher", allow_paid_campaigns=True
)
self.publisher_group = get(PublisherGroup)
self.publisher_group.publishers.add(self.publisher)

self.ad_type = get(AdType, has_image=False, slug="z")
self.campaign = get(Campaign, publishers=[self.publisher])
self.campaign = get(Campaign, publisher_groups=[self.publisher_group])
self.include_flight = get(
Flight,
live=True,
Expand Down Expand Up @@ -546,7 +550,9 @@ def test_campaign_type_priority(self):

# Paid
paid_campaign = get(
Campaign, campaign_type=PAID_CAMPAIGN, publishers=[self.publisher]
Campaign,
campaign_type=PAID_CAMPAIGN,
publisher_groups=[self.publisher_group],
)
paid_flight = get(
Flight,
Expand All @@ -569,7 +575,9 @@ def test_campaign_type_priority(self):

# Affiliate
affiliate_campaign = get(
Campaign, campaign_type=AFFILIATE_CAMPAIGN, publishers=[self.publisher]
Campaign,
campaign_type=AFFILIATE_CAMPAIGN,
publisher_groups=[self.publisher_group],
)
affiliate_flight = get(
Flight,
Expand All @@ -592,7 +600,9 @@ def test_campaign_type_priority(self):

# Community
community_campaign = get(
Campaign, campaign_type=COMMUNITY_CAMPAIGN, publishers=[self.publisher]
Campaign,
campaign_type=COMMUNITY_CAMPAIGN,
publisher_groups=[self.publisher_group],
)
community_flight = get(
Flight,
Expand All @@ -614,7 +624,9 @@ def test_campaign_type_priority(self):

# House
house_campaign = get(
Campaign, campaign_type=HOUSE_CAMPAIGN, publishers=[self.publisher]
Campaign,
campaign_type=HOUSE_CAMPAIGN,
publisher_groups=[self.publisher_group],
)
house_campaign.campaign_type = HOUSE_CAMPAIGN
house_campaign.save()
Expand Down

0 comments on commit e580fa8

Please sign in to comment.