Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions learning_resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ def upsert_offered_by_data():
for offeror in offered_by_json:
offeror_fields = offeror["fields"]
offered_by, _ = LearningResourceOfferor.objects.update_or_create(
name=offeror_fields["name"],
code=offeror_fields["code"],
defaults=offeror_fields,
)
offeror_upserted_actions(offered_by)
offeror_upserted_actions(offered_by, overwrite=True)
offerors.append(offeror_fields["name"])
invalid_offerors = LearningResourceOfferor.objects.exclude(name__in=offerors)
for offeror in invalid_offerors:
Expand Down
21 changes: 20 additions & 1 deletion learning_resources/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
LearningResourceRunFactory,
LearningResourceTopicFactory,
)
from learning_resources.models import LearningResourcePlatform, LearningResourceTopic
from learning_resources.models import (
LearningResourceOfferor,
LearningResourcePlatform,
LearningResourceTopic,
)
from learning_resources.utils import (
add_parent_topics_to_learning_resource,
upsert_topic_data,
Expand Down Expand Up @@ -305,3 +309,18 @@ def test_add_parent_topics_to_learning_resource(fixture_resource):
fixture_resource.refresh_from_db()

assert fixture_resource.topics.filter(pk=main_topic.id).exists()


def test_upsert_offered_by(mocker):
"""Test that upsert_offered_by_data creates expected offerors and triggers pluggy"""
mock_upsert = mocker.patch("learning_resources.utils.offeror_upserted_actions")
with Path.open(Path(__file__).parent / "fixtures" / "offered_by.json") as inf:
offered_by_json = json.load(inf)
utils.upsert_offered_by_data()
assert LearningResourceOfferor.objects.count() == len(offered_by_json)
for offered_by_data in offered_by_json:
offeror = LearningResourceOfferor.objects.get(
code=offered_by_data["fields"]["code"]
)
assert offeror.name == offered_by_data["fields"]["name"]
mock_upsert.assert_any_call(offeror, overwrite=True)