From 8dd99d1cf2457c677fcd4de47f51f9a46f47598d Mon Sep 17 00:00:00 2001 From: Chau Nguyen Date: Wed, 11 Jan 2017 14:56:21 -0800 Subject: [PATCH 1/3] Initial commit --- hackIDE/tests.py | 178 +++++++++++++++++++++++++++++++++++++++++++---- hackIDE/views.py | 2 +- requirements.txt | 28 +++++--- 3 files changed, 183 insertions(+), 25 deletions(-) diff --git a/hackIDE/tests.py b/hackIDE/tests.py index b192774..77fea18 100644 --- a/hackIDE/tests.py +++ b/hackIDE/tests.py @@ -6,23 +6,175 @@ # @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 +from selenium.webdriver.common.by import By # for classes +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 ') + 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 \ No newline at end of file diff --git a/hackIDE/views.py b/hackIDE/views.py index 7501ad4..9c3e5d6 100644 --- a/hackIDE/views.py +++ b/hackIDE/views.py @@ -18,7 +18,7 @@ # access config variable DEBUG = (os.environ.get('HACKIDE_DEBUG') != None) # DEBUG = (os.environ.get('HACKIDE_DEBUG') or "").lower() == "true" -CLIENT_SECRET = os.environ['HE_CLIENT_SECRET'] if not DEBUG else "" +CLIENT_SECRET = os.environ['HE_CLIENT_SECRET'] if DEBUG else "" permitted_languages = ["C", "CPP", "CSHARP", "CLOJURE", "CSS", "HASKELL", "JAVA", "JAVASCRIPT", "OBJECTIVEC", "PERL", "PHP", "PYTHON", "R", "RUBY", "RUST", "SCALA"] diff --git a/requirements.txt b/requirements.txt index 1c64f9d..4a61c13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file From 81283a6213757d296b9e91797a86822b8f94ed99 Mon Sep 17 00:00:00 2001 From: Chau Nguyen Date: Thu, 12 Jan 2017 07:09:18 -0800 Subject: [PATCH 2/3] revert --- hackIDE/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hackIDE/views.py b/hackIDE/views.py index 9c3e5d6..7501ad4 100644 --- a/hackIDE/views.py +++ b/hackIDE/views.py @@ -18,7 +18,7 @@ # access config variable DEBUG = (os.environ.get('HACKIDE_DEBUG') != None) # DEBUG = (os.environ.get('HACKIDE_DEBUG') or "").lower() == "true" -CLIENT_SECRET = os.environ['HE_CLIENT_SECRET'] if DEBUG else "" +CLIENT_SECRET = os.environ['HE_CLIENT_SECRET'] if not DEBUG else "" permitted_languages = ["C", "CPP", "CSHARP", "CLOJURE", "CSS", "HASKELL", "JAVA", "JAVASCRIPT", "OBJECTIVEC", "PERL", "PHP", "PYTHON", "R", "RUBY", "RUST", "SCALA"] From a8a3595de21038ee7ceecb6c4170a8468d6c401a Mon Sep 17 00:00:00 2001 From: Chau Nguyen Date: Thu, 12 Jan 2017 19:13:49 -0800 Subject: [PATCH 3/3] Minor cleanup --- hackIDE/tests.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hackIDE/tests.py b/hackIDE/tests.py index 77fea18..eaf3e3a 100644 --- a/hackIDE/tests.py +++ b/hackIDE/tests.py @@ -11,24 +11,25 @@ from selenium import webdriver from selenium.webdriver.common.keys import Keys -from selenium.webdriver.common.by import By # for classes + import os from time import sleep # URL-related constants BASE_URL = 'localhost:8000' -# List of important elements' ids and classes. +# 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. +# List of important messages COMPILE_SUCCESS = 'OK' COMPILE_FAILURE = '--' + class IndexViewTests(TestCase): def test_index_view_in_general(self): @@ -177,4 +178,5 @@ def test_go_on(self): 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 \ No newline at end of file