Skip to content
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

test: add TestPathRedirectionMiddleware integration tests AP-1547 #298

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b34c983
test: add middleware integration tests
BryanttV Oct 28, 2024
a9cd5df
chore: only execute middleware integration tests
BryanttV Oct 29, 2024
ab85448
chore: use branch with fix
BryanttV Oct 29, 2024
8a71008
chore: only execute middleware integration tests
BryanttV Oct 29, 2024
d25fe88
ci: use ubuntu-22.04 in integration tests workflow
BryanttV Oct 29, 2024
96c29e3
ci: use ubuntu-24.04 in integration tests workflow
BryanttV Oct 29, 2024
c68280d
fix: fix codestyle errors
BryanttV Oct 29, 2024
de7825f
test: add tests for other custom actions
BryanttV Oct 29, 2024
187c6e6
refactor: move get_access_token, make_request, and BaseIntegrationTes…
BryanttV Oct 31, 2024
e82ba34
chore: remove comments in test.py
BryanttV Oct 31, 2024
e1a6643
test: add EDNX_CUSTOM_PATH_REDIRECTS setting in fixtures
BryanttV Oct 31, 2024
38c4234
ci: add custom tutor plugin
BryanttV Nov 1, 2024
b09f775
chore: remove nightly from integration tests workflow
BryanttV Nov 1, 2024
af37b19
chore: update input to inline_tutor_plugin
BryanttV Nov 1, 2024
0e9dbab
ci: use ubuntu-latest in integration tests workflow
BryanttV Nov 1, 2024
5dc0969
chore: commit inline_tutor_plugin input
BryanttV Nov 1, 2024
2cf0ded
chore: uncomment inline_tutor_plugin input
BryanttV Nov 1, 2024
ffdcce5
chore: remove mfe url and update link in assert
BryanttV Nov 1, 2024
5bad7cc
chore: use base url of the tenant
BryanttV Nov 1, 2024
389f0fc
ci: use plugins folder in the integration tests input
BryanttV Nov 5, 2024
76116b5
ci: use custom plugin filename in the integration tests input
BryanttV Nov 5, 2024
5435b34
ci: use plugins folder in the integration tests input
BryanttV Nov 5, 2024
dd1c08d
Revert "ci: use plugins folder in the integration tests input"
BryanttV Nov 5, 2024
f86f4f7
Revert "Revert "ci: use plugins folder in the integration tests input""
BryanttV Nov 5, 2024
f44d271
chore: delete commented tests and remove ignore flag in makefile
BryanttV Nov 7, 2024
9cb671a
ci: add tutor_plugins input in integration tests workflow
BryanttV Nov 13, 2024
e4e62cc
chore: add user profile for user in fixtures
BryanttV Nov 13, 2024
aac938d
fix: use init instead setUp
BryanttV Nov 13, 2024
a5fd61d
test: add username and password of integration test user
BryanttV Nov 13, 2024
958fb05
test: add fixture to start a new session
BryanttV Nov 13, 2024
ea45a44
fix: add session attribute in init method
BryanttV Nov 13, 2024
35e17ce
ci: use main branch in integration tests workflow
BryanttV Nov 13, 2024
a2187a5
test: add missing test when user is logged
BryanttV Nov 13, 2024
8958208
ci: remove tutor_plugins input in integration tests workflow
BryanttV Nov 13, 2024
20b07af
test: add tests for mktg_redirect feature
BryanttV Nov 13, 2024
80ed570
fix: omit folders for coverage
BryanttV Nov 13, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
tutor_version: ['<18.0.0', '<19.0.0', 'nightly']
tutor_version: ['<18.0.0', '<19.0.0']
steps:
- name: Run Integration Tests
uses: eduNEXT/integration-test-in-tutor@main
Expand All @@ -18,3 +18,4 @@ jobs:
shell_file_to_run: 'scripts/execute_integration_tests.sh'
fixtures_file: 'fixtures/initial_data.json'
openedx_imports_test_file_path: 'eox_core/edxapp_wrapper/tests/integration/test_backends.py'
inline_tutor_plugins_folder: 'plugins'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ python-quality-test:
run-tests: python-test python-quality-test

run-integration-tests: install-dev-dependencies
pytest -rPf ./eox_core --ignore-glob='**/unit/*' --ignore-glob='**/edxapp_wrapper/*'
pytest -rPf ./eox_core --ignore-glob='**/unit/*' --ignore-glob='**/edxapp_wrapper/*' --ignore-glob='**/api/v1/*'

upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
Expand Down
108 changes: 5 additions & 103 deletions eox_core/api/v1/tests/integration/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,113 +10,15 @@
import ddt
import requests
from django.conf import settings as ds
from django.test import TestCase
from django.urls import reverse
from rest_framework import status

from eox_core.api.v1.tests.integration.data.fake_users import FAKE_USER_DATA
from eox_core.tests.integration.utils import BaseIntegrationTest, make_request

settings = ds.INTEGRATION_TEST_SETTINGS


