Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 167 additions & 13 deletions hackIDE/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,177 @@
# @Last Modified time: 2016-01-12 05:49:53


from django.test import TestCase
from django.test import TestCase, LiveServerTestCase
from django.core.urlresolvers import reverse

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

import os
from time import sleep

# URL-related constants
BASE_URL = 'localhost:8000'

# List of important elements' ids and classes
MAIN_TEXT_AREA_CLASS_NAME = 'ace_text-input'
COMPILE_BUTTON_ID = 'compile-code'
RUN_BUTTON_ID = 'run-code'
CUSTOM_INPUT_ID = 'custom-input'
CUSTOM_INPUT_CHECKBOX_ID = 'custom-input-checkbox'

# List of important messages
COMPILE_SUCCESS = 'OK'
COMPILE_FAILURE = '--'


class IndexViewTests(TestCase):

def test_index_view_in_general(self):
"""
Testing for status code returned as well checking for text matching from different parts of index view
"""
response = self.client.get(reverse('hackIDE:index'))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "hackIDE")
self.assertContains(response, "Use custom input to test the code")
self.assertContains(response, "Powered by")
def test_index_view_in_general(self):
"""
Testing for status code returned as well checking for text matching from different parts of index view
"""
response = self.client.get(reverse('hackIDE:index'))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "hackIDE")
self.assertContains(response, "Use custom input to test the code")
self.assertContains(response, "Powered by")


# """
# TODO: Write some Selenium tests - testing UI for different features
# """


class CompileSuccessOnIndex(LiveServerTestCase):

def setUp(self):
self.selenium = webdriver.Chrome()
super(CompileSuccessOnIndex, self).setUp()

def tearDown(self):
self.selenium.quit()
super(CompileSuccessOnIndex, self).tearDown()

def test_go_on(self):
"""
Testing if the application displays the proper success status without any additional input
"""
selenium = self.selenium
selenium.get(BASE_URL)

compile_btn = selenium.find_element_by_id(COMPILE_BUTTON_ID)

compile_btn.send_keys(Keys.RETURN)

sleep(3)

assert COMPILE_SUCCESS in selenium.page_source


class CompileFailOnIndex(LiveServerTestCase):

def setUp(self):
self.selenium = webdriver.Chrome()
super(CompileFailOnIndex, self).setUp()

def tearDown(self):
self.selenium.quit()
super(CompileFailOnIndex, self).tearDown()

def test_go_on(self):
"""
Testing if the application displays the proper failure status for compilation errors
"""
selenium = self.selenium
selenium.get(BASE_URL)

compile_btn = selenium.find_element_by_id(COMPILE_BUTTON_ID)

ace_text_area = selenium.find_elements_by_class_name(MAIN_TEXT_AREA_CLASS_NAME)[0]
ace_text_area.clear()
ace_text_area.send_keys('fail')

sleep(2)
compile_btn.send_keys(Keys.RETURN)
sleep(3)

assert 'Compile Status:' in selenium.page_source
assert COMPILE_FAILURE in selenium.page_source


class CheckCustomInputDisplay(LiveServerTestCase):

def setUp(self):
self.selenium = webdriver.Chrome()
super(CheckCustomInputDisplay, self).setUp()

def tearDown(self):
self.selenium.quit()
super(CheckCustomInputDisplay, self).tearDown()

def test_go_on(self):
"""
Testing if the custom input is displayed
"""
selenium = self.selenium
selenium.get(BASE_URL)
test_input = '123 test'

custom_input_checkbox = selenium.find_element_by_id(CUSTOM_INPUT_CHECKBOX_ID)
run_btn = selenium.find_element_by_id(RUN_BUTTON_ID)

custom_input_checkbox.click()
custom_input = selenium.find_element_by_id(CUSTOM_INPUT_ID)

custom_input.send_keys(test_input)
run_btn.send_keys(Keys.RETURN)

sleep(4)

assert COMPILE_SUCCESS in selenium.page_source
assert test_input in selenium.page_source


class TestSavedCode(LiveServerTestCase):

def setUp(self):
self.selenium = webdriver.Chrome()
super(TestSavedCode, self).setUp()

def tearDown(self):
self.selenium.quit()
super(TestSavedCode, self).tearDown()

def test_go_on(self):
"""
Testing the save code feature.
"""
selenium = self.selenium
selenium.get(BASE_URL)

run_btn = selenium.find_element_by_id(RUN_BUTTON_ID)

ace_text_area = selenium.find_elements_by_class_name(MAIN_TEXT_AREA_CLASS_NAME)[0]
ace_text_area.clear()
ace_text_area.send_keys('#include <iostream>')
ace_text_area.send_keys(Keys.RETURN) # Need a blank line after an include directive.

code_text = 'Hello, World!'
code = 'using namespace std; int main() { cout << "' + code_text + '" << endl; return 0; }'
ace_text_area.send_keys(code)

sleep(2)
run_btn.send_keys(Keys.RETURN)
sleep(3)

new_link = selenium.find_element_by_id('copy_code').text

selenium.get(new_link)
sleep(2)

"""
TODO: Write some Selenium tests - testing UI for different features
"""
run_btn = selenium.find_element_by_id(RUN_BUTTON_ID)
run_btn.send_keys(Keys.RETURN)
sleep(3)

assert code_text in selenium.page_source
28 changes: 17 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
alabaster==0.7.9
Babel==2.1.1
Django==1.9.1
Jinja2==2.8
MarkupSafe==0.23
MySQL-python==1.2.3
Pillow==2.3.0
PyPDF2==1.25.1
Pygments==2.0.2
Sphinx==1.3.3
beautifulsoup4==4.4.0
decorator==3.4.0
Django==1.9.1
django-cors-headers==1.1.0
docutils==0.13.1
gunicorn==19.4.5
Jinja2==2.8
MarkupSafe==0.23
mongoengine==0.10.6
MySQL-python==1.2.3
oauthlib==0.6.1
Pillow==2.3.0
pycurl==7.19.3
Pygments==2.0.2
pymongo==3.4.0
PyPDF2==1.25.1
pytz==2016.10
requests==2.2.1
selenium==3.0.2
simplejson==3.3.1
six==1.10.0
snowballstemmer==1.2.1
Sphinx==1.3.3
sphinx-rtd-theme==0.1.9
urllib3==1.7.1
wheel==0.24.0
whitenoise==2.0.6
wsgiref==0.1.2
mongoengine==0.10.6