diff --git a/contentcuration/contentcuration/tests/test_chef_pipeline.py b/contentcuration/contentcuration/tests/test_chef_pipeline.py index 27637c49e3..9e93512770 100644 --- a/contentcuration/contentcuration/tests/test_chef_pipeline.py +++ b/contentcuration/contentcuration/tests/test_chef_pipeline.py @@ -88,7 +88,7 @@ def test_authenticate_user_internal(self): response = self.post(self.authenticate_user_internal_url, None) assert response.status_code == 200 data = json.loads(response.content) - assert data["success"] == True + assert data["success"] assert data["username"] == user().email def test_check_version_bad_request(self): @@ -184,6 +184,32 @@ def test_add_nodes(self): response.content ) + def test_add_node_with_tags(self): + response = self.post( + self.create_channel_url, {"channel_data": channel_metadata} + ) + assert response.status_code == 200 + data = json.loads(response.content) + assert "root" in data + + node_data = node_json( + {"kind": "video", "license": cc.License.objects.all()[0].license_name} + ) + unique_title = "This is a title that we can almost certainly find uniquely later" + node_data["tags"] = ["test"] + node_data["title"] = unique_title + response = self.post( + self.add_nodes_url, {"root_id": data["root"], "content_data": [node_data]} + ) + assert response.status_code == 200, "Call failed:\n output: {}".format( + response.content + ) + + node = cc.ContentNode.objects.get(title=unique_title) + + self.assertEqual(node.tags.count(), 1) + self.assertEqual(node.tags.first().tag_name, "test") + def test_finish_channel_bad_request(self): response = self.post(self.finish_channel_url, {}) assert response.status_code == 400 diff --git a/contentcuration/contentcuration/views/internal.py b/contentcuration/contentcuration/views/internal.py index 8eb625f81a..54097c5d08 100644 --- a/contentcuration/contentcuration/views/internal.py +++ b/contentcuration/contentcuration/views/internal.py @@ -219,7 +219,7 @@ def api_commit_channel(request): event = generate_update_event( channel_id, CHANNEL, - {"root_id": obj.main_tree.id, "staging_root_id": obj.staging_tree.id,}, + {"root_id": obj.main_tree.id, "staging_root_id": obj.staging_tree.id}, ) # Mark old staging tree for garbage collection @@ -441,7 +441,7 @@ def get_channel_status_bulk(request): raise PermissionDenied() statuses = {cid: get_status(cid) for cid in data['channel_ids']} - return Response({"success": True, "statuses": statuses,}) + return Response({"success": True, "statuses": statuses}) except (Channel.DoesNotExist, PermissionDenied): return HttpResponseNotFound( "No complete set of channels matching: {}".format(",".join(channel_ids)) @@ -642,8 +642,7 @@ def create_node(node_data, parent_node, sort_order): # noqa: C901 ) if len(tags) > 0: - node.tags = tags - node.save() + node.tags.set(tags) return node