-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rest_framework import serializers | ||
from taxonomy.models import Skill | ||
|
||
|
||
class SkillSerializer(serializers.ModelSerializer): | ||
""" Skill Searlizer """ | ||
|
||
class Meta: | ||
model = Skill | ||
fields = ('name', 'description') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.urls import path | ||
from taxonomy.api.v1.views import SkillsView | ||
|
||
urlpatterns = [ | ||
path('api/v1/skills/', SkillsView.as_view(), name='skill_list') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from rest_framework.generics import ListAPIView | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework import filters | ||
from taxonomy.models import Skill, CourseSkills | ||
from taxonomy.api.v1.serializers import SkillSerializer | ||
|
||
|
||
class SkillsView(ListAPIView): | ||
""" List view for Skills """ | ||
filter_backends = [filters.SearchFilter] | ||
search_fields = ['^name'] | ||
permission_classes = [IsAuthenticated] | ||
serializer_class = SkillSerializer | ||
|
||
def get_queryset(self): | ||
blacklisted_skill_ids = list(CourseSkills.objcts.filter(is_blacklised=True).values_list('skill__id', flat=True)) | ||
return Skill.objects.exclude(id__in=blacklisted_skill_ids) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from pytest import mark | ||
from django.urls import reverse | ||
|
||
from rest_framework.test import APITestCase | ||
from test_utils import factories | ||
|
||
|
||
TEST_USERNAME = 'taxonomy_user' | ||
TEST_EMAIL = '[email protected]' | ||
TEST_PASSWORD = 'password' | ||
|
||
|
||
@mark.django_db | ||
class TestSkillsView(APITestCase): | ||
def setUp(self): | ||
""" | ||
Perform operations common to all tests. | ||
""" | ||
super().setUp() | ||
self.user = self.create_user(username=TEST_USERNAME, email=TEST_EMAIL, password=TEST_PASSWORD) | ||
|
||
self.url = reverse('skill_list') | ||
|
||
self.skill_names = [ | ||
('C++', False), ('CLI', False), ('Data Strcutures', False), ('Biochemistry', False), | ||
('Animations', False), ('Algorithms', False), ('VB', True), ('Oracle', True) | ||
] | ||
for skill_name, is_blacklisted in self.skill_names: | ||
skill = factories.SkillFactory(name=skill_name) | ||
factories.CourseSkillsFactory(skill=skill, is_blacklisted=is_blacklisted) | ||
|
||
def create_user(self, username=TEST_USERNAME, password=TEST_PASSWORD, **kwargs): | ||
""" | ||
Create a test user and set its password. | ||
""" | ||
user = factories.UserFactory(username=username, **kwargs) | ||
user.set_password(password) # pylint: disable=no-member | ||
user.save() # pylint: disable=no-member | ||
return user | ||
|
||
def test_search(self): | ||
self.client.login(username=TEST_USERNAME, password=TEST_PASSWORD) | ||
response = self.client.get(path=self.url) | ||
assert response.status_code == 200 |