From 5440c6fc844667e77c5661c772ab1953cb375df5 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 30 Dec 2019 20:34:28 +0100 Subject: [PATCH] Create Settings object for notification tests just when needed --- tests/plugins/notifications/test_views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/plugins/notifications/test_views.py b/tests/plugins/notifications/test_views.py index e3681c75..dacc6cfd 100644 --- a/tests/plugins/notifications/test_views.py +++ b/tests/plugins/notifications/test_views.py @@ -1,16 +1,12 @@ -import pdb - from django.shortcuts import resolve_url from django_nyt.models import Settings - -from tests.base import RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestBase +from tests.base import ArticleWebTestUtils, DjangoClientTestBase, RequireRootArticleMixin class NotificationSettingsTests(RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestBase): def setUp(self): super().setUp() - self.settings = Settings.objects.get_or_create(user=self.superuser1, is_default=True) def test_login_required(self): self.client.logout() @@ -23,6 +19,8 @@ class NotificationSettingsTests(RequireRootArticleMixin, ArticleWebTestUtils, Dj self.assertTemplateUsed(response, 'wiki/plugins/notifications/settings.html') def test_change_settings(self): + self.settings, __ = Settings.objects.get_or_create(user=self.superuser1, is_default=True) + url = resolve_url('wiki:notification_settings') response = self.client.get(url) @@ -47,4 +45,6 @@ class NotificationSettingsTests(RequireRootArticleMixin, ArticleWebTestUtils, Dj data['form-0-email'] = 2 # post the request without any change response = self.client.post(url, data) - self.root_article.refresh_from_db() + + # Ensure we didn't create redundant Settings objects + assert self.superuser1.nyt_settings.all().count() == 1 -- 2.45.2