Skip to content

Commit

Permalink
fix: code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shadinaif committed Apr 19, 2024
1 parent fccfea5 commit 8adc75b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 12 deletions.
Empty file added tests/__init__.py
Empty file.
Empty file.
4 changes: 1 addition & 3 deletions tests/test_dashboard/test_details/test_details_learners.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Tests for learner details collectors"""
import pytest
from django.db.models import Sum

from futurex_openedx_extensions.dashboard.details.learners import get_learners_queryset
from tests.base_test_data import expected_statistics


@pytest.mark.django_db
Expand All @@ -16,6 +14,6 @@
([7], 'user6', 0),
([4], None, 0),
])
def test_get_learners_queryset(base_data, tenant_ids, search_text, expected_count):
def test_get_learners_queryset(base_data, tenant_ids, search_text, expected_count): # pylint: disable=unused-argument
"""Verify that get_learners_queryset returns the correct QuerySet."""
assert get_learners_queryset(tenant_ids, search_text).count() == expected_count
Empty file.
4 changes: 2 additions & 2 deletions tests/test_dashboard/test_statistics/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
([2, 7], {'ORG3': 7, 'ORG8': 2}),
([7, 8], {'ORG3': 7, 'ORG8': 2}),
])
def test_get_certificates_count(base_data, tenant_ids, expected_result):
def test_get_certificates_count(base_data, tenant_ids, expected_result): # pylint: disable=unused-argument
"""Verify get_certificates_count function."""
result = certificates.get_certificates_count(tenant_ids)
assert result == expected_result, \
f'Wrong certificates result for tenant(s) {tenant_ids}. expected: {expected_result}, got: {result}'


@pytest.mark.django_db
def test_get_certificates_count_not_downloadable(base_data):
def test_get_certificates_count_not_downloadable(base_data): # pylint: disable=unused-argument
"""Verify get_certificates_count function with empty tenant_ids."""
result = certificates.get_certificates_count([1])
assert result == {'ORG1': 4, 'ORG2': 10}, f'Wrong certificates result. expected: {result}'
Expand Down
14 changes: 10 additions & 4 deletions tests/test_dashboard/test_statistics/test_learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
(7, {'ORG3': 13}),
(8, {'ORG8': 6}),
])
def test_get_learners_count_having_enrollment_per_org(base_data, tenant_id, expected_result):
def test_get_learners_count_having_enrollment_per_org(
base_data, tenant_id, expected_result
): # pylint: disable=unused-argument
"""Test get_learners_count_having_enrollment_per_org function."""
result = learners.get_learners_count_having_enrollment_per_org(tenant_id)
assert result.count() == len(expected_result), 'Wrong number of organizations returned'
Expand All @@ -37,7 +39,9 @@ def test_get_learners_count_having_enrollment_per_org(base_data, tenant_id, expe
(7, 13),
(8, 6),
])
def test_get_learners_count_having_enrollment_for_tenant(base_data, tenant_id, expected_result):
def test_get_learners_count_having_enrollment_for_tenant(
base_data, tenant_id, expected_result
): # pylint: disable=unused-argument
"""Test get_learners_count_having_enrollment_for_tenant function."""
result = learners.get_learners_count_having_enrollment_for_tenant(tenant_id)
assert result == expected_result, f'Wrong learners count: {result} for tenant: {tenant_id}'
Expand All @@ -54,14 +58,16 @@ def test_get_learners_count_having_enrollment_for_tenant(base_data, tenant_id, e
(7, 4),
(8, 3),
])
def test_get_learners_count_having_no_enrollment(base_data, tenant_id, expected_result):
def test_get_learners_count_having_no_enrollment(
base_data, tenant_id, expected_result
): # pylint: disable=unused-argument
"""Test get_learners_count_having_no_enrollment function."""
result = learners.get_learners_count_having_no_enrollment(tenant_id)
assert result == expected_result, f'Wrong learners count: {result} for tenant: {tenant_id}'


@pytest.mark.django_db
def test_get_learners_count(base_data):
def test_get_learners_count(base_data): # pylint: disable=unused-argument
"""Test get_learners_count function."""
result = learners.get_learners_count([1, 2, 4])
assert result == {
Expand Down
Empty file added tests/test_helpers/__init__.py
Empty file.
8 changes: 5 additions & 3 deletions tests/test_helpers/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def set_user(request, user_id):
('GET', '?tenant_ids=1,2,3', 2),
('GET', '', 1),
])
def test_has_tenant_access(base_data, method, query_params, user_id):
def test_has_tenant_access(base_data, method, query_params, user_id): # pylint: disable=unused-argument
"""Verify that HasTenantAccess returns True when user has access to all tenants."""
permission = HasTenantAccess()
request = APIRequestFactory().generic(method, f'/dummy/{query_params}')
Expand All @@ -40,7 +40,9 @@ def test_has_tenant_access(base_data, method, query_params, user_id):
('GET', '?tenant_ids=1,2,3', 6, 'denied', [1, 2, 3]),
('GET', '?tenant_ids=1,2,3,4,9', 1, 'invalid', [9, 4]),
])
def test_has_tenant_access_no_access(base_data, method, query_params, user_id, reason, bad_tenant_ids):
def test_has_tenant_access_no_access(
base_data, method, query_params, user_id, reason, bad_tenant_ids
): # pylint: disable=unused-argument
"""Verify that PermissionDenied is raised when user does not have access to one of the tenants."""
permission = HasTenantAccess()
request = APIRequestFactory().generic(method, f'/dummy/{query_params}')
Expand All @@ -63,7 +65,7 @@ def test_has_tenant_access_no_access(base_data, method, query_params, user_id, r

@pytest.mark.django_db
@pytest.mark.parametrize('user_id', [0, None])
def test_has_tenant_access_not_authenticated(base_data, user_id):
def test_has_tenant_access_not_authenticated(base_data, user_id): # pylint: disable=unused-argument
"""Verify that NotAuthenticated is raised when user is not authenticated."""
permission = HasTenantAccess()
request = APIRequestFactory().generic('GET', '/dummy/')
Expand Down

0 comments on commit 8adc75b

Please sign in to comment.