Skip to content

Commit

Permalink
Added unit tests to test_style.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anbeemer committed Jul 16, 2024
1 parent 3e6e012 commit 1bce33f
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions test/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,77 @@ def course():
yield canvas.get_course(test_course_id)

@pytest.fixture(scope='class')
def page_uses_droplets_via_style(course):
def page_uses_droplets_via_style_generic():
import os
folder = 'uses_droplets_via_style'

yield mc.Page(folder)


@pytest.fixture(scope='class')
def page_uses_droplets_via_style_custom():
import os
folder = 'uses_droplets_via_style_custom'

yield mc.Page(folder)


@pytest.fixture(scope='class')
def page_contents_generic(course):
a = course.get_pages(search_term = 'Test Uses Droplets via Style')[1]
rev = a.show_latest_revision()
yield rev.body

@pytest.fixture(scope='class')
def page_contents_custom(course):
a = course.get_pages(search_term = 'Test Uses Droplets via Style Custom')[0]
rev = a.show_latest_revision()
yield rev.body


class TestStyle():

def test_meta(self, page_uses_droplets_via_style):
assert page_uses_droplets_via_style.name == 'Test Uses Droplets via Style'
def test_meta(self, page_uses_droplets_via_style_generic,page_uses_droplets_via_style_custom):
assert page_uses_droplets_via_style_generic.name == 'Test Uses Droplets via Style'
assert page_uses_droplets_via_style_custom.name == 'Test Uses Droplets via Style Custom'

def test_can_publish(self, course, page_uses_droplets_via_style):
page_uses_droplets_via_style.publish(course,overwrite=True)
def test_can_publish(self, course, page_uses_droplets_via_style_generic,page_uses_droplets_via_style_custom):
page_uses_droplets_via_style_generic.publish(course,overwrite=True)
page_uses_droplets_via_style_custom.publish(course,overwrite=True)

def test_already_online_raises(self, course, page_uses_droplets_via_style):
def test_already_online_raises(self, course,page_uses_droplets_via_style_custom):
# publish once, forcefully.
page_uses_droplets_via_style.publish(course,overwrite=True)

page_uses_droplets_via_style_custom.publish(course,overwrite=True)
# the second publish, with overwrite=False, should raise
with pytest.raises(mc.exception.AlreadyExists):
page_uses_droplets_via_style.publish(course,overwrite=False) # default is False

page_uses_droplets_via_style_custom.publish(course,overwrite=False) # default is False

def test_doesnt_find_deleted(self, course, page_uses_droplets_via_style):
name = page_uses_droplets_via_style.name
def test_doesnt_find_deleted(self, course, page_uses_droplets_via_style_generic):
name = page_uses_droplets_via_style_generic.name

page_uses_droplets_via_style.publish(course,overwrite=True)
page_uses_droplets_via_style_generic.publish(course,overwrite=True)
assert mc.is_page_already_uploaded(name,course)
f = mc.find_page_in_course(name,course)
f.delete()
# print([i.name for i in course.get_pages()])
assert not mc.is_page_already_uploaded(name,course)


def test_can_find_published(self, course, page_uses_droplets_via_style):
page_uses_droplets_via_style.publish(course,overwrite=True)
assert mc.is_page_already_uploaded(page_uses_droplets_via_style.name,course)
def test_can_find_published(self, course, page_uses_droplets_via_style_generic):
page_uses_droplets_via_style_generic.publish(course,overwrite=True)
assert mc.is_page_already_uploaded(page_uses_droplets_via_style_generic.name,course)


def test_default_style_implemented(course, page_contents_generic):
assert 'Markdown header content here' in page_contents_generic
assert 'Header image credit: Medoffer, CC BY-SA 4.0' in page_contents_generic
assert 'This is a photo of a natural heritage site in Ukraine, id: 59-247-5004.' in page_contents_generic

def test_custom_style_implemented(course, page_contents_custom):
assert 'Header image credit: Jeremy Visser, CC BY-SA 4.0' in page_contents_custom
assert 'This is a photo of Mount Ruapehu and Mount Ngauruhoe looking west from the Desert Road in Tongariro National Park (New Zealand) in January 2015.' in page_contents_custom

def test_incorrect_style_used(course, page_contents_generic, page_contents_custom):
assert 'Header image credit: Medoffer, CC BY-SA 4.0' not in page_contents_custom
assert 'Markdown header content here' not in page_contents_custom
assert 'Header image credit: Jeremy Visser, CC BY-SA 4.0' not in page_contents_generic

0 comments on commit 1bce33f

Please sign in to comment.