Skip to content

Commit 8e891c8

Browse files
committed
Add some doc/comments & remove unnecessary __init__.py file
1 parent be603aa commit 8e891c8

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ build: venv
1313
rm -f README.rst
1414
. venv/bin/activate && python -m build
1515

16-
unit-test: venv install
16+
# Note: "make install" needs to be ran once before this target will work, but we
17+
# don't want to set it as a dependency otherwise it unnecessarily slows down
18+
# fast implement/test cycles. "make install" created an editable install of the
19+
# package which is linked to the files you are editing so there is no need to
20+
# re-install after each change.
21+
unit-test:
1722
. venv/bin/activate && pytest test/unit
1823

1924
lint: venv

test/unit/__init__.py

Whitespace-only changes.

test/unit/test_mas.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
IMAGE = 'testImage'
2424

2525

26-
##############################################################################
26+
# -----------------------------------------------------------------------------
2727
# WARNING: All tests must be written with strictly no external dependencies.
2828
# Mocks must be used in place of any calls to OpenShift API etc.
29-
##############################################################################
29+
# -----------------------------------------------------------------------------
3030

3131

3232
@pytest.fixture(autouse=True)
@@ -36,19 +36,29 @@ def dynamic_client(client):
3636

3737

3838
def test_get_current_catalog_success(dynamic_client):
39-
client = dynamic_client()
40-
resources = MagicMock()
39+
# 1. Create a mock catalogsource resources API
4140
catalog_api = MagicMock()
41+
42+
# 2. Create a mock kubernetes resources API and attach the mock catalogsource API
43+
resources = MagicMock()
4244
resources.get.side_effect = lambda **kwargs: catalog_api if kwargs['api_version'] == 'operators.coreos.com/v1alpha1' \
4345
and kwargs['kind'] == 'CatalogSource' else None
46+
47+
# 3. Create a mock client using the mock resources API
48+
client = dynamic_client()
4449
client.resources = resources
45-
catalog = MagicMock()
46-
catalog_api.get.side_effect = lambda **kwargs: catalog if kwargs['name'] == 'ibm-operator-catalog' \
47-
and kwargs['namespace'] == 'openshift-marketplace' else None
50+
51+
# 4. Create a mock catalogsource API response for the catalogsource mock
4852
spec = MagicMock()
49-
catalog.spec = spec
5053
spec.displayName = CATALOG_DISPLAY_NAME_VALID
5154
spec.image = IMAGE
55+
catalog = MagicMock()
56+
catalog.spec = spec
57+
58+
catalog_api.get.side_effect = lambda **kwargs: catalog if kwargs['name'] == 'ibm-operator-catalog' \
59+
and kwargs['namespace'] == 'openshift-marketplace' else None
60+
61+
# 5. Call the mock API
5262
current_catalog = mas.getCurrentCatalog(client)
5363
assert current_catalog['displayName'] == CATALOG_DISPLAY_NAME_VALID
5464
assert current_catalog['catalogId'] == CATALOG_ID

0 commit comments

Comments
 (0)