diff options
author | Vitor Freitas | 2019-05-25 19:34:29 +0300 |
---|---|---|
committer | Vitor Freitas | 2019-05-25 19:34:29 +0300 |
commit | a735944af7f5aa1c67dd0a89f2e593bb5022fdcf (patch) | |
tree | 2ce50e1c70426222d41a46ff74189261a4e117e6 | |
parent | d9d5b617ecd523221013921960371e2b28d45b90 (diff) | |
download | colossus-a735944af7f5aa1c67dd0a89f2e593bb5022fdcf.tar.gz colossus-a735944af7f5aa1c67dd0a89f2e593bb5022fdcf.tar.bz2 colossus-a735944af7f5aa1c67dd0a89f2e593bb5022fdcf.zip |
Fix exception when campaign has no mailing list
-rw-r--r-- | colossus/apps/campaigns/forms.py | 2 | ||||
-rw-r--r-- | colossus/apps/campaigns/tests/test_views.py | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/colossus/apps/campaigns/forms.py b/colossus/apps/campaigns/forms.py index 6f675cf..3ec7666 100644 --- a/colossus/apps/campaigns/forms.py +++ b/colossus/apps/campaigns/forms.py @@ -72,7 +72,7 @@ class CampaignRecipientsForm(forms.ModelForm): self.fields['tag'].queryset = Tag.objects.filter(mailing_list_id=mailing_list_id).order_by('name') except (ValueError, TypeError): pass - elif self.instance.pk: + elif self.instance.pk and self.instance.mailing_list: self.fields['tag'].queryset = self.instance.mailing_list.tags.order_by('name') diff --git a/colossus/apps/campaigns/tests/test_views.py b/colossus/apps/campaigns/tests/test_views.py index 48f314b..d4525bf 100644 --- a/colossus/apps/campaigns/tests/test_views.py +++ b/colossus/apps/campaigns/tests/test_views.py @@ -92,3 +92,14 @@ class CampaignCreateViewTests(AuthenticatedTestCase): response = self.client.get(self.url) self.assertContains(response, '<input type="hidden"', 3) # csrf_token, mailing_list, tag self.assertContains(response, '<input type="text"', 1) # name tag + + +class TestCampaignEditRecipientsViewNoneMailingList(AuthenticatedTestCase): + def setUp(self): + super().setUp() + self.campaign = CampaignFactory(mailing_list=None) + self.url = reverse('campaigns:campaign_edit_recipients', kwargs={'pk': self.campaign.pk}) + self.response = self.client.get(self.url) + + def test_status_code(self): + self.assertEqual(200, self.response.status_code) |