Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #63 Create Practice Area Model #156

Merged
merged 17 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ app/htmlcov
[._]ss[a-gi-z]
[._]sw[a-p]

### python ###
venv

### 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 @@ -12,6 +12,7 @@
from .models import RecurringEvent
from .models import SponsorPartner
from .models import User
from .models import PracticeArea


class UserCreationForm(DefaultUserCreationForm):
Expand Down Expand Up @@ -123,6 +124,14 @@ class RecurringEventAdmin(admin.ModelAdmin):
)


@admin.register(PracticeArea)
class PracticeArea(admin.ModelAdmin):
fyliu marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -8,6 +8,26 @@
from core.models import RecurringEvent
from core.models import SponsorPartner
from core.models import User
from core.models import PracticeArea


class PracticeAreaSerializer(serializers.ModelSerializer):
"""Used to retrieve user 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):
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 @@ -6,6 +6,7 @@
from .views import LocationViewSet
from .views import ProjectViewSet
from .views import RecurringEventViewSet
from .views import PracticeAreaViewSet
from .views import SponsorPartnerViewSet
from .views import UserProfileAPIView
from .views import UserViewSet
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
18 changes: 17 additions & 1 deletion app/core/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
from rest_framework import viewsets
from rest_framework.generics import GenericAPIView
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly

from ..models import Faq
from ..models import FaqViewed
from ..models import Location
from ..models import Project
from ..models import RecurringEvent
from ..models import PracticeArea
from ..models import SponsorPartner
from .serializers import FaqSerializer
from .serializers import FaqViewedSerializer
from .serializers import LocationSerializer
from .serializers import ProjectSerializer
from .serializers import RecurringEventSerializer
from .serializers import PracticeAreaSerializer
from .serializers import SponsorPartnerSerializer
from .serializers import UserSerializer

Expand Down Expand Up @@ -128,6 +130,20 @@ class RecurringEventViewSet(viewsets.ModelViewSet):
serializer_class = RecurringEventSerializer


@extend_schema_view(
list=extend_schema(description="Return a list of all the sponsor partners"),
create=extend_schema(description="Create a new sponsor partner"),
retrieve=extend_schema(description="Return the details of a sponsor partner"),
destroy=extend_schema(description="Delete a sponsor partner"),
update=extend_schema(description="Update a sponsor partner"),
partial_update=extend_schema(description="Patch a sponsor partner"),
)
class PracticeAreaViewSet(viewsets.ModelViewSet):
fyliu marked this conversation as resolved.
Show resolved Hide resolved
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)
ethanstrominger marked this conversation as resolved.
Show resolved Hide resolved

def __str__(self):
return f"{self.name}"
6 changes: 6 additions & 0 deletions app/core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..models import Location
from ..models import Project
from ..models import RecurringEvent
from ..models import PracticeArea
from ..models import SponsorPartner


Expand Down Expand Up @@ -47,6 +48,11 @@ 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
13 changes: 12 additions & 1 deletion app/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

ME_URL = reverse("my_profile")
USERS_URL = reverse("user-list")
RECURRING_EVENTS_URL = reverse("recurring-event-list")
RECURRING_EVENTS_URL = reverse("practice-area-list")
PRACTICE_AREA_URL = reverse("practice-area--list")
fyliu marked this conversation as resolved.
Show resolved Hide resolved
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(FAQS_URL, payload)
fyliu marked this conversation as resolved.
Show resolved Hide resolved
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(recurring_event):
assert str(recurring_event) == "Test Practice Area"
fyliu marked this conversation as resolved.
Show resolved Hide resolved


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

Expand Down