From 87ec50c7db806436ec977b07722a9fc290e3567e Mon Sep 17 00:00:00 2001 From: Allison Beemer <66966224+anbeemer@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:29:25 -0500 Subject: [PATCH] Fix to test_file.py Takes into account that there may be multiple instances of a given file in different folders if meta.json was changed and the previous instances were not deleted. --- test/test_file.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/test_file.py b/test/test_file.py index bc48ef4..66b221a 100644 --- a/test/test_file.py +++ b/test/test_file.py @@ -4,6 +4,7 @@ import markdown2canvas as mc import pytest +import json import datetime @pytest.fixture(scope='class') @@ -23,9 +24,21 @@ def content(): yield mc.File(folder) +#the following gives all instances of that file, if it lives in multiple locations @pytest.fixture(scope='class') -def file(course): - yield course.get_files(search_term = 'ds150_course_logo.pdf')[0] +def file_list(course): + yield course.get_files(search_term = 'ds150_course_logo.pdf') + +#gives the current instance, based on the destination in meta.json +@pytest.fixture(scope='class') +def current_file(course, file_list): + with open('a_file.file/meta.json', "r", encoding="utf-8") as f: + folder_name = json.loads(f.read())['destination'] + for instance in file_list: + if instance.folder_id == course.get_folders(search_term=folder_name)[0].id: + yield instance + + @@ -39,15 +52,23 @@ def test_can_publish(self, course, content): content.publish(course,overwrite=True) assert content.is_already_uploaded(course) - def test_in_modules(self,course,content): + def test_in_modules(self, course, content): content.publish(course,overwrite=True) for m in content.metadata['modules']: assert content.is_in_module(course, m) module_test = course.get_modules(search_term = m)[0] assert module_test.get_module_items(search_term = 'ds150')[0].title == 'automatically uploaded file: ds150_course_logo.pdf' - def test_in_folder(self,course,file): - assert file.folder_id == course.get_folders(search_term='a_subfolder')[0].id + #tests that it ends up in the folder you specified this time (it can simultaneously be in another folder if you put it there previously) + def test_in_folder(self, course, content, file_list, current_file): + content.publish(course,overwrite=True) + with open('a_file.file/meta.json', "r", encoding="utf-8") as f: + folder_name = json.loads(f.read())['destination'] + folder_list=[] + for instance in file_list: + folder_list.append(instance.folder_id) + assert course.get_folders(search_term=folder_name)[0].id in folder_list + assert current_file.folder_id == course.get_folders(search_term=folder_name)[0].id def test_already_online_raises(self, course, content): # publish once, forcefully. @@ -58,10 +79,10 @@ def test_already_online_raises(self, course, content): content.publish(course,overwrite=False) # default is False - def test_attributes(self, course, content, file): + def test_attributes(self, course, content, current_file): content.publish(course,overwrite=True) - assert file.filename == 'ds150_course_logo.pdf' - assert file.modified_at_date.day == datetime.date.today().day + assert current_file.filename == 'ds150_course_logo.pdf' + assert current_file.modified_at_date.day == datetime.date.today().day