Skip to content

Commit

Permalink
Merge pull request #196 from ita-social-projects/#188GetCategoryActivity
Browse files Browse the repository at this point in the history
#188 get category activity
  • Loading branch information
BelousSofiya authored Sep 12, 2023
2 parents a2efdce + c070489 commit 1b7e749
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
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()

0 comments on commit 1b7e749

Please sign in to comment.