Skip to content

Commit

Permalink
Fix to test_file.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anbeemer committed Jul 17, 2024
1 parent c85a7f3 commit 87ec50c
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import markdown2canvas as mc

import pytest
import json
import datetime

@pytest.fixture(scope='class')
Expand All @@ -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





Expand All @@ -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.
Expand All @@ -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



Expand Down

0 comments on commit 87ec50c

Please sign in to comment.