Skip to content

Commit

Permalink
Issue #63 Create Practice Area Model (#156)
Browse files Browse the repository at this point in the history
* Issue 63 Create Practice Area Model
  • Loading branch information
ethanstrominger authored May 31, 2023
1 parent 5ca01a5 commit faa10be
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Generate the entire file as reference with this form:
# https://www.toptal.com/developers/gitignore?templates=python,django,dotenv,vim,visualstudiocode

temp

### django ###
*.sqlite3
app/.coverage
Expand All @@ -18,8 +20,13 @@ app/htmlcov
[._]ss[a-gi-z]
[._]sw[a-p]

### python ###
venv
__pycache__

### VisualStudioCode ###
.vscode/*
.idea
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
Expand Down
9 changes: 9 additions & 0 deletions app/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .models import Faq
from .models import FaqViewed
from .models import Location
from .models import PracticeArea
from .models import Project
from .models import RecurringEvent
from .models import SponsorPartner
Expand Down Expand Up @@ -123,6 +124,14 @@ class RecurringEventAdmin(admin.ModelAdmin):
)


@admin.register(PracticeArea)
class PracticeAreaAdmin(admin.ModelAdmin):
list_display = (
"name",
"description",
)


@admin.register(SponsorPartner)
class SponsorPartnerAdmin(admin.ModelAdmin):
list_display = (
Expand Down
20 changes: 20 additions & 0 deletions app/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@
from core.models import Faq
from core.models import FaqViewed
from core.models import Location
from core.models import PracticeArea
from core.models import Project
from core.models import RecurringEvent
from core.models import SponsorPartner
from core.models import User


class PracticeAreaSerializer(serializers.ModelSerializer):
"""Used to retrieve practice area info"""

class Meta:
model = PracticeArea
fields = (
"uuid",
"created_at",
"updated_at",
"name",
"description",
)
read_only_fields = (
"uuid",
"created_at",
"updated_at",
)


class UserSerializer(serializers.ModelSerializer):
"""Used to retrieve user info"""

Expand Down
2 changes: 2 additions & 0 deletions app/core/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .views import FaqViewedViewSet
from .views import FaqViewSet
from .views import LocationViewSet
from .views import PracticeAreaViewSet
from .views import ProjectViewSet
from .views import RecurringEventViewSet
from .views import SponsorPartnerViewSet
Expand All @@ -14,6 +15,7 @@
router.register(r"users", UserViewSet, basename="user")
router.register(r"projects", ProjectViewSet, basename="project")
router.register(r"recurring-events", RecurringEventViewSet, basename="recurring-event")
router.register(r"practice-areas", PracticeAreaViewSet, basename="practice-area")
router.register(r"sponsor-partners", SponsorPartnerViewSet, basename="sponsor-partner")
router.register(r"faqs", FaqViewSet, basename="faq")
router.register(r"faqs-viewed", FaqViewedViewSet, basename="faq-viewed")
Expand Down
19 changes: 19 additions & 0 deletions app/core/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
from rest_framework.generics import GenericAPIView
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import IsAuthenticatedOrReadOnly

from ..models import Faq
from ..models import FaqViewed
from ..models import Location
from ..models import PracticeArea
from ..models import Project
from ..models import RecurringEvent
from ..models import SponsorPartner
from .serializers import FaqSerializer
from .serializers import FaqViewedSerializer
from .serializers import LocationSerializer
from .serializers import PracticeAreaSerializer
from .serializers import ProjectSerializer
from .serializers import RecurringEventSerializer
from .serializers import SponsorPartnerSerializer
Expand Down Expand Up @@ -128,6 +131,22 @@ class RecurringEventViewSet(viewsets.ModelViewSet):
serializer_class = RecurringEventSerializer


@extend_schema_view(
list=extend_schema(description="Return a list of all the practice areas"),
create=extend_schema(description="Create a new sponsor practice area"),
retrieve=extend_schema(description="Return the details of a practice area"),
destroy=extend_schema(description="Delete a practice area"),
update=extend_schema(description="Update a practice area"),
partial_update=extend_schema(
description="Patch (partially update) a practice area"
),
)
class PracticeAreaViewSet(viewsets.ModelViewSet):
permission_classes = [IsAuthenticatedOrReadOnly]
queryset = PracticeArea.objects.all()
serializer_class = PracticeAreaSerializer


@extend_schema_view(
list=extend_schema(description="Return a list of all the sponsor partners"),
create=extend_schema(description="Create a new sponsor partner"),
Expand Down
27 changes: 27 additions & 0 deletions app/core/migrations/0010_practicearea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.0.10 on 2023-05-03 18:49

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
('core', '0009_location'),
]

operations = [
migrations.CreateModel(
name='PracticeArea',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.CharField(blank=True, max_length=255)),
],
options={
'abstract': False,
},
),
]
12 changes: 12 additions & 0 deletions app/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,15 @@ class Location(AbstractBaseModel):

def __str__(self):
return f"{self.name}"


class PracticeArea(AbstractBaseModel):
"""
Practice Area
"""

name = models.CharField(max_length=255, unique=True)
description = models.CharField(max_length=255, blank=True)

def __str__(self):
return f"{self.name}"
8 changes: 8 additions & 0 deletions app/core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ..models import Faq
from ..models import FaqViewed
from ..models import Location
from ..models import PracticeArea
from ..models import Project
from ..models import RecurringEvent
from ..models import SponsorPartner
Expand Down Expand Up @@ -47,6 +48,13 @@ def recurring_event(project):
return RecurringEvent.objects.create(name="Test Recurring Event", project=project)


@pytest.fixture
def practice_area():
return PracticeArea.objects.create(
name="Test Practice Area", description="Test Description"
)


@pytest.fixture
def client():
return APIClient()
Expand Down
11 changes: 11 additions & 0 deletions app/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ME_URL = reverse("my_profile")
USERS_URL = reverse("user-list")
RECURRING_EVENTS_URL = reverse("recurring-event-list")
PRACTICE_AREA_URL = reverse("practice-area-list")
FAQS_URL = reverse("faq-list")
FAQS_VIEWED_URL = reverse("faq-viewed-list")
SPONSOR_PARTNERS_URL = reverse("sponsor-partner-list")
Expand Down Expand Up @@ -176,6 +177,16 @@ def test_create_sponsor_partner(auth_client):
assert res.status_code == status.HTTP_201_CREATED


def test_create_practice_area(auth_client):
payload = {
"name": "Test API for creating practice area",
"description": "See name. Description is optional.",
}
res = auth_client.post(PRACTICE_AREA_URL, payload)
assert res.status_code == status.HTTP_201_CREATED
assert res.data["name"] == payload["name"]


def test_create_faq(auth_client):
payload = {
"question": "How do I work on an issue",
Expand Down
4 changes: 4 additions & 0 deletions app/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def test_recurring_event(recurring_event):
assert str(recurring_event) == "Test Recurring Event"


def test_practice_area(practice_area):
assert str(practice_area) == "Test Practice Area"


def test_sponsor_partner(sponsor_partner):
assert str(sponsor_partner) == "Test Sponsor Partner"

Expand Down

0 comments on commit faa10be

Please sign in to comment.