Skip to content
Snippets Groups Projects

Resolve "Updating own past feedback sets other tutors assignment to is_done=True"

All threads resolved!
2 files
+ 28
19
Compare changes
  • Side-by-side
  • Inline
Files
2
import json
import os
from pathlib import Path
from django.test import LiveServerTestCase
from selenium import webdriver
@@ -10,18 +11,22 @@ from functional_tests.util import login, create_browser, reset_browser_after_tes
from util import factory_boys as fact
def expect_file_to_be_present(path):
def expect_file_to_be_downloaded(path):
"""
Checks if a file has finished downloading by checking if a file exists at the path and
no accompanying `<path>.part` file.
:param path: path to check
:return:
"""
def condition(*args):
try:
with open(path):
pass
except FileNotFoundError:
return False
return True
file_present = Path(path).is_file()
partial_file_present = Path(os.path.join(path, '.part')).is_file()
return file_present and not partial_file_present
return condition
JSON_EXPORT_FILE = os.path.join(os.path.dirname(__file__), 'export.json')
SCREENSHOTS = os.path.join(os.path.dirname(__file__), 'screenshots')
class ExportTestModal(LiveServerTestCase):
@@ -51,6 +56,15 @@ class ExportTestModal(LiveServerTestCase):
)
def tearDown(self):
try:
os.mkdir(SCREENSHOTS)
except FileExistsError:
pass
for method, error in self._outcome.errors:
if error:
self.browser.get_screenshot_as_file(
os.path.join(SCREENSHOTS, self.id() + ".png")
)
reset_browser_after_test(self.browser, self.live_server_url)
def _login(self):
@@ -97,8 +111,8 @@ class ExportTestModal(LiveServerTestCase):
list_elements[1].find_element_by_tag_name('a').text)
def test_export_student_scores_as_json(self):
self._login()
fact.StudentInfoFactory()
self._login()
export_btn = self.browser.find_element_by_id('export-btn')
export_btn.click()
export_scores = self.browser.find_element_by_id('export-list0')
@@ -110,21 +124,29 @@ class ExportTestModal(LiveServerTestCase):
export_type_json.click()
data_export_btn = data_export_modal.find_element_by_id('export-data-download-btn')
data_export_btn.click()
WebDriverWait(self.browser, 10).until(expect_file_to_be_present(JSON_EXPORT_FILE))
with open(JSON_EXPORT_FILE) as f:
data = json.load(f)
self.assertEqual('B.Inf.4242 Test Module', data[0]['Exam'])
os.remove(JSON_EXPORT_FILE)
WebDriverWait(self.browser, 10).until(expect_file_to_be_downloaded(JSON_EXPORT_FILE))
try:
with open(JSON_EXPORT_FILE) as f:
data = json.load(f)
self.assertEqual('B.Inf.4242 Test Module', data[0]['Exam'])
except Exception as e:
raise e
finally:
os.remove(JSON_EXPORT_FILE)
def test_export_instance(self):
self._login()
fact.SubmissionFactory()
self._login()
self.browser.find_element_by_id('export-btn').click()
self.browser.find_element_by_id('export-list1').click()
instance_export_modal = self.browser.find_element_by_id('instance-export-modal')
instance_export_modal.find_element_by_id('instance-export-dl').click()
WebDriverWait(self.browser, 10).until(expect_file_to_be_present(JSON_EXPORT_FILE))
with open(JSON_EXPORT_FILE) as f:
data = json.load(f)
self.assertEqual('B.Inf.4242 Test Module', data['examTypes'][0]['moduleReference'])
os.remove(JSON_EXPORT_FILE)
WebDriverWait(self.browser, 10).until(expect_file_to_be_downloaded(JSON_EXPORT_FILE))
try:
with open(JSON_EXPORT_FILE) as f:
data = json.load(f)
self.assertEqual('B.Inf.4242 Test Module', data['examTypes'][0]['moduleReference'])
except Exception as e:
raise e
finally:
os.remove(JSON_EXPORT_FILE)
Loading