From f5a8a9c2682b9d93000c8773c1b93ad2a11d9397 Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 17:33:37 -0400 Subject: [PATCH 1/9] Update: Set GitHub Actions to run on Python 3.10 only --- .github/workflows/pylint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 383e65c..5abdb30 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.10"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} From 499f4e33f279b86d40fcf13439b02f480b3e0460 Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 17:54:12 -0400 Subject: [PATCH 2/9] Exclude migrations folder from flake8 and isort --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 694928e..906065e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,7 @@ repos: entry: isort additional_dependencies: [isort] types: [python] + exclude: migrations - id: flake8 name: flake8 @@ -18,7 +19,7 @@ repos: entry: flake8 additional_dependencies: [flake8, Flake8-pyproject] types: [python] - exclude: setup.py + exclude: setup.py, migrations args: [--max-line-length=100] - id: pytest From dfd62ff23f04bcf66abbc09bcf5a8a49de80affc Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 17:57:33 -0400 Subject: [PATCH 3/9] Exclude migrations folder from flake8 and isort --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 906065e..13a82b4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: entry: isort additional_dependencies: [isort] types: [python] - exclude: migrations + exclude: 'migrations/.*|setup.py' - id: flake8 name: flake8 @@ -19,7 +19,7 @@ repos: entry: flake8 additional_dependencies: [flake8, Flake8-pyproject] types: [python] - exclude: setup.py, migrations + exclude: 'migrations/.*|setup.py' args: [--max-line-length=100] - id: pytest From 04ddb36f05f4a00f4a2e88045e6f70fdff86fb76 Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 17:57:42 -0400 Subject: [PATCH 4/9] Added gender and is_neutered fields to pet model --- .../0007_pet_gender_pet_is_neutered.py | 23 +++++++++++++++++++ pet/models.py | 11 +++++++++ 2 files changed, 34 insertions(+) create mode 100644 pet/migrations/0007_pet_gender_pet_is_neutered.py diff --git a/pet/migrations/0007_pet_gender_pet_is_neutered.py b/pet/migrations/0007_pet_gender_pet_is_neutered.py new file mode 100644 index 0000000..f8d4838 --- /dev/null +++ b/pet/migrations/0007_pet_gender_pet_is_neutered.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.2 on 2024-03-19 21:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pet', '0006_alter_pet_owner'), + ] + + operations = [ + migrations.AddField( + model_name='pet', + name='gender', + field=models.CharField(blank=True, choices=[('F', 'Female'), ('M', 'Male')], max_length=1, verbose_name='gender'), + ), + migrations.AddField( + model_name='pet', + name='is_neutered', + field=models.BooleanField(default=False, verbose_name='is_neutered'), + ), + ] diff --git a/pet/models.py b/pet/models.py index 8d69b8e..24b2f49 100644 --- a/pet/models.py +++ b/pet/models.py @@ -5,7 +5,17 @@ class Pet(models.Model): + GENDER_CHOICES = ( + ("F", _("Female")), + ("M", _("Male")), + ) name = models.CharField(max_length=40, blank=False, null=False, verbose_name=_("name")) + gender = models.CharField( + max_length=1, + choices=GENDER_CHOICES, + blank=True, + verbose_name=_("gender"), + ) owner = models.ForeignKey( "people.Person", on_delete=models.SET_NULL, @@ -23,6 +33,7 @@ class Pet(models.Model): blank=True, verbose_name=_("breed") ) + is_neutered = models.BooleanField(default=False, verbose_name=_("is_neutered")) @property def age(self): From 93493707d71661ba9643b69be4c19c91e4fa4553 Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 18:18:04 -0400 Subject: [PATCH 5/9] Added django.yml job in github actions --- .github/workflows/django.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/django.yml diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml new file mode 100644 index 0000000..9d41094 --- /dev/null +++ b/.github/workflows/django.yml @@ -0,0 +1,32 @@ +name: Django CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + max-parallel: 4 + matrix: + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python - + - name: Install Dependencies + run: | + poetry install + - name: Run Tests + run: | + poetry run python manage.py test From 45d1a6a0f4ce5ca04d54d91a929d30cbb4666789 Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 18:18:21 -0400 Subject: [PATCH 6/9] Updated dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b2002b0..4344ae5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# Dockerfile FROM python:3.10-slim ENV PYTHONUNBUFFERED 1 From 8b62ddfa36286c93c78269628b74d73397eb877d Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 18:19:08 -0400 Subject: [PATCH 7/9] Added rest_framework package --- albercan_backend/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/albercan_backend/settings.py b/albercan_backend/settings.py index 9c7601f..641cd10 100644 --- a/albercan_backend/settings.py +++ b/albercan_backend/settings.py @@ -39,7 +39,6 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", - "rest_framework", "people", "pet", "structure" From 63928aa103282cd0b6fa145f6d39aa01b59af778 Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 18:29:37 -0400 Subject: [PATCH 8/9] Added a simple test to test a job in GitHub actions --- pet/tests.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pet/tests.py b/pet/tests.py index e69de29..8fb019a 100644 --- a/pet/tests.py +++ b/pet/tests.py @@ -0,0 +1,9 @@ +from django.test import TestCase + +from pet.models import Pet + + +class TestPet(TestCase): + def test_create_pet_with_valid_instance(self): + pet = Pet.objects.create(name="Peter") + self.assertIsInstance(pet, Pet) From 884d4b265a02d95f27b8ac4bc15b753711cb6bdc Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Tue, 19 Mar 2024 18:30:01 -0400 Subject: [PATCH 9/9] Changed the required http method to main page view --- pet/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pet/views.py b/pet/views.py index 062df8e..2fdbe59 100644 --- a/pet/views.py +++ b/pet/views.py @@ -1,5 +1,7 @@ from django.shortcuts import render +from django.views.decorators.http import require_http_methods +@require_http_methods(["GET"]) def main_page(request): return render(request, 'pet/main_page.html')