summaryrefslogtreecommitdiff
path: root/yaksh/tests
diff options
context:
space:
mode:
authorankitjavalkar2016-09-21 15:51:19 +0530
committerankitjavalkar2016-09-21 17:51:23 +0530
commit48f5117a0a0f7f712d3bafabf06e1c63de56e9fa (patch)
treea8a9b90e0df9ce0893e7741bc33309af86ea034d /yaksh/tests
parentbf1986b58ce0e5619a2af221d5897f5f7fc708f0 (diff)
downloadonline_test-48f5117a0a0f7f712d3bafabf06e1c63de56e9fa.tar.gz
online_test-48f5117a0a0f7f712d3bafabf06e1c63de56e9fa.tar.bz2
online_test-48f5117a0a0f7f712d3bafabf06e1c63de56e9fa.zip
Place selenium script and unit tests in live_server_tests dir
Diffstat (limited to 'yaksh/tests')
-rw-r--r--yaksh/tests/load_test.py60
-rw-r--r--yaksh/tests/selenium_test.py145
2 files changed, 0 insertions, 205 deletions
diff --git a/yaksh/tests/load_test.py b/yaksh/tests/load_test.py
deleted file mode 100644
index 05fd02f..0000000
--- a/yaksh/tests/load_test.py
+++ /dev/null
@@ -1,60 +0,0 @@
-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
-from selenium_test import SeleniumTest
-
-from yaksh.code_server import ServerPool #SERVER_POOL_PORT, SERVER_PORTS
-from yaksh import settings
-# from django.core.management import call_command
-from yaksh.management.commands.create_demo_course import create_demo_course
-
-
-CUR_DIR = os.path.dirname(os.path.abspath(__file__))
-
-
-class YakshSeleniumTests(StaticLiveServerTestCase):
- @classmethod
- def setUpClass(cls):
- super(YakshSeleniumTests, cls).setUpClass()
- # setup a demo code server
- settings.code_evaluators['python']['standardtestcase'] = \
- "yaksh.python_assertion_evaluator.PythonAssertionEvaluator"
- settings.code_evaluators['c']['standardtestcase'] = \
- "yaksh.cpp_code_evaluator.CppCodeEvaluator"
- settings.code_evaluators['bash']['standardtestcase'] = \
- "yaksh.bash_code_evaluator.BashCodeEvaluator"
- settings.SERVER_POOL_PORT = 53578
- code_server_pool = ServerPool(ports=settings.SERVER_PORTS, pool_port=settings.SERVER_POOL_PORT)
- cls.code_server_pool = code_server_pool
- cls.code_server_thread = t = Thread(target=code_server_pool.run)
- t.start()
-
- demo_course_setup = create_demo_course()
-
- @classmethod
- def tearDownClass(cls):
- User.objects.all().delete()
- Question.objects.all().delete()
- Quiz.objects.all().delete()
- Course.objects.all().delete()
-
- settings.SERVER_POOL_PORT = 53579
-
- cls.code_server_pool.stop()
- cls.code_server_thread.join()
-
- super(YakshSeleniumTests, cls).tearDownClass()
-
- def test_load(self):
- url = '%s%s' % (self.live_server_url, '/exam/login/')
- quiz_name = "Demo_quiz"
- selenium_test = SeleniumTest(url=url, quiz_name=quiz_name)
- selenium_test.run_load_test(url=url, username='demo_student', password='demo_student')
diff --git a/yaksh/tests/selenium_test.py b/yaksh/tests/selenium_test.py
deleted file mode 100644
index 01ccc96..0000000
--- a/yaksh/tests/selenium_test.py
+++ /dev/null
@@ -1,145 +0,0 @@
-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
-
-class SeleniumTest():
- def __init__(self, url, quiz_name):
- self.driver = webdriver.Firefox()
- self.quiz_name = quiz_name
- self.url = url
-
- def run_load_test(self, url, username, password):
- try:
- self.driver.delete_all_cookies()
- self.driver.get(self.url)
- self.login(username, password)
- self.open_quiz()
- self.close_quiz()
- self.logout()
- self.driver.close()
- except Exception as e:
- with open("/tmp/yaksh_load_test_log.txt", "ab") as f:
- f.write('Username: {0}\nError: {1}\n'.format(username, e))
- self.driver.close()
-
- def login(self, username, password):
- # 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')
-
- # Type in the username, password and submit form
- username_elem.send_keys(username)
- password_elem.send_keys(password)
- submit_login_elem.click()
-
- def submit_answer(self, question_label, answer, loop_count=1):
- self.driver.implicitly_wait(2)
- 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('editor.setValue({})'.format(answer))
- submit_answer_elem.click()
-
- def test_c_question(self, question_label):
- # Incorrect Answer
- loop_count = 10
- answer = '\"int add(int a, int b, int c)\\n{return;}\"'
- self.submit_answer(question_label, answer, loop_count)
-
- # Infinite Loop
- loop_count = 3
- answer = '\"int add(int a, int b, int c)\\n{while(1){}}\"'
- self.submit_answer(question_label, answer, loop_count)
-
- # Correct Answer
- loop_count = 1
- answer = '\"int add(int a, int b, int c)\\n{return a + b + c;}\"'
- self.submit_answer(question_label, answer, loop_count)
-
- def test_python_question(self, question_label):
- # Incorrect Answer
- loop_count = 10
- answer = '\"def is_palindrome(s):\\n return s\"'
- self.submit_answer(question_label, answer, loop_count)
-
- # Infinite Loop
- loop_count = 3
- answer = '\"while True:\\n pass"'
- self.submit_answer(question_label, answer, loop_count)
-
- # Correct Answer
- loop_count = 1
- answer = '\"def is_palindrome(s):\\n return s[::-1] == s\"'
- self.submit_answer(question_label, answer, loop_count)
-
- def test_bash_question(self, question_label):
- # Incorrect Answer
- loop_count = 10
- answer = '\"#!/bin/bash\\nls\"'
- self.submit_answer(question_label, answer, loop_count)
-
- # Infinite Loop
- loop_count = 3
- answer = '\"#!/bin/bash\\nwhile [ 1 ]; do : ; done\"'
- self.submit_answer(question_label, answer, loop_count)
-
- # Correct Answer
- loop_count = 1
- answer = '\"#!/bin/bash\\ncat $1 | cut -d: -f2 | paste -d: $3 - $2\"'
- self.submit_answer(question_label, answer, loop_count)
-
- def open_quiz(self):
- # open quiz link
- quiz_link_elem = 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"))
- )
- start_exam_elem.click()
-
- 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):
- quit_link_elem = WebDriverWait(self.driver, 5).until(
- EC.presence_of_element_located((By.ID, "login_again"))
- )
- quit_link_elem.click()
-
- def logout(self):
- logout_link_elem = WebDriverWait(self.driver, 5).until(
- EC.presence_of_element_located((By.ID, "logout"))
- )
- logout_link_elem.click()
-
-def user_gen(url, 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/"
- selenium_test = SeleniumTest(url=url, quiz_name=quiz_name)
- return selenium_test.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('start', type=int, help="Starting user id")
- parser.add_argument("-n", "--number", type=int, default=10, help="number of users")
- opts = parser.parse_args()
-
- 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)))
- pool.close()
- pool.join()
-