-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove bad static file reference
- Loading branch information
1 parent
4aa1c88
commit fb78314
Showing
8 changed files
with
33,786 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
from django.core.exceptions import PermissionDenied | ||
from model_bakery import baker | ||
|
||
from pepfar_mle.common.views import HomeView | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_approved_mixin_approved_user(rf, django_user_model): | ||
approved_user = baker.make(django_user_model, is_approved=True) | ||
url = "/" | ||
request = rf.get(url) | ||
request.user = approved_user | ||
view = HomeView() | ||
view.setup(request) | ||
view.dispatch(request) # no error raised | ||
|
||
|
||
def test_approved_mixin_non_approved_authenticated_user(rf, django_user_model): | ||
non_approved_user = baker.make(django_user_model, is_approved=False) | ||
url = "/" | ||
request = rf.get(url) | ||
request.user = non_approved_user | ||
view = HomeView() | ||
view.setup(request) | ||
with pytest.raises(PermissionDenied) as e: | ||
view.dispatch(request) # no error raised | ||
|
||
assert "PermissionDenied" in str(e) |
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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
from django.views.generic import TemplateView | ||
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin | ||
from django.views.generic import TemplateView, View | ||
|
||
|
||
class HomeView(LoginRequiredMixin, TemplateView): | ||
class ApprovedMixin(UserPassesTestMixin, View): | ||
permission_denied_message = "Your account is pending approval" | ||
|
||
def test_func(self): | ||
return self.request.user.is_authenticated and self.request.user.is_approved | ||
|
||
|
||
class HomeView(LoginRequiredMixin, ApprovedMixin, TemplateView): | ||
template_name = "pages/home.html" | ||
|
||
|
||
class AboutView(LoginRequiredMixin, TemplateView): | ||
class AboutView(LoginRequiredMixin, ApprovedMixin, TemplateView): | ||
template_name = "pages/about.html" |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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