-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from SkyCascade/fix/pylint
Code format and best practices
- Loading branch information
Showing
78 changed files
with
2,420 additions
and
2,015 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,38 +5,37 @@ | |
|
||
User = get_user_model() | ||
|
||
|
||
class AdminRequiredDecoratorTests(TestCase): | ||
def setUp(self): | ||
self.superuser = User.objects.create_superuser( | ||
username='admin', email='[email protected]', password='password' | ||
username="admin", email="[email protected]", password="password" | ||
) | ||
self.user = User.objects.create_user( | ||
username='user', email='[email protected]', password='password' | ||
username="user", email="[email protected]", password="password" | ||
) | ||
self.factory = RequestFactory() | ||
|
||
def admin_view(self, request): | ||
return HttpResponse() | ||
|
||
def test_admin_required_decorator(self): | ||
# Apply the admin_required decorator to the view function | ||
decorated_view = admin_required(self.admin_view) | ||
|
||
request = self.factory.get("/") | ||
request.user = self.user | ||
response = decorated_view(request) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
|
||
def test_admin_required_decorator_with_redirect(self): | ||
# Apply the admin_required decorator to the view function | ||
decorated_view = admin_required(function=self.admin_view,redirect_to="/login/") | ||
decorated_view = admin_required(function=self.admin_view, redirect_to="/login/") | ||
|
||
request = self.factory.get("/") | ||
request.user = self.user | ||
response = decorated_view(request) | ||
|
||
# Assert redirection to login page | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, '/login/') | ||
|
||
self.assertEqual(response.url, "/login/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,51 +5,51 @@ | |
|
||
User = get_user_model() | ||
|
||
|
||
class AdminRequiredDecoratorTests(TestCase): | ||
def setUp(self): | ||
self.superuser = User.objects.create_superuser( | ||
username='admin', email='[email protected]', password='password' | ||
username="admin", email="[email protected]", password="password" | ||
) | ||
self.user = User.objects.create_user( | ||
username='user', email='[email protected]', password='password' | ||
username="user", email="[email protected]", password="password" | ||
) | ||
self.factory = RequestFactory() | ||
|
||
def admin_view(self, request): | ||
return HttpResponse("Admin View Content") | ||
|
||
def test_admin_required_decorator_redirects(self): | ||
decorated_view = admin_required(self.admin_view) | ||
|
||
request = self.factory.get("/restricted-view") | ||
request.user = self.user | ||
response = decorated_view(request) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, "/") | ||
|
||
|
||
def test_admin_required_decorator_redirects_to_correct_path(self): | ||
decorated_view = admin_required(function=self.admin_view,redirect_to="/login/") | ||
decorated_view = admin_required(function=self.admin_view, redirect_to="/login/") | ||
|
||
request = self.factory.get("restricted-view") | ||
request.user = self.user | ||
response = decorated_view(request) | ||
|
||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, '/login/') | ||
self.assertEqual(response.url, "/login/") | ||
|
||
def test_admin_required_decorator_does_not_redirect_superuser(self): | ||
decorated_view = admin_required(self.admin_view) | ||
|
||
request = self.factory.get("/restricted-view") | ||
request.user = self.superuser | ||
response = decorated_view(request) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.content, b"Admin View Content") | ||
|
||
def test_admin_redirect_decorator_return_correct_response(self): | ||
decorated_view = admin_required(self.admin_view) | ||
|
||
request = self.factory.get("/restricted-view") | ||
request.user = self.superuser | ||
response = decorated_view(request) | ||
|
@@ -59,10 +59,13 @@ def test_admin_redirect_decorator_return_correct_response(self): | |
class LecturerRequiredDecoratorTests(TestCase): | ||
def setUp(self): | ||
self.lecturer = User.objects.create_user( | ||
username='lecturer', email='[email protected]', password='password', is_lecturer=True | ||
username="lecturer", | ||
email="[email protected]", | ||
password="password", | ||
is_lecturer=True, | ||
) | ||
self.user = User.objects.create_user( | ||
username='user', email='[email protected]', password='password' | ||
username="user", email="[email protected]", password="password" | ||
) | ||
self.factory = RequestFactory() | ||
|
||
|
@@ -81,15 +84,17 @@ def test_lecturer_required_decorator_redirects(self): | |
self.assertEqual(response.url, "/") | ||
|
||
def test_lecturer_required_decorator_redirects_to_correct_path(self): | ||
decorated_view = lecturer_required(function=self.lecturer_view, redirect_to="/login/") | ||
decorated_view = lecturer_required( | ||
function=self.lecturer_view, redirect_to="/login/" | ||
) | ||
|
||
request = self.factory.get("/restricted-view") | ||
request.user = self.user | ||
|
||
response = decorated_view(request) | ||
|
||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, '/login/') | ||
self.assertEqual(response.url, "/login/") | ||
|
||
def test_lecturer_required_decorator_does_not_redirect_lecturer(self): | ||
decorated_view = lecturer_required(self.lecturer_view) | ||
|
@@ -112,13 +117,17 @@ def test_lecturer_redirect_decorator_return_correct_response(self): | |
|
||
self.assertIsInstance(response, HttpResponse) | ||
|
||
|
||
class StudentRequiredDecoratorTests(TestCase): | ||
def setUp(self): | ||
self.student = User.objects.create_user( | ||
username='student', email='[email protected]', password='password', is_student=True | ||
username="student", | ||
email="[email protected]", | ||
password="password", | ||
is_student=True, | ||
) | ||
self.user = User.objects.create_user( | ||
username='user', email='[email protected]', password='password' | ||
username="user", email="[email protected]", password="password" | ||
) | ||
self.factory = RequestFactory() | ||
|
||
|
@@ -137,15 +146,17 @@ def test_student_required_decorator_redirects(self): | |
self.assertEqual(response.url, "/") | ||
|
||
def test_student_required_decorator_redirects_to_correct_path(self): | ||
decorated_view = student_required(function=self.student_view, redirect_to="/login/") | ||
decorated_view = student_required( | ||
function=self.student_view, redirect_to="/login/" | ||
) | ||
|
||
request = self.factory.get("/restricted-view") | ||
request.user = self.user | ||
|
||
response = decorated_view(request) | ||
|
||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, '/login/') | ||
self.assertEqual(response.url, "/login/") | ||
|
||
def test_student_required_decorator_does_not_redirect_student(self): | ||
decorated_view = student_required(self.student_view) | ||
|
@@ -166,4 +177,4 @@ def test_student_redirect_decorator_return_correct_response(self): | |
|
||
response = decorated_view(request) | ||
|
||
self.assertIsInstance(response, HttpResponse) | ||
self.assertIsInstance(response, HttpResponse) |
Oops, something went wrong.