Skip to content

Commit c59099f

Browse files
Refactor opportunity_to_dict tests for dynamic import
Refactor tests to import opportunity_to_dict dynamically and use a fake Opportunities class.
1 parent 6fd93ef commit c59099f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tests/test_single_opportunity_routes.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import pytest
22

3-
from labconnect import db
4-
from labconnect.main.opportunity_routes import opportunity_to_dict
5-
from labconnect.models import Opportunities
6-
7-
83
def test_opportunity_to_dict_none():
9-
assert opportunity_to_dict(None) == {}
4+
from importlib import import_module
5+
opp_mod = import_module("labconnect.main.opportunity_routes")
6+
assert opp_mod.opportunity_to_dict(None) == {}
107

118

129
def test_opportunity_to_dict_populated():
1310
# create a lightweight Opportunities instance (no DB persistence needed)
14-
opp = Opportunities()
11+
import
12+
class FakeOpp:
13+
pass
14+
opp = FakeOpp()
1515
opp.id = 123
1616
opp.name = "Unit Test Opportunity"
1717
opp.description = "A test description"
@@ -25,7 +25,9 @@ def test_opportunity_to_dict_populated():
2525
opp.year = 2025
2626
opp.active = True
2727

28-
out = opportunity_to_dict(opp)
28+
from importlib import import_module
29+
opp_mod = import_module("labconnect.main.opportunity_routes")
30+
out = opp_mod.opportunity_to_dict(opp)
2931

3032
assert out["id"] == 123
3133
assert out["name"] == "Unit Test Opportunity"
@@ -45,6 +47,9 @@ def test_get_single_opportunity_not_found(test_client):
4547
@pytest.mark.usefixtures("test_client")
4648
def test_get_single_opportunity_success_and_json_variant(test_client):
4749
# create and persist an opportunity to the test database
50+
from labconnect import db
51+
from labconnect.models import Opportunities
52+
4853
opp = Opportunities()
4954
opp.name = "Endpoint Test Opportunity"
5055
opp.description = "Endpoint description"

0 commit comments

Comments
 (0)