Skip to content
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:

- name: Set up Python dependencies
run: |
poetry env use python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

poetry install

- uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion src/users/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def user_list(request):
role = request.GET.get('role')
if not role or role != "Reviewer":
return JsonResponse({'detail': 'role is not given or invalid.'}, status=400)
qs = User.objects.filter(is_active=True,verified=True, groups__name= "Reviewer")
qs = User.objects.get_valid_users_by_role(role).order_by('speaker_name')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflict with #1256?

users = []
for user in qs:
users.append({
Expand Down
8 changes: 8 additions & 0 deletions src/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def get_valid_speakers(self):
users = users.exclude(speaker_name='').exclude(bio='')
return users

def get_valid_users_by_role(self, role):
"""Get active and verified users with specific role"""
return self.filter(
is_active=True,
verified=True,
groups__name=role
)


class UserManager(BaseUserManager.from_queryset(UserQueryset)):
"""Custom manager for User.
Expand Down
39 changes: 25 additions & 14 deletions src/users/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,46 @@
from django.urls import reverse


@pytest.fixture
def auth_user(django_user_model):
return django_user_model.objects.create(
email="[email protected]",
speaker_name="Auth User",
verified=True,
is_active=True,
)


@pytest.mark.django_db
def test_user_list_with_role_filter_exact_match(api_client, django_user_model):
def test_user_list_with_role_filter_exact_match(api_client, django_user_model, auth_user):
group = Group.objects.create(name='Reviewer')
user = django_user_model.objects.create(
reviewer = django_user_model.objects.create(
email="[email protected]",
speaker_name="Reviewer Name",
bio="Some bio",
verified=True,
is_active=True,
)
user.groups.add(group)
reviewer.groups.add(group)

api_client.force_authenticate(user=user)
api_client.force_authenticate(user=auth_user)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1247 (comment)
why does it need force_authenticate()?

Suggested change
api_client.force_authenticate(user=auth_user)


django_user_model.objects.create(
email="[email protected]",
speaker_name="Other User",
bio="Other bio",
verified=True,
is_active=True,
)

url = reverse('user_list')
response = api_client.get(url, {'role': 'Reviewer'})
assert response.status_code == 200

data = response.json()
assert data == [
{
'full_name': user.get_full_name(),
'bio': user.bio,
'photo_url': None,
'facebook_profile_url': user.facebook_profile_url,
'twitter_profile_url': user.twitter_profile_url,
'github_profile_url': user.github_profile_url,
}
]
assert len(data) == 1
assert data[0]['full_name'] == reviewer.get_full_name()
assert data[0]['bio'] == reviewer.bio


@pytest.mark.django_db
Expand Down