Skip to content

Commit

Permalink
Added unit tests to test_file.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anbeemer committed Jul 17, 2024
1 parent 8114200 commit e0ffa03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/a_file.file/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"type":"file",
"title":"automatically uploaded file: ds150_course_logo.pdf",
"filename":"ds150_course_logo.pdf",
"modules":["Automatically Added Test Module", "Another automatically added test module"],
"modules":["Automatically Added Test Module", "Another automatically added test module", "module created by file upload"],
"destination": "automatically_uploaded_files/a_subfolder"
}
23 changes: 22 additions & 1 deletion 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 datetime

@pytest.fixture(scope='class')
def course():
Expand All @@ -16,12 +17,16 @@ def course():
yield canvas.get_course(test_course_id)

@pytest.fixture(scope='class')
def content(course):
def content():
import os
folder = 'a_file.file'

yield mc.File(folder)

@pytest.fixture(scope='class')
def file(course):
yield course.get_files(search_term = 'ds150_course_logo.pdf')[0]



class TestFile():
Expand All @@ -33,9 +38,16 @@ def test_meta(self, content):
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):
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

def test_already_online_raises(self, course, content):
# publish once, forcefully.
Expand All @@ -46,5 +58,14 @@ def test_already_online_raises(self, course, content):
content.publish(course,overwrite=False) # default is False


def test_attributes(self, course, content, file):
content.publish(course,overwrite=True)
assert file.filename == 'ds150_course_logo.pdf'
assert file.modified_at_date.day == datetime.date.today().day







0 comments on commit e0ffa03

Please sign in to comment.