def get_access_token() -> str:
"""
Get an access token for all requests in the test suite.

Returns:
str: The access token.
"""
data = {
"client_id": settings["CLIENT_ID"],
"client_secret": settings["CLIENT_SECRET"],
"grant_type": "client_credentials",
}
url = f"http://{settings['LMS_BASE']}/oauth2/access_token/"
response = requests.post(url, data=data, timeout=settings["API_TIMEOUT"])
return response.json()["access_token"]


ACCESS_TOKEN = get_access_token()


# pylint: disable=too-many-arguments
def make_request(
tenant: dict,
method: str,
url: str,
json: dict | None = None,
data: dict | None = None,
params: dict | None = None,
with_auth: bool = True,
) -> requests.Response:
"""
Make a request to a site (default site or tenant).

Args:
tenant (dict): The tenant data.
method (str): The HTTP method ('GET', 'POST', etc.).
url (str): The URL to make the request to.
json (dict, optional): The JSON data for POST, PATCH and PUT requests.
data (dict, optional): The data for POST, PATCH and PUT requests.
params (dict, optional): The parameters for GET and DELETE requests.
with_auth (bool, optional): Whether to include the access token in the request headers.

Returns:
requests.Response: The response object.
"""
headers = {"Host": tenant["domain"]}
if with_auth:
headers["Authorization"] = f"Bearer {ACCESS_TOKEN}"
full_url = f"{tenant['base_url']}/{url}"

method = method.upper()
if method not in ("GET", "POST", "PATCH", "PUT", "DELETE"):
raise ValueError(f"Unsupported HTTP method: {method}.")

return requests.request(
method,
full_url,
json=json,
data=data,
params=params,
headers=headers,
timeout=settings["API_TIMEOUT"],
)


class BaseAPIIntegrationTest(TestCase):
"""
Base class for the integration test suite.
"""

def setUp(self):
"""
Set up the test suite.
"""
self.default_site = self.get_tenant_data()
self.tenant_x = self.get_tenant_data("tenant-x")
self.tenant_y = self.get_tenant_data("tenant-y")
self.demo_course_id = settings["DEMO_COURSE_ID"]

def get_tenant_data(self, prefix: str = "") -> dict:
"""
Get the tenant data.

If no prefix is provided, the default site data is returned.

Args:
prefix (str, optional): The tenant prefix. Defaults to "".

Returns:
dict: The tenant data.
"""
domain = f"{prefix}.{settings['LMS_BASE']}" if prefix else settings["LMS_BASE"]
return {
"base_url": f"http://{domain}",
"domain": domain,
}


class UsersAPIRequestMixin:
"""
Mixin class for the Users API request methods.
Expand Down Expand Up @@ -282,7 +184,7 @@ def delete_pre_enrollment(self, tenant: dict, data: dict | None = None) -> reque


@ddt.ddt
class TestUsersAPIIntegration(BaseAPIIntegrationTest, UsersAPIRequestMixin):
class TestUsersAPIIntegration(BaseIntegrationTest, UsersAPIRequestMixin):
"""Integration test suite for the Users API"""

@ddt.data(
Expand Down Expand Up @@ -493,7 +395,7 @@ def test_update_user_in_tenant_user_not_found(self, param: str, value: str) -> N


@ddt.ddt
class TestEnrollmentAPIIntegration(BaseAPIIntegrationTest, UsersAPIRequestMixin, EnrollmentAPIRequestMixin):
class TestEnrollmentAPIIntegration(BaseIntegrationTest, UsersAPIRequestMixin, EnrollmentAPIRequestMixin):
"""Integration test suite for the Enrollment API"""

def setUp(self) -> None:
Expand Down Expand Up @@ -1078,7 +980,7 @@ def test_update_valid_enrollment_using_force_flag(self, param: str) -> None:

@ddt.ddt
class TestPreEnrollmentAPIIntegration(
BaseAPIIntegrationTest,
BaseIntegrationTest,
UsersAPIRequestMixin,
PreEnrollmentAPIRequestMixin,
):
Expand Down Expand Up @@ -1517,7 +1419,7 @@ def test_delete_pre_enrollment_missing_required_fields(self, errors: dict) -> No
self.assertEqual(pre_enrollment_response.status_code, status.HTTP_200_OK)


class TestInfoView(BaseAPIIntegrationTest):
class TestInfoView(BaseIntegrationTest):
"""
Integration test suite for the info view.
"""
Expand Down
4 changes: 3 additions & 1 deletion eox_core/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ def plugin_settings(settings): # pylint: disable=function-redefined
"API_TIMEOUT": 5,
"CLIENT_ID": "client_id",
"CLIENT_SECRET": "client_secret",
"DEMO_COURSE_ID": os.environ.get("DEMO_COURSE_ID", "course-v1:OpenedX+DemoX+DemoCourse")
"DEMO_COURSE_ID": os.environ.get("DEMO_COURSE_ID", "course-v1:OpenedX+DemoX+DemoCourse"),
"TEST_USER_USERNAME": "admin-eox-core",
"TEST_USER_PASSWORD": "admin",
}
Loading
Loading