Skip to content

Commit

Permalink
Fix broken unit tests by mocking metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-woythaler committed Nov 14, 2023
1 parent cb62db9 commit 5af462f
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions test_package/unit/test_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,15 @@ def test_page_needs_updating_content_replace_all_labels_and_labels_not_changed(m
)

message_hash = "[v6e71b3cac15d32fe2d36c270887df9479c25c640]"
existing_page_mock = mocker.Mock()
existing_page_mock = mocker.Mock(
get=mocker.Mock(return_value=[{"name": label} for label in labels])
)
ancestor_mock = mocker.Mock()
ancestor_mock.id = mocker.sentinel.parent_id
existing_page_mock.ancestors = [ancestor_mock]
existing_page_mock.version.message = message_hash
existing_page_mock.metadata.labels.results = []
for label in labels:
label_mock = mocker.Mock()
label_mock.name = label
existing_page_mock.metadata.labels.results.append(label_mock)
# existing_page_mock.metadata.labels.results.append(label_mock)

assert not md2cf.upsert.page_needs_updating(
page, existing_page_mock, replace_all_labels=True
Expand Down Expand Up @@ -424,19 +423,15 @@ def test_page_needs_updating_content_replace_all_labels_and_empty_labels_supplie
)

message_hash = "[v6e71b3cac15d32fe2d36c270887df9479c25c640]"
existing_page_mock = mocker.Mock()
labels = ["label1", "label2"]
existing_page_mock = mocker.Mock(
get=mocker.Mock(return_value=[{"name": label} for label in labels])
)
ancestor_mock = mocker.Mock()
ancestor_mock.id = mocker.sentinel.parent_id
existing_page_mock.ancestors = [ancestor_mock]
existing_page_mock.version.message = message_hash

labels = ["label1", "label2"]
existing_page_mock.metadata.labels.results = []
for label in labels:
label_mock = mocker.Mock()
label_mock.name = label
existing_page_mock.metadata.labels.results.append(label_mock)

assert md2cf.upsert.page_needs_updating(
page, existing_page_mock, replace_all_labels=True
)
Expand All @@ -456,14 +451,35 @@ def test_page_needs_updating_content_replace_all_labels_and_empty_labels_supplie
)

message_hash = "[v6e71b3cac15d32fe2d36c270887df9479c25c640]"
existing_page_mock = mocker.Mock()
existing_page_mock = mocker.Mock(get=mocker.Mock(return_value=[]))
ancestor_mock = mocker.Mock()
ancestor_mock.id = mocker.sentinel.parent_id
existing_page_mock.ancestors = [ancestor_mock]
existing_page_mock.version.message = message_hash

existing_page_mock.metadata.labels.results = []

assert not md2cf.upsert.page_needs_updating(
page, existing_page_mock, replace_all_labels=True
)


def test_page_needs_updated_created_with_no_labels_and_new_ones_were_added(mocker):
"""An existing page with no labels was created, and new labels were added
after the fact. We should update the page with these new labels"""
page = Page(
space=mocker.sentinel.space,
title=mocker.sentinel.title,
body="hello there",
labels=["foo"],
parent_id=mocker.sentinel.parent_id,
)

message_hash = "[v6e71b3cac15d32fe2d36c270887df9479c25c640]"
existing_page_mock = mocker.Mock(get=mocker.Mock(return_value=[]))
ancestor_mock = mocker.Mock()
ancestor_mock.id = mocker.sentinel.parent_id
existing_page_mock.ancestors = [ancestor_mock]
existing_page_mock.version.message = message_hash

assert md2cf.upsert.page_needs_updating(
page, existing_page_mock, replace_all_labels=True
)

0 comments on commit 5af462f

Please sign in to comment.