Skip to content

Commit

Permalink
Add test_newlines_normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
utapyngo committed May 26, 2020
1 parent 39f762c commit 73fa362
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from constance import settings
from constance.admin import Config
from constance.admin import get_values


class TestAdmin(TestCase):
Expand Down Expand Up @@ -117,6 +118,26 @@ def test_submit(self):
response = self.options.changelist_view(request, {})
self.assertIsInstance(response, HttpResponseRedirect)

@mock.patch('constance.settings.CONFIG_FIELDSETS', {
'FieldSetOne': ('MULTILINE',)
})
@mock.patch('constance.settings.CONFIG', {
'MULTILINE': ('Hello\nWorld', 'multiline value'),
})
@mock.patch('constance.settings.IGNORE_ADMIN_VERSION_CHECK', True)
def test_newlines_normalization(self):
self.client.login(username='admin', password='nimda')
request = self.rf.post('/admin/constance/config/', data={
"MULTILINE": "Hello\r\nWorld",
"version": "123",
})
request.user = self.superuser
request._dont_enforce_csrf_checks = True
with mock.patch("django.contrib.messages.add_message"):
response = self.options.changelist_view(request, {})
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual(get_values()['MULTILINE'], 'Hello\nWorld')

@mock.patch('constance.settings.CONFIG', {
'DATETIME_VALUE': (datetime(2019, 8, 7, 18, 40, 0), 'some naive datetime'),
})
Expand Down

0 comments on commit 73fa362

Please sign in to comment.