-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove node-progressive (#2375)
* chore: remove node-progressive * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * chore: update ci options * chore: update ci settings location
- Loading branch information
Showing
13 changed files
with
70 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
FROM python:3.8 | ||
ENV PYTHONUNBUFFERED 1 | ||
FROM python:3.12-slim as base | ||
FROM base as builder | ||
|
||
# Allows docker to cache installed dependencies between builds | ||
RUN apt-get update && apt-get -y install libpq-dev gcc | ||
COPY ./requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
RUN pip3 install --no-cache-dir --target=packages -r requirements.txt | ||
|
||
FROM base as runtime | ||
COPY --from=builder packages /usr/lib/python3.12/site-packages | ||
ENV PYTHONPATH=/usr/lib/python3.12/site-packages | ||
|
||
# Security Context | ||
RUN useradd -m nonroot | ||
USER nonroot | ||
|
||
# Adds our application code to the image | ||
COPY . code | ||
WORKDIR code | ||
|
||
EXPOSE 8000 | ||
|
||
# Run the production server | ||
CMD newrelic-admin run-program gunicorn --bind 0.0.0.0:$PORT --access-logfile - {{cookiecutter.app_name}}.wsgi:application |
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,7 @@ | ||
import pytest | ||
|
||
# Ensures pytest waits for the database to load | ||
# https://pytest-django.readthedocs.io/en/latest/faq.html#how-can-i-give-database-access-to-all-my-tests-without-the-django-db-marker | ||
@pytest.fixture(autouse=True) | ||
def enable_db_access_for_all_tests(db): | ||
pass |
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
4 changes: 4 additions & 0 deletions
4
{{cookiecutter.github_repository_name}}/{{cookiecutter.app_name}}/pytest.ini
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,4 @@ | ||
[pytest] | ||
DJANGO_CONFIGURATION = Local | ||
DJANGO_SETTINGS_MODULE = {{cookiecutter.app_name}}.config | ||
python_files = tests.py test_*.py *_tests.py |
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
14 changes: 10 additions & 4 deletions
14
{{cookiecutter.github_repository_name}}/{{cookiecutter.app_name}}/users/permissions.py
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,14 +1,20 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class IsUserOrReadOnly(permissions.BasePermission): | ||
class IsUserOrCreatingAccountOrReadOnly(permissions.BasePermission): | ||
""" | ||
Object-level permission to only allow owners of an object to edit it. | ||
Object-level permission that allows users to create accounts or edit their | ||
own accounts. | ||
""" | ||
|
||
def has_object_permission(self, request, view, obj): | ||
user_is_making_new_account = view.action == 'create' | ||
if user_is_making_new_account: | ||
return True | ||
|
||
if request.method in permissions.SAFE_METHODS: | ||
is_read_only_action = request.method in permissions.SAFE_METHODS | ||
if is_read_only_action: | ||
return True | ||
|
||
return obj == request.user | ||
is_accessing_their_own_user_object = obj == request.user | ||
return is_accessing_their_own_user_object |
11 changes: 6 additions & 5 deletions
11
...ecutter.github_repository_name}}/{{cookiecutter.app_name}}/users/test/test_serializers.py
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,27 +1,28 @@ | ||
from django.test import TestCase | ||
from django.forms.models import model_to_dict | ||
from django.contrib.auth.hashers import check_password | ||
from nose.tools import eq_, ok_ | ||
import pytest | ||
from .factories import UserFactory | ||
from ..serializers import CreateUserSerializer | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestCreateUserSerializer(TestCase): | ||
|
||
def setUp(self): | ||
self.user_data = model_to_dict(UserFactory.build()) | ||
|
||
def test_serializer_with_empty_data(self): | ||
serializer = CreateUserSerializer(data={}) | ||
eq_(serializer.is_valid(), False) | ||
assert serializer.is_valid() is False | ||
|
||
def test_serializer_with_valid_data(self): | ||
serializer = CreateUserSerializer(data=self.user_data) | ||
ok_(serializer.is_valid()) | ||
assert serializer.is_valid() | ||
|
||
def test_serializer_hashes_password(self): | ||
serializer = CreateUserSerializer(data=self.user_data) | ||
ok_(serializer.is_valid()) | ||
assert serializer.is_valid() | ||
|
||
user = serializer.save() | ||
ok_(check_password(self.user_data.get('password'), user.password)) | ||
assert check_password(self.user_data.get('password'), user.password) |
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
22 changes: 9 additions & 13 deletions
22
{{cookiecutter.github_repository_name}}/{{cookiecutter.app_name}}/users/views.py
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,26 +1,22 @@ | ||
from rest_framework import viewsets, mixins | ||
from rest_framework.permissions import AllowAny | ||
from .models import User | ||
from .permissions import IsUserOrReadOnly | ||
from .permissions import IsUserOrCreatingAccountOrReadOnly | ||
from .serializers import CreateUserSerializer, UserSerializer | ||
|
||
|
||
class UserViewSet(mixins.RetrieveModelMixin, | ||
class UserViewSet(mixins.CreateModelMixin, | ||
mixins.RetrieveModelMixin, | ||
mixins.UpdateModelMixin, | ||
viewsets.GenericViewSet): | ||
""" | ||
Updates and retrieves user accounts | ||
""" | ||
queryset = User.objects.all() | ||
serializer_class = UserSerializer | ||
permission_classes = (IsUserOrReadOnly,) | ||
permission_classes = (IsUserOrCreatingAccountOrReadOnly,) | ||
|
||
|
||
class UserCreateViewSet(mixins.CreateModelMixin, | ||
viewsets.GenericViewSet): | ||
""" | ||
Creates user accounts | ||
""" | ||
queryset = User.objects.all() | ||
serializer_class = CreateUserSerializer | ||
permission_classes = (AllowAny,) | ||
def get_serializer_class(self): | ||
is_creating_a_new_user = self.action == 'create' | ||
if is_creating_a_new_user: | ||
return CreateUserSerializer | ||
return self.serializer_class |