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

#188 get category activity #196

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions profiles/tests/test_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from rest_framework.test import APITestCase, APIClient
from profiles.models import Activity

class TestActivityList(APITestCase):

def setUp(self) -> None:
self.transport_activity = Activity.objects.create(name="transport")
self.sale_activity = Activity.objects.create(name="sale")
self.production_activity = Activity.objects.create(name="production")
self.education_activity = Activity.objects.create(name="education")

def tearDown(self) -> None:
objects_to_delete = Activity.objects.all()
objects_to_delete.delete()

def test_get_all_activities(self):
response = self.client.get("/api/activity-list/")
self.assertEqual(200, response.status_code)
18 changes: 18 additions & 0 deletions profiles/tests/test_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from rest_framework.test import APITestCase, APIClient
from profiles.models import Category

class TestCategoryList(APITestCase):

def setUp(self) -> None:
self.cheese_category = Category.objects.create(name='cheese')
self.honey_category = Category.objects.create(name="honey")
self.chocolate_category = Category.objects.create(name='chocolate')
self.bacery_category = Category.objects.create(name="bacery")

def tearDown(self) -> None:
objects_to_delete = Category.objects.all()
objects_to_delete.delete()

def test_get_all_activities(self):
response = self.client.get("/api/category-list/")
self.assertEqual(200, response.status_code)
4 changes: 3 additions & 1 deletion profiles/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path
from .views import SavedCompaniesListCreate, SavedCompaniesDestroy
from .views import ProfileList, ProfileDetail, ViewedCompanyList
from .views import ProfileList, ProfileDetail, ViewedCompanyList, CategoryList, ActivityList

app_name = "profiles"

Expand All @@ -10,4 +10,6 @@
path('saved-list/', SavedCompaniesListCreate.as_view(), name='saved_companies_list_create'),
path('saved-list/<pk>/', SavedCompaniesDestroy.as_view(), name='saved_companies_destroy'),
path('viewed-list/', ViewedCompanyList.as_view(), name='viewed_company_list'),
path('category-list/', CategoryList.as_view(), name='category_list'),
path('activity-list/', ActivityList.as_view(), name='activity_list'),
]
17 changes: 15 additions & 2 deletions profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from rest_framework.response import Response
from rest_framework import status
from rest_framework.exceptions import ValidationError

from forum.pagination import ForumPagination
from .models import SavedCompany, Profile, ViewedCompany
from .models import SavedCompany, Profile, ViewedCompany, Category, Activity
from .serializers import (SavedCompanySerializer, ProfileSerializer, ViewedCompanySerializer,
ProfileSensitiveDataROSerializer, ProfileDetailSerializer)
ProfileSensitiveDataROSerializer, ProfileDetailSerializer, CategorySerializer, ActivitySerializer)
from .permissions import UserIsProfileOwnerOrReadOnly


Expand Down Expand Up @@ -129,3 +130,15 @@ class ViewedCompanyList(ListCreateAPIView):
def get_queryset(self):
user_id = self.request.user.id
return ViewedCompany.objects.filter(user=user_id).order_by("company_id")


class CategoryList(ListAPIView):
model = Category
serializer_class = CategorySerializer
queryset = Category.objects.all()


class ActivityList(ListAPIView):
model = Activity
serializer_class = ActivitySerializer
queryset = Activity.objects.all()
Loading