-
Notifications
You must be signed in to change notification settings - Fork 448
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
feat: add feature to the List Users API to filter users by skill #1097
Open
battuAshita
wants to merge
18
commits into
anitab-org:develop
Choose a base branch
from
battuAshita:issue#759
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2876e7c
feat: add feature to the List Users API to filter users by skill
battuAshita fd71462
feat: add feature to the List Users API to filter users by skill
battuAshita d6df0d2
feat: add feature to the List Users API to filter users by skill
battuAshita f60c559
feat: add feature to the List Users API to filter users by skill
battuAshita e80cdbd
incorporated review comments
battuAshita 424daca
incorporated review comments
battuAshita 458bcc0
made changes
battuAshita 8308492
made changes
battuAshita e4fbd3f
incorporated changes
battuAshita c38f715
made necessary changes
battuAshita 3d4c9d7
removed fts functionality
battuAshita bee18f0
removed verify-user condition
battuAshita fe906b0
Merge branch 'develop' into issue#759
battuAshita 7d24370
Incorporated review comments
battuAshita 3333ec0
Incorporated review comments
battuAshita b416b38
Removed lint errors
battuAshita 34b440c
Removed lint errors
battuAshita 7f158f9
Removed error
battuAshita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -59,7 +59,16 @@ class UserModel(db.Model): | |
need_mentoring = db.Column(db.Boolean) | ||
available_to_mentor = db.Column(db.Boolean) | ||
|
||
def __init__(self, name, username, password, email, terms_and_conditions_checked): | ||
def __init__( | ||
self, | ||
name, | ||
username, | ||
password, | ||
email, | ||
terms_and_conditions_checked, | ||
need_mentoring=False, | ||
available_to_mentor=False, | ||
): | ||
"""Initialises userModel class with name, username, password, email, and terms_and_conditions_checked.""" | ||
# required fields | ||
|
||
|
@@ -78,8 +87,8 @@ def __init__(self, name, username, password, email, terms_and_conditions_checked | |
|
||
# optional fields | ||
|
||
self.need_mentoring = False | ||
self.available_to_mentor = False | ||
self.need_mentoring = need_mentoring | ||
self.available_to_mentor = available_to_mentor | ||
Comment on lines
+90
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow so this was just making these values set to false 😱 nice catch! |
||
|
||
def json(self): | ||
"""Returns Usermodel object in json format.""" | ||
|
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,74 @@ | ||
import unittest | ||
|
||
from flask import json | ||
from http import HTTPStatus | ||
from tests.base_test_case import BaseTestCase | ||
from app.database.models.user import UserModel | ||
from app.database.sqlalchemy_extension import db | ||
from tests.test_data import user1, user2, user3 | ||
from tests.test_utils import get_test_request_header | ||
|
||
|
||
class TestFilterUsersBySkill(BaseTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
# Insert data of the first entry | ||
self.first_user = UserModel(**user1) | ||
self.first_user.is_email_verified = True | ||
self.first_user.skills = "Problem Solving" | ||
|
||
db.session.add(self.first_user) | ||
db.session.commit() | ||
|
||
# Insert data of the second entry | ||
self.second_user = UserModel(**user2) | ||
self.second_user.is_email_verified = True | ||
self.second_user.skills = "Problem Solving" | ||
|
||
db.session.add(self.second_user) | ||
db.session.commit() | ||
|
||
# Insert data of the third entry | ||
self.third_user = UserModel(**user3) | ||
self.third_user.is_email_verified = True | ||
self.third_user.skills = "Critical thinking" | ||
|
||
db.session.add(self.third_user) | ||
db.session.commit() | ||
|
||
def test_filter_users_by_skill_problem_solving(self): | ||
|
||
auth_header = get_test_request_header(self.admin_user.id) | ||
expected_response = "Problem Solving" | ||
|
||
actual_response = self.client.get( | ||
"/users/verified?skills=Problem Solving", | ||
headers=auth_header, | ||
content_type="application/json", | ||
) | ||
|
||
self.assertEqual(HTTPStatus.OK, actual_response.status_code) | ||
|
||
for data in json.loads(actual_response.data): | ||
self.assertEqual(expected_response, data["skills"]) | ||
|
||
def test_filter_users_by_skill_critical(self): | ||
|
||
auth_header = get_test_request_header(self.admin_user.id) | ||
expected_response = "Critical thinking" | ||
|
||
actual_response = self.client.get( | ||
"/users/verified?skills=Critical thinking", | ||
headers=auth_header, | ||
content_type="application/json", | ||
) | ||
|
||
self.assertEqual(HTTPStatus.OK, actual_response.status_code) | ||
|
||
for data in json.loads(actual_response.data): | ||
self.assertEqual(expected_response, data["skills"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only work when the skill exactly matches. Enable FTS and use proter tokenizer (or the postgres equivalent).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make the necessary changes and get back :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @epicadk Please correct me if I'm wrong. Adding FTS would require changes to made in the underlying table right? We need to have a ts_vector column which helps us compare with the given query.
Also, I have a row with skill as "critical thinking"
select * from users where to_tsvector('english', skills) @@ to_tsquery('Criti');
This query did not give me the result whereas
select * from users where skills ilike '%criti%';
This query gave me the result
I feel using something like "ILIKE" would be sufficient here.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like with a wildcard at the beginning will not use indexes.
Also porter will match Frustrate to Frustration which would be nice to have since skills isn't an enum.
A good practice is to use Explain Analyze on SQL queries. ( Only for your understanding not in production of course.)