Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand committed Aug 28, 2024
1 parent b18366c commit 45537cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions learning_resources/etl/mitpe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def read_json(file_path):
def test_extract(settings, mock_fetch_data, prof_ed_api_url):
"""Test extract function"""
settings.MITPE_BASE_API_URL = prof_ed_api_url
settings.MITPE_API_ENABLED = True
expected = []
for page in range(3):
with Path.open(
Expand Down
1 change: 0 additions & 1 deletion learning_resources/etl/prolearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
{{operator: \"<>\", name: \"department\", value: \"MIT xPRO\"}}
{see_exclusion}
{mitpe_exclusion}
{{operator: \"<>\", name: \"department\", value: \"MIT Professional Education\"}}
]
}}
]
Expand Down
36 changes: 19 additions & 17 deletions learning_resources/etl/prolearn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from datetime import UTC, datetime
from decimal import Decimal
from pathlib import Path
from urllib.parse import urljoin, urlparse

import pytest
Expand Down Expand Up @@ -60,22 +61,23 @@ def _mock_offerors_platforms():


@pytest.fixture(autouse=True)
def mock_prolearn_api_setting(settings): # noqa: PT004
def mock_prolearn_api_setting(settings):
"""Set the prolearn api url"""
settings.PROLEARN_CATALOG_API_URL = "http://localhost/test/programs/api"
return settings


@pytest.fixture
def mock_csail_programs_data():
"""Mock prolearn CSAIL programs data"""
with open("./test_json/prolearn_csail_programs.json") as f: # noqa: PTH123
with Path.open("./test_json/prolearn_csail_programs.json") as f:
return json.loads(f.read())


@pytest.fixture
def mock_mitpe_courses_data():
"""Mock prolearn MIT Professional Education courses data"""
with open("./test_json/prolearn_mitpe_courses.json") as f: # noqa: PTH123
with Path.open("./test_json/prolearn_mitpe_courses.json") as f:
return json.loads(f.read())


Expand Down Expand Up @@ -267,8 +269,8 @@ def test_prolearn_transform_courses(mock_mitpe_courses_data):
@pytest.mark.parametrize(
("date_int", "expected_dt"),
[
[1670932800, datetime(2022, 12, 13, 12, 0, tzinfo=UTC)], # noqa: PT007
[None, None], # noqa: PT007
(1670932800, datetime(2022, 12, 13, 12, 0, tzinfo=UTC)),
(None, None),
],
)
def test_parse_date(date_int, expected_dt):
Expand All @@ -279,10 +281,10 @@ def test_parse_date(date_int, expected_dt):
@pytest.mark.parametrize(
("price_str", "price_list"),
[
["$5,342", [round(Decimal(5342), 2)]], # noqa: PT007
["5.34", [round(Decimal(5.34), 2)]], # noqa: PT007
[None, []], # noqa: PT007
["", []], # noqa: PT007
("$5,342", [round(Decimal(5342), 2)]),
("5.34", [round(Decimal(5.34), 2)]),
(None, []),
("", []),
],
)
def test_parse_price(price_str, price_list):
Expand All @@ -294,10 +296,10 @@ def test_parse_price(price_str, price_list):
@pytest.mark.parametrize(
("topic", "expected"),
[
["Blockchain", "Blockchain"], # noqa: PT007
["Systems Engineering", "Systems Engineering"], # noqa: PT007
["Other Business", "Management"], # noqa: PT007
["Other Technology", "Digital Business & IT"], # noqa: PT007
("Blockchain", "Blockchain"),
("Systems Engineering", "Systems Engineering"),
("Other Business", "Management"),
("Other Technology", "Digital Business & IT"),
],
)
def test_parse_topic(topic, expected):
Expand Down Expand Up @@ -352,9 +354,9 @@ def test_parse_platform(department, platform_name):
@pytest.mark.parametrize(
("featured_image_url", "expected_url"),
[
["/a/b/c.jog", "http://localhost/a/b/c.jog"], # noqa: PT007
["", None], # noqa: PT007
[None, None], # noqa: PT007
("/a/b/c.jog", "http://localhost/a/b/c.jog"),
("", None),
(None, None),
],
)
def test_parse_image(featured_image_url, expected_url):
Expand Down Expand Up @@ -404,7 +406,7 @@ def test_sloan_exclusion(settings, mocker, sloan_api_enabled, mitpe_api_enabled)
"""Slaon/MITPE exclusion should be included if respective api enabled"""
settings.SEE_API_ENABLED = sloan_api_enabled
settings.MITPE_API_ENABLED = mitpe_api_enabled
mock_post = mocker.patch("learning_resources.etl.sloan.requests.post")
mock_post = mocker.patch("learning_resources.etl.prolearn.requests.post")
extract_data("course")
assert (
SEE_EXCLUSION in mock_post.call_args[1]["json"]["query"]
Expand Down

0 comments on commit 45537cf

Please sign in to comment.