summaryrefslogtreecommitdiff
path: root/yaksh/tests
diff options
context:
space:
mode:
authorankitjavalkar2016-09-06 18:56:30 +0530
committerankitjavalkar2016-09-21 17:51:23 +0530
commit722e82275c28418dc7535ca7393b81eecadbeba9 (patch)
tree8cb74f9231f81f144032b0ea3d92314e2905df11 /yaksh/tests
parent87930b211e3011ad0e2da982519ef5e6ef5ab865 (diff)
downloadonline_test-722e82275c28418dc7535ca7393b81eecadbeba9.tar.gz
online_test-722e82275c28418dc7535ca7393b81eecadbeba9.tar.bz2
online_test-722e82275c28418dc7535ca7393b81eecadbeba9.zip
Modify selenium based test to accomodate create_demo_course command
Diffstat (limited to 'yaksh/tests')
-rw-r--r--yaksh/tests/selenium_test.py14
-rw-r--r--yaksh/tests/test_load.py56
2 files changed, 12 insertions, 58 deletions
diff --git a/yaksh/tests/selenium_test.py b/yaksh/tests/selenium_test.py
index a0ce8f2..15d730e 100644
--- a/yaksh/tests/selenium_test.py
+++ b/yaksh/tests/selenium_test.py
@@ -3,16 +3,14 @@ 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
class SeleniumTest():
def __init__(self, url, quiz_name):
- try:
- self.driver = webdriver.PhantomJS()
- except WebDriverException:
- self.driver = webdriver.Firefox()
+ self.driver = webdriver.Firefox()
self.quiz_name = quiz_name
self.url = url
@@ -94,7 +92,7 @@ class SeleniumTest():
# Correct Answer
loop_count = 1
- answer = '\"#!/bin/bash\\n[[ $# -eq 2 ]] && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))\"'
+ answer = '\"#!/bin/bash\\ncat $1 | cut -d: -f2 | paste -d: $3 - $2\"'
self.submit_answer(question_label, answer, loop_count)
def open_quiz(self):
@@ -107,8 +105,8 @@ class SeleniumTest():
)
start_exam_elem.click()
- self.test_c_question(question_label=3)
- self.test_python_question(question_label=1)
+ self.test_c_question(question_label=1)
+ self.test_python_question(question_label=3)
self.test_bash_question(question_label=2)
def close_quiz(self):
@@ -139,7 +137,7 @@ if __name__ == '__main__':
parser.add_argument("-n", "--number", type=int, default=10, help="number of users")
opts = parser.parse_args()
- quiz_name = "yaksh demo quiz"
+ quiz_name = "Demo quiz"
selenium_test = SeleniumTest(url=opts.url, quiz_name=quiz_name)
pool = multiprocessing.Pool(opts.number)
pool.map(wrap_run_load_test, user_gen(opts.url, range(opts.start, opts.start + opts.number)))
diff --git a/yaksh/tests/test_load.py b/yaksh/tests/test_load.py
index c552137..27ae750 100644
--- a/yaksh/tests/test_load.py
+++ b/yaksh/tests/test_load.py
@@ -14,9 +14,12 @@ from selenium_test import SeleniumTest
from yaksh.code_server import ServerPool, SERVER_POOL_PORT, SERVER_PORTS
from yaksh import settings
from yaksh.xmlrpc_clients import CodeServerProxy
+from django.core.management import call_command
+
CUR_DIR = os.path.dirname(os.path.abspath(__file__))
+
class MySeleniumTests(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
@@ -33,54 +36,7 @@ class MySeleniumTests(StaticLiveServerTestCase):
cls.code_server_thread = t = Thread(target=code_server_pool.run)
t.start()
- # Create set of demo users and profiles
- mod_user = User.objects.create_user(username='yaksh_demo_mod',
- password='yaksh_demo_mod',
- email='yaksh_demo_mod@test.com'
- )
-
- user = User.objects.create_user(username='demo_yaksh_user',
- password='demo_yaksh_user',
- email='demo_yaksh_user@test.com'
- )
- Profile.objects.create(user=user,
- roll_number='demo_rn',
- institute='IIT',
- department='Chemical',
- position='Student'
- )
-
- # create a course
- course = Course.objects.create(name="Demo Load Course",
- enrollment="Open Course",
- creator=mod_user
- )
- course.students.add(user)
-
- # create a Quiz
- quiz = Quiz.objects.create(
- start_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc),
- end_date_time=datetime(2199, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc),
- duration=30, active=True,
- attempts_allowed=1, time_between_attempts=0,
- description='yaksh demo quiz', pass_criteria=0,
- language='Python', prerequisite=None,
- course=course
- )
-
- # create a question set
- question = Question()
- with open(os.path.join(CUR_DIR, 'test_questions.json'), 'r') as f:
- question_list = f.read()
- question.load_from_json(question_list, mod_user)
-
- # create question paper
- question_paper = QuestionPaper.objects.create(quiz=quiz,
- total_marks=5,
- shuffle_questions=False
- )
- # add fixed set of questions to the question paper
- question_paper.fixed_questions.add(*Question.objects.all())
+ call_command('create_demo_course')
@classmethod
def tearDownClass(cls):
@@ -96,6 +52,6 @@ class MySeleniumTests(StaticLiveServerTestCase):
def test_load(self):
url = '%s%s' % (self.live_server_url, '/exam/login/')
- quiz_name = "yaksh demo quiz"
+ quiz_name = "Demo_quiz"
selenium_test = SeleniumTest(url=url, quiz_name=quiz_name)
- selenium_test.run_load_test(url=url, username='demo_yaksh_user', password='demo_yaksh_user')
+ selenium_test.run_load_test(url=url, username='demo_student', password='demo_student')