Skip to content

Commit

Permalink
tests: fix tests for published records checking
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Sep 13, 2024
1 parent 2092b38 commit c9478e0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cds/modules/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def pid(self):
pid = self.record_fetcher(self.id, self)
return PersistentIdentifier.get(pid.pid_type, pid.pid_value)

@property
def ref(self):
"""Get video url (for the record if it's published)."""
return "https://cds.cern.ch/api/record/{0}".format(str(self["recid"]))

@property
def depid(self):
"""Return depid of the record."""
Expand Down
26 changes: 26 additions & 0 deletions scripts/setup-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
#
# This file is part of CERN Document Server.
# Copyright (C) 2024 CERN.
#
# CERN Document Server is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# CERN Document Server is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CERN Document Server; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

pip install -e .[tests]
16 changes: 15 additions & 1 deletion tests/unit/test_project_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def check_connection(videos, project):
assert all({"$ref": video.ref} in project["videos"] for video in videos)
assert len(videos) == len(project["videos"])

def assert_bucket_for_video(bucket_id, video):
"""Check that the video files have the expected bucket_id."""
for f in video["_files"]:
assert f["bucket_id"] == bucket_id

project_schema = (
"https://cds.cern.ch/schemas/"
"deposits/records/videos/project/project-v1.0.0.json"
Expand Down Expand Up @@ -286,7 +291,8 @@ def check_connection(videos, project):

def get_video_record(depid):
deposit = deposit_video_resolver(depid)
return Video.get_record(deposit.fetch_published()[1].id)
published_deposit = deposit.fetch_published()[1]
return published_deposit

video_1 = get_video_record(video_1_dict["metadata"]["_deposit"]["id"])
video_2 = get_video_record(video_2_dict["metadata"]["_deposit"]["id"])
Expand All @@ -299,6 +305,14 @@ def get_video_record(depid):
assert project_dict["metadata"]["recid"] == 3
assert project_dict["metadata"]["videos"][0] == record_videos[0]
assert project_dict["metadata"]["videos"][1] == record_videos[1]

# Assert published videos have the correct bucket assigned
assert_bucket_for_video(
record_videos[0]["_buckets"]["record"], record_videos[0]
)
assert_bucket_for_video(
record_videos[1]["_buckets"]["record"], record_videos[1]
)
# check database: connection project <---> videos
check_connection(
record_videos,
Expand Down

0 comments on commit c9478e0

Please sign in to comment.