Skip to content

Commit

Permalink
Merge pull request #75 from cclauss/more-ruff
Browse files Browse the repository at this point in the history
Apply some ruff C4,UP,W fixes
  • Loading branch information
nicholasserra authored Sep 26, 2023
2 parents 2e4fe4d + 4936f03 commit 543f300
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}
},
'SECRET_KEY': '7v%d@z##e=8z5#oc=cc-o%!cka5ibyy7#9r!#2fyiwn7ki020y',
'TOS_CACHE_NAME': 'tos'
'TOS_CACHE_NAME': 'tos'
}

django_settings['MIDDLEWARE'] = [
Expand Down
2 changes: 1 addition & 1 deletion tos/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def process_request(self, request):
request.session['tos_user'] = user_id
request.session['tos_backend'] = request.session['_auth_user_backend']

response = HttpResponseRedirect('{0}?{1}={2}'.format(
response = HttpResponseRedirect('{}?{}={}'.format(
tos_check_url,
REDIRECT_FIELD_NAME,
request.path_info,
Expand Down
2 changes: 0 additions & 2 deletions tos/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-04-19 14:09
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
Expand Down
2 changes: 1 addition & 1 deletion tos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def save(self, *args, **kwargs):
'One of the terms of service must be marked active'
)

super(TermsOfService, self).save(*args, **kwargs)
super().save(*args, **kwargs)


class UserAgreement(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions tos/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def setUp(self):
user=self.user1
)

self.redirect_page = '{0}?{1}={2}'.format(
self.redirect_page = '{}?{}={}'.format(
reverse('tos_check_tos'),
REDIRECT_FIELD_NAME,
reverse('index'),
Expand Down Expand Up @@ -141,7 +141,7 @@ def setUp(self):
# Test the backward compatibility of the middleware
@skipIf(DJANGO_VERSION >= (4,0), 'Django < 4.0 only')
def test_ajax_request_pre_40(self):
class Request(object):
class Request:
method = 'GET'
META = {
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'
Expand All @@ -157,7 +157,7 @@ def is_ajax(self):
self.assertIsNone(response)

def test_ajax_request(self):
class Request(object):
class Request:
method = 'GET'
META = {
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'
Expand Down
4 changes: 2 additions & 2 deletions tos/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setUp(self):

def test_terms_of_service(self):

self.assertEquals(TermsOfService.objects.count(), 2)
self.assertEqual(TermsOfService.objects.count(), 2)

# order is by -created
latest = TermsOfService.objects.latest()
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_terms_of_service_manager(self):
active=True
)

self.assertEquals(TermsOfService.objects.get_current_tos(), tos1)
self.assertEqual(TermsOfService.objects.get_current_tos(), tos1)

def test_terms_of_service_manager_raises_error(self):

Expand Down
18 changes: 9 additions & 9 deletions tos/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_login(self):

self.assertTrue(has_user_agreed_latest_tos(self.user1))
login = self.client.login(username='user1', password='user1pass')
self.failUnless(login, 'Could not log in')
self.assertTrue(login, 'Could not log in')
self.assertTrue(has_user_agreed_latest_tos(self.user1))

def test_user_agrees_multiple_times(self):
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_need_agreement(self):

self.assertFalse(has_user_agreed_latest_tos(self.user2))

response = self.client.post(self.login_url, dict(username='user2', password='user2pass'))
response = self.client.post(self.login_url, {'username': 'user2', 'password': 'user2pass'})
self.assertContains(response, "first edition of the terms of service")

self.assertFalse(has_user_agreed_latest_tos(self.user2))
Expand All @@ -79,15 +79,15 @@ def test_do_not_need_agreement(self):

self.assertTrue(has_user_agreed_latest_tos(self.user1))

response = self.client.post(self.login_url, dict(username='user1',
password='user1pass'))
response = self.client.post(self.login_url, {'username': 'user1',
'password': 'user1pass'})
self.assertEqual(302, response.status_code)

def test_redirect_security(self):
""" redirect to outside url not allowed, should redirect to login url"""

response = self.client.post(self.login_url, dict(username='user1',
password='user1pass', next='http://example.com'))
response = self.client.post(self.login_url, {'username': 'user1',
'password': 'user1pass', 'next': 'http://example.com'})
self.assertEqual(302, response.status_code)
self.assertIn(settings.LOGIN_REDIRECT_URL, response.url)

Expand All @@ -106,7 +106,7 @@ def test_reject_agreement(self):

self.assertFalse(has_user_agreed_latest_tos(self.user2))

response = self.client.post(self.login_url, dict(username='user2', password='user2pass'))
response = self.client.post(self.login_url, {'username': 'user2', 'password': 'user2pass'})
self.assertContains(response, "first edition of the terms of service")
url = reverse('tos_check_tos')
response = self.client.post(url, {'accept': 'reject'})
Expand All @@ -117,7 +117,7 @@ def test_accept_agreement(self):

self.assertFalse(has_user_agreed_latest_tos(self.user2))

response = self.client.post(self.login_url, dict(username='user2', password='user2pass'))
response = self.client.post(self.login_url, {'username': 'user2', 'password': 'user2pass'})
self.assertContains(response, "first edition of the terms of service")
self.assertFalse(has_user_agreed_latest_tos(self.user2))
url = reverse('tos_check_tos')
Expand All @@ -135,7 +135,7 @@ def test_bump_new_agreement(self):
self.assertFalse(has_user_agreed_latest_tos(self.user1))

# user1 agrees again
response = self.client.post(self.login_url, dict(username='user1', password='user1pass'))
response = self.client.post(self.login_url, {'username': 'user1', 'password': 'user1pass'})
self.assertContains(response, "second edition of the terms of service")
self.assertFalse(has_user_agreed_latest_tos(self.user2))
url = reverse('tos_check_tos')
Expand Down
2 changes: 1 addition & 1 deletion tos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TosView(TemplateView):
template_name = "tos/tos.html"

def get_context_data(self, **kwargs):
context = super(TosView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['tos'] = TermsOfService.objects.get_current_tos()
return context

Expand Down

0 comments on commit 543f300

Please sign in to comment.