diff options
-rw-r--r-- | yaksh/live_server_tests/load_test.py | 41 | ||||
-rw-r--r-- | yaksh/live_server_tests/selenium_test.py | 50 | ||||
-rw-r--r-- | yaksh/test_views.py | 83 |
3 files changed, 136 insertions, 38 deletions
diff --git a/yaksh/live_server_tests/load_test.py b/yaksh/live_server_tests/load_test.py index c3eb6e6..520bebe 100644 --- a/yaksh/live_server_tests/load_test.py +++ b/yaksh/live_server_tests/load_test.py @@ -1,17 +1,10 @@ -import os -import signal -import subprocess -from datetime import datetime -import pytz from threading import Thread -from selenium.webdriver.firefox.webdriver import WebDriver - from django.contrib.staticfiles.testing import StaticLiveServerTestCase -from yaksh.models import User, Profile, Question, Quiz, Course, QuestionPaper, TestCase +# Local imports +from yaksh.models import User, Profile, Course from yaksh.code_server import ServerPool from yaksh import settings - from .selenium_test import SeleniumTest @@ -33,20 +26,24 @@ class YakshSeleniumTests(StaticLiveServerTestCase): cls.code_server_thread = t = Thread(target=code_server_pool.run) t.start() - cls.demo_student = User.objects.create_user(username='demo_student', - password='demo_student', - email='demo_student@test.com' + cls.demo_student = User.objects.create_user( + username='demo_student', + password='demo_student', + email='demo_student@test.com' ) - cls.demo_student_profile = Profile.objects.create(user=cls.demo_student, + cls.demo_student_profile = Profile.objects.create( + user=cls.demo_student, roll_number=3, institute='IIT', department='Chemical', position='Student' ) - cls.demo_mod = User.objects.create_user(username='demo_mod', - password='demo_mod', - email='demo_mod@test.com' + cls.demo_mod = User.objects.create_user( + username='demo_mod', + password='demo_mod', + email='demo_mod@test.com' ) - cls.demo_mod_profile = Profile.objects.create(user=cls.demo_mod, + cls.demo_mod_profile = Profile.objects.create( + user=cls.demo_mod, roll_number=0, institute='IIT', department='Chemical', position='Moderator' ) @@ -73,7 +70,11 @@ class YakshSeleniumTests(StaticLiveServerTestCase): def test_load(self): url = '%s%s' % (self.live_server_url, '/exam/login/') quiz_name = "Yaksh Demo quiz" - module_name = "demo module" + module_name = "Demo Module" + course_name = "Yaksh Demo course" selenium_test = SeleniumTest(url=url, quiz_name=quiz_name, - module_name=module_name) - selenium_test.run_load_test(url=url, username='demo_student', password='demo_student') + module_name=module_name, + course_name=course_name) + selenium_test.run_load_test( + url=url, username='demo_student', password='demo_student' + ) diff --git a/yaksh/live_server_tests/selenium_test.py b/yaksh/live_server_tests/selenium_test.py index 160ad02..0d9e8b8 100644 --- a/yaksh/live_server_tests/selenium_test.py +++ b/yaksh/live_server_tests/selenium_test.py @@ -1,9 +1,7 @@ from selenium import webdriver -from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC -from selenium.common.exceptions import WebDriverException import multiprocessing import argparse @@ -18,18 +16,20 @@ class ElementDisplay(object): try: element = EC._find_element(driver, self.locator) return element.value_of_css_property("display") == "none" - except Exception as e: + except Exception: return False class SeleniumTestError(Exception): pass + class SeleniumTest(): - def __init__(self, url, quiz_name, module_name): + def __init__(self, url, quiz_name, module_name, course_name): self.driver = webdriver.Firefox() self.quiz_name = quiz_name self.module_name = module_name + self.course_name = course_name self.url = url def run_load_test(self, url, username, password): @@ -43,10 +43,10 @@ class SeleniumTest(): self.logout() self.driver.close() except Exception as e: - self.driver.close() + # self.driver.close() msg = ("An Error occurred while running the Selenium load" - " test on Yaksh!\n" - "Error:\n{0}".format(e)) + " test on Yaksh!\n" + "Error:\n{0}".format(e)) raise SeleniumTestError(msg) @@ -54,7 +54,8 @@ class SeleniumTest(): # get the username, password and submit form elements username_elem = self.driver.find_element_by_id("id_username") password_elem = self.driver.find_element_by_id("id_password") - submit_login_elem = self.driver.find_element_by_css_selector('button.btn') + submit_login_elem = self.driver.find_element_by_css_selector( + 'button.btn') # Type in the username, password and submit form username_elem.send_keys(username) @@ -66,7 +67,8 @@ class SeleniumTest(): for count in range(loop_count): self.driver.find_element_by_link_text(question_label).click() submit_answer_elem = self.driver.find_element_by_id("check") - self.driver.execute_script('global_editor.editor.setValue({});'.format(answer)) + self.driver.execute_script( + 'global_editor.editor.setValue({});'.format(answer)) submit_answer_elem.click() WebDriverWait(self.driver, 90).until(ElementDisplay( (By.XPATH, "//*[@id='ontop']"))) @@ -121,10 +123,12 @@ class SeleniumTest(): def open_quiz(self): # open module link + self.driver.find_elements_by_partial_link_text( + self.course_name)[0].click() self.driver.find_element_by_link_text(self.module_name).click() # open quiz link - quiz_link_elem = self.driver.find_element_by_link_text(self.quiz_name).click() - + self.driver.find_element_by_link_text(self.quiz_name).click() + # Get page elements start_exam_elem = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located((By.NAME, "start")) @@ -158,8 +162,10 @@ class SeleniumTest(): ) logout_link_elem.click() + def user_gen(url, ids): - return [(url, 'User%d'%x, 'User%d'%x) for x in ids] + return [(url, 'User%d' % x, 'User%d' % x) for x in ids] + def wrap_run_load_test(args): url = "http://yaksh.fossee.aero.iitb.ac.in/exam/" @@ -168,17 +174,25 @@ def wrap_run_load_test(args): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('url', type=str, help="url of the website being tested") + parser.add_argument( + 'url', type=str, help="url of the website being tested" + ) parser.add_argument('start', type=int, help="Starting user id") - parser.add_argument("-n", "--number", type=int, default=10, help="number of users") + parser.add_argument( + "-n", "--number", type=int, default=10, help="number of users" + ) opts = parser.parse_args() quiz_name = "Demo quiz" - module_name = "demo module" + module_name = "Demo Module" + course_name = "Yaksh Demo course" selenium_test = SeleniumTest(url=opts.url, quiz_name=quiz_name, - module_name=module_name) + module_name=module_name, + course_name=course_name) pool = multiprocessing.Pool(opts.number) - pool.map(wrap_run_load_test, user_gen(opts.url, range(opts.start, opts.start + opts.number))) + pool.map( + wrap_run_load_test, + user_gen(opts.url, range(opts.start, opts.start + opts.number)) + ) pool.close() pool.join() - diff --git a/yaksh/test_views.py b/yaksh/test_views.py index a5bd25e..45d3314 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1171,6 +1171,20 @@ class TestAddQuiz(TestCase): self.assertEqual(response.status_code, 302) self.assertRedirects(response, '/exam/manage/courses/all_quizzes/') + def test_show_all_quizzes(self): + self.client.login( + username=self.user.username, + password=self.user_plaintext_pass + ) + response = self.client.get( + reverse('yaksh:show_all_quizzes'), + follow=True + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['type'], "quiz") + self.assertEqual(response.context['quizzes'][0], self.quiz) + self.assertTemplateUsed(response, "yaksh/courses.html") + class TestAddTeacher(TestCase): def setUp(self): @@ -1524,6 +1538,14 @@ class TestCourses(TestCase): last_name='student_last_name', email='demo_student@test.com' ) + Profile.objects.create( + user=self.student, + roll_number=10, + institute='IIT', + department='Aeronautical', + position='Moderator', + timezone='UTC' + ) self.teacher_plaintext_pass = 'teacher' self.teacher = User.objects.create_user( @@ -1663,6 +1685,54 @@ class TestCourses(TestCase): self.assertTemplateUsed(response, 'yaksh/design_course_session.html') self.assertFalse(self.user1_course.learning_module.all().exists()) + def test_get_course_modules(self): + """ Test to check if student gets course modules """ + self.client.login( + username=self.student.username, + password=self.student_plaintext_pass + ) + response = self.client.get( + reverse('yaksh:course_modules', + kwargs={"course_id": self.user1_course.id}), + follow=True + ) + # Student is not allowed if not enrolled in the course + err_msg = "You are not enrolled for this course!" + self.assertEqual(response.context['msg'], err_msg) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "yaksh/quizzes_user.html") + + # enroll student in the course + self.user1_course.students.add(self.student) + # deactivate the course and check if student is able to view course + self.user1_course.active = False + self.user1_course.save() + response = self.client.get( + reverse('yaksh:course_modules', + kwargs={"course_id": self.user1_course.id}), + follow=True + ) + err_msg = "{0} is either expired or not active".format( + self.user1_course.name) + self.assertEqual(response.context['msg'], err_msg) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "yaksh/quizzes_user.html") + + # activate the course and check if students gets course modules + self.user1_course.active = True + self.user1_course.save() + self.user1_course.learning_module.add(self.learning_module) + response = self.client.get( + reverse('yaksh:course_modules', + kwargs={"course_id": self.user1_course.id}), + follow=True + ) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "yaksh/course_modules.html") + self.assertEqual(response.context['course'], self.user1_course) + self.assertEqual(response.context['learning_modules'][0], + self.learning_module) + class TestAddCourse(TestCase): def setUp(self): @@ -4624,3 +4694,16 @@ class TestLessons(TestCase): self.assertEqual(response.context["type"], "lesson") self.assertEqual(response.context["lessons"][0], self.lesson) + def test_preview_lesson_description(self): + """ Test preview lesson description converted from md to html""" + self.client.login( + username=self.teacher.username, + password=self.teacher_plaintext_pass + ) + lesson = json.dumps({'description': self.lesson.description}) + response = self.client.post( + reverse('yaksh:preview_html_text'), + data=lesson, content_type="application/json" + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['data'], '<p>test description</p>') |