Skip to content

Commit f0e3fc1

Browse files
committed
Flake, autoflake and various cleanups for tests file
1 parent 1586a65 commit f0e3fc1

13 files changed

+74
-104
lines changed

docs/conf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
master_doc = "index"
5151

5252
# General information about the project.
53-
project = u"django-dynamic-preferences"
54-
copyright = u"2014, Agate Blue"
53+
project = "django-dynamic-preferences"
54+
copyright = "2014, Agate Blue"
5555

5656
# The version info for the project you're documenting, acts as replacement for
5757
# |version| and |release|, also used in various other places throughout the
@@ -197,8 +197,8 @@
197197
(
198198
"index",
199199
"django-dynamic-preferences.tex",
200-
u"django-dynamic-preferences Documentation",
201-
u"Agate Blue",
200+
"django-dynamic-preferences Documentation",
201+
"Agate Blue",
202202
"manual",
203203
),
204204
]
@@ -232,8 +232,8 @@
232232
(
233233
"index",
234234
"django-dynamic-preferences",
235-
u"django-dynamic-preferences Documentation",
236-
[u"Agate Blue"],
235+
"django-dynamic-preferences Documentation",
236+
["Agate Blue"],
237237
1,
238238
)
239239
]
@@ -251,8 +251,8 @@
251251
(
252252
"index",
253253
"django-dynamic-preferences",
254-
u"django-dynamic-preferences Documentation",
255-
u"Agate Blue",
254+
"django-dynamic-preferences Documentation",
255+
"Agate Blue",
256256
"django-dynamic-preferences",
257257
"One line description of project.",
258258
"Miscellaneous",

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[wheel]
22
universal = 1
3+
4+
[flake8]
5+
max-line-length = 90

tests/test_app/dynamic_preferences_registry.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from datetime import timezone
1+
import datetime
2+
23
from decimal import Decimal
3-
from dynamic_preferences.types import *
4+
from dynamic_preferences import types
45
from dynamic_preferences.registries import global_preferences_registry
56
from dynamic_preferences.users.registries import user_preferences_registry
67
from dynamic_preferences.preferences import Section
@@ -10,7 +11,7 @@
1011

1112
# Tutorial preferences
1213
@global_preferences_registry.register
13-
class RegistrationAllowed(BooleanPreference):
14+
class RegistrationAllowed(types.BooleanPreference):
1415
"""
1516
Are new registrations allowed ?
1617
"""
@@ -21,7 +22,7 @@ class RegistrationAllowed(BooleanPreference):
2122

2223

2324
@global_preferences_registry.register
24-
class MaxUsers(IntPreference):
25+
class MaxUsers(types.IntPreference):
2526
"""
2627
Are new registrations allowed ?
2728
"""
@@ -39,26 +40,26 @@ def validate(self, value):
3940
return value
4041

4142

42-
class NoDefault(IntPreference):
43+
class NoDefault(types.IntPreference):
4344
section = "user"
4445
name = "no_default"
4546

4647

47-
class NoModel(ModelChoicePreference):
48+
class NoModel(types.ModelChoicePreference):
4849
section = "blog"
4950
name = "no_model"
5051
default = None
5152

5253

5354
@global_preferences_registry.register
54-
class ItemsPerPage(IntPreference):
55+
class ItemsPerPage(types.IntPreference):
5556
section = "user"
5657
name = "items_per_page"
5758
default = 25
5859

5960

6061
@global_preferences_registry.register
61-
class FeaturedBlogEntry(ModelChoicePreference):
62+
class FeaturedBlogEntry(types.ModelChoicePreference):
6263
section = "blog"
6364
name = "featured_entry"
6465
queryset = BlogEntry.objects.all()
@@ -68,26 +69,26 @@ def get_default(self):
6869

6970

7071
@global_preferences_registry.register
71-
class BlogLogo(FilePreference):
72+
class BlogLogo(types.FilePreference):
7273
section = "blog"
7374
name = "logo"
7475

7576

7677
@global_preferences_registry.register
77-
class BlogLogo2(FilePreference):
78+
class BlogLogo2(types.FilePreference):
7879
section = "blog"
7980
name = "logo2"
8081

8182

8283
@global_preferences_registry.register
83-
class BlogCost(DecimalPreference):
84+
class BlogCost(types.DecimalPreference):
8485
section = "type"
8586
name = "cost"
8687
default = Decimal(0)
8788

8889

8990
@user_preferences_registry.register
90-
class FavoriteVegetable(ChoicePreference):
91+
class FavoriteVegetable(types.ChoicePreference):
9192
choices = (
9293
("C", "Carrot"),
9394
("T", "Tomato. I know, it's not a vegetable"),
@@ -99,7 +100,7 @@ class FavoriteVegetable(ChoicePreference):
99100

100101

101102
@user_preferences_registry.register
102-
class FavoriteVegetables(MultipleChoicePreference):
103+
class FavoriteVegetables(types.MultipleChoicePreference):
103104
choices = (
104105
("C", "Carrot"),
105106
("T", "Tomato. I know, it's not a vegetable"),
@@ -111,7 +112,7 @@ class FavoriteVegetables(MultipleChoicePreference):
111112

112113

113114
@user_preferences_registry.register
114-
class FavouriteColour(StringPreference):
115+
class FavouriteColour(types.StringPreference):
115116
"""
116117
What's your favourite colour ?
117118
"""
@@ -122,7 +123,7 @@ class FavouriteColour(StringPreference):
122123

123124

124125
@user_preferences_registry.register
125-
class IsZombie(BooleanPreference):
126+
class IsZombie(types.BooleanPreference):
126127
"""
127128
Are you a zombie ?
128129
"""
@@ -138,78 +139,78 @@ class BaseTestPref(object):
138139

139140
# No section pref
140141
@global_preferences_registry.register
141-
class NoSection(BooleanPreference):
142+
class NoSection(types.BooleanPreference):
142143
name = "no_section"
143144
default = False
144145

145146

146147
# User preferences
147148
@user_preferences_registry.register
148-
class TestUserPref1(BaseTestPref, StringPreference):
149+
class TestUserPref1(BaseTestPref, types.StringPreference):
149150
name = "TestUserPref1"
150151
default = "default value"
151152

152153

153154
@user_preferences_registry.register
154-
class TestUserPref2(BaseTestPref, StringPreference):
155+
class TestUserPref2(BaseTestPref, types.StringPreference):
155156
name = "TestUserPref2"
156157
default = "default value"
157158

158159

159160
@user_preferences_registry.register
160-
class UserBooleanPref(BaseTestPref, BooleanPreference):
161+
class UserBooleanPref(BaseTestPref, types.BooleanPreference):
161162
name = "SiteBooleanPref"
162163
default = False
163164

164165

165166
@user_preferences_registry.register
166-
class UserStringPref(BaseTestPref, StringPreference):
167+
class UserStringPref(BaseTestPref, types.StringPreference):
167168
name = "SUserStringPref"
168169
default = "Hello world!"
169170

170171

171172
# Global
172173
@global_preferences_registry.register
173-
class TestGlobal1(BaseTestPref, StringPreference):
174+
class TestGlobal1(BaseTestPref, types.StringPreference):
174175
name = "TestGlobal1"
175176
default = "default value"
176177

177178

178179
@global_preferences_registry.register
179-
class TestGlobal2(BaseTestPref, BooleanPreference):
180+
class TestGlobal2(BaseTestPref, types.BooleanPreference):
180181
name = "TestGlobal2"
181182
default = False
182183

183184

184185
@global_preferences_registry.register
185-
class TestGlobal3(BaseTestPref, BooleanPreference):
186+
class TestGlobal3(BaseTestPref, types.BooleanPreference):
186187
name = "TestGlobal3"
187188
default = False
188189

189190

190191
@global_preferences_registry.register
191-
class ExamDuration(DurationPreference):
192+
class ExamDuration(types.DurationPreference):
192193
section = "exam"
193194
name = "duration"
194-
default = timedelta(hours=3)
195+
default = datetime.timedelta(hours=3)
195196

196197

197198
@global_preferences_registry.register
198-
class RegistrationDate(DatePreference):
199+
class RegistrationDate(types.DatePreference):
199200
section = "company"
200201
name = "RegistrationDate"
201-
default = date(1998, 9, 4)
202+
default = datetime.date(1998, 9, 4)
202203

203204

204205
@global_preferences_registry.register
205-
class BirthDateTime(DateTimePreference):
206+
class BirthDateTime(types.DateTimePreference):
206207
section = Section("child", verbose_name="Child Section Verbose Name")
207208
name = "BirthDateTime"
208-
default = datetime(1992, 5, 4, 3, 4, 10, 150, tzinfo=timezone.utc)
209+
default = datetime.datetime(1992, 5, 4, 3, 4, 10, 150, tzinfo=datetime.timezone.utc)
209210

210211

211212
@global_preferences_registry.register
212-
class OpenningTime(TimePreference):
213+
class OpenningTime(types.TimePreference):
213214
section = "company"
214215
name = "OpenningTime"
215-
default = time(hour=8, minute=0)
216+
default = datetime.time(hour=8, minute=0)

tests/test_checkpreferences_command.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from io import StringIO
22

3-
from django.core.cache import caches
43
from django.core.management import call_command
5-
from django.test import TestCase
64

75

86
def call(*args, **kwargs):

tests/test_global_preferences.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
from __future__ import unicode_literals
2-
3-
import pytest
4-
5-
61
from datetime import timezone
72
from decimal import Decimal
83

94
from datetime import date, timedelta, datetime, time
105
from django.apps import apps
11-
from django.test import LiveServerTestCase, TestCase
12-
from django.test.utils import override_settings
136
from django.urls import reverse
147
from django.core.management import call_command
15-
from django.core.cache import caches
16-
from django.contrib.auth.models import User
178
from django.core.files.uploadedfile import SimpleUploadedFile
189
from django.utils.timezone import make_aware
1910

@@ -164,7 +155,7 @@ def test_preference_are_updated_on_form_submission(admin_client):
164155
"exam__duration": timedelta(hours=5),
165156
"company__OpenningTime": time(hour=8, minute=0),
166157
}
167-
response = admin_client.post(url, data)
158+
admin_client.post(url, data)
168159
for key, expected_value in data.items():
169160
try:
170161
section, name = key.split("__")
@@ -189,7 +180,9 @@ def test_preference_are_updated_on_form_submission_by_section(admin_client):
189180
"user__registration_allowed": True,
190181
"user__items_per_page": 12,
191182
},
183+
follow=True,
192184
)
185+
assert response.status_code == 200
193186
assert (
194187
GlobalPreferenceModel.objects.get(section="user", name="max_users").value == 95
195188
)
@@ -218,8 +211,9 @@ def test_file_preference(admin_client):
218211
logo = SimpleUploadedFile("logo.png", content, content_type="image/png")
219212
url = reverse("dynamic_preferences:global.section", kwargs={"section": "blog"})
220213
response = admin_client.post(
221-
url, {"blog__featured_entry": blog_entry.pk, "blog__logo": logo}
214+
url, {"blog__featured_entry": blog_entry.pk, "blog__logo": logo}, follow=True
222215
)
216+
assert response.status_code == 200
223217
assert (
224218
GlobalPreferenceModel.objects.get(section="blog", name="featured_entry").value
225219
== blog_entry

tests/test_manager.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
from __future__ import unicode_literals
2-
from django.test import TestCase
3-
from django.core.cache import caches
41
from django.urls import reverse
5-
from django.contrib.auth.models import User
62

73
from dynamic_preferences.registries import global_preferences_registry as registry
84
from dynamic_preferences.models import GlobalPreferenceModel
@@ -72,7 +68,9 @@ def test_invalidates_cache_when_saving_from_admin(admin_client):
7268
assert manager.cache.get(key) == "reset1"
7369
assert manager.all()["test__TestGlobal1"] == "reset1"
7470

75-
response = admin_client.post(url, {"raw_value": "reset2"})
71+
response = admin_client.post(url, {"raw_value": "reset2"}, follow=True)
72+
73+
assert response.status_code == 200
7674

7775
assert manager.cache.get(key) == "reset2"
7876
assert manager.all()["test__TestGlobal1"] == "reset2"

tests/test_preferences.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
from __future__ import unicode_literals
2-
from django.test import TestCase
3-
from django.test.utils import override_settings
4-
from django.contrib.auth.models import User
5-
from django.core.cache import caches
6-
71
import pytest
82

93
from dynamic_preferences.registries import (
@@ -75,11 +69,11 @@ def test_preferences_manager_set(db):
7569
def test_can_cache_single_preference(db, django_assert_num_queries):
7670

7771
manager = global_preferences_registry.manager()
78-
v = manager["no_section"]
72+
manager["no_section"]
7973
with django_assert_num_queries(0):
80-
v = manager["no_section"]
81-
v = manager["no_section"]
82-
v = manager["no_section"]
74+
manager["no_section"]
75+
manager["no_section"]
76+
manager["no_section"]
8377

8478

8579
def test_can_bypass_cache_in_get(db, settings, django_assert_num_queries):
@@ -108,7 +102,7 @@ def test_can_bypass_cache_in_get_all(db, settings):
108102

109103

110104
def test_can_cache_all_preferences(db, django_assert_num_queries):
111-
blog_entry = BlogEntry.objects.create(title="test", content="test")
105+
BlogEntry.objects.create(title="test", content="test")
112106
manager = global_preferences_registry.manager()
113107
manager.all()
114108
with django_assert_num_queries(3):
@@ -175,12 +169,12 @@ def test_can_get_to_string_notation(db):
175169

176170
def test_preference_requires_default_value():
177171
with pytest.raises(exceptions.MissingDefault):
178-
preference = prefs.NoDefault()
172+
prefs.NoDefault()
179173

180174

181175
def test_modelchoicepreference_requires_model_value():
182176
with pytest.raises(exceptions.MissingModel):
183-
preference = prefs.NoModel()
177+
prefs.NoModel()
184178

185179

186180
def test_get_field_uses_field_kwargs():

0 commit comments

Comments
 (0)