From d251375f6edd614cbe338970d65eb89a91064238 Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Fri, 14 Mar 2014 12:04:03 -0400 Subject: [PATCH] Updated existing tests --- karmaworld/apps/courses/forms.py | 8 ++-- karmaworld/apps/courses/test/test_selenium.py | 48 ++++++++++++++----- karmaworld/templates/partial/add_course.html | 19 ++++---- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/karmaworld/apps/courses/forms.py b/karmaworld/apps/courses/forms.py index fc97194..1d24ac6 100644 --- a/karmaworld/apps/courses/forms.py +++ b/karmaworld/apps/courses/forms.py @@ -13,6 +13,7 @@ from ajax_select.fields import AutoCompleteSelectField from ajax_select_cascade.fields import AutoCompleteDependentSelectField # generates DIV errors with appropriate classes +from django.utils.safestring import mark_safe from karmaworld.utils.forms import NiceErrorModelForm # supports handling autocomplete fields as a model object or a value from karmaworld.utils.forms import ACFieldModelForm @@ -20,7 +21,6 @@ from karmaworld.utils.forms import ACFieldModelForm from karmaworld.utils.forms import DependentModelForm from karmaworld.apps.courses.models import Course -from karmaworld.apps.courses.models import School from karmaworld.apps.courses.models import Professor from karmaworld.apps.courses.models import Department @@ -80,7 +80,9 @@ class ProfessorForm(NiceErrorModelForm, ACFieldModelForm): class DepartmentForm(NiceErrorModelForm, ACFieldModelForm): """ Find and create a Department given a School. """ # first argument is ajax channel name, defined in models as LookupChannel. - school = AutoCompleteSelectField('school_object_by_name', help_text='') + school = AutoCompleteSelectField('school_object_by_name', + help_text='', + label=mark_safe('School (required)')) # first argument is ajax channel name, defined in models as LookupChannel. name = AutoCompleteDependentSelectField( 'dept_object_by_name_given_school', help_text='', @@ -113,7 +115,7 @@ class CourseForm(NiceErrorModelForm, DependentModelForm): # first argument is ajax channel name, defined in models as LookupChannel. # note this AJAX field returns a field value, not a course object. name = AutoCompleteField('course_name_by_name', help_text='', - label="Course name") + label=mark_safe('Course name (required)')) def __init__(self, *args, **kwargs): """ Add a dynamically named field. """ diff --git a/karmaworld/apps/courses/test/test_selenium.py b/karmaworld/apps/courses/test/test_selenium.py index bb7015d..326185b 100644 --- a/karmaworld/apps/courses/test/test_selenium.py +++ b/karmaworld/apps/courses/test/test_selenium.py @@ -1,3 +1,4 @@ +import time from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By @@ -14,17 +15,17 @@ class AddCourseTest(LiveServerTestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(3) - self.wait = WebDriverWait(self.driver, 10) + self.wait = WebDriverWait(self.driver, 200) self.harvard = School.objects.create(name="Harvard University", usde_id=12345) self.northeastern = School.objects.create(name="Northeastern University", usde_id=33333) def tearDown(self): self.driver.close() - def selectAutocomplete(self, name, keys, fieldIndex): + def selectAutocomplete(self, name, keys): input = self.driver.find_element_by_name(name) input.send_keys(keys) - self.wait.until(EC.element_to_be_clickable((By.XPATH, "//ul[contains(@class,'ui-autocomplete')]/li[" + str(fieldIndex) + "]"))) + self.wait.until(EC.element_to_be_clickable((By.XPATH, "//ul[contains(@style,'display: block')]/li[contains(@class,'ui-menu-item')][1]"))) input.send_keys(Keys.DOWN) autocompleteMenuItem = self.driver.find_element_by_id("ui-active-menuitem") autocompleteMenuItem.click() @@ -53,7 +54,7 @@ class AddCourseTest(LiveServerTestCase): activeItem = self.driver.find_element_by_id("ui-active-menuitem") activeItem.click() - school_name_on_deck = self.driver.find_element_by_xpath("//div[contains(@class,'results-on-deck')][1]") + school_name_on_deck = self.driver.find_element_by_xpath("//div[contains(@class,'results_on_deck')][1]") self.assertIn("Harvard University", school_name_on_deck.text) schoolId = self.driver.find_element_by_name("DepartmentForm-school") @@ -68,16 +69,21 @@ class AddCourseTest(LiveServerTestCase): self.driver.execute_script("javascript:window.scrollBy(0,200)") # Choose a school - self.selectAutocomplete("DepartmentForm-school_text", "northeastern u", 1) + self.selectAutocomplete("DepartmentForm-school_text", "northeastern u") # Course name newCourseName = "SELENIUM TEST COURSE " + uuid.uuid4().hex - courseNameInput = self.driver.find_element_by_id("id_CourseForm-name") + courseNameInput = self.driver.find_element_by_name("CourseForm-name") courseNameInput.send_keys(newCourseName) + # Department name + newDepartmentName = "SELENIUM TEST DEPARTMENT " + uuid.uuid4().hex + departmentNameInput = self.driver.find_element_by_name("DepartmentForm-name_text") + departmentNameInput.send_keys(newDepartmentName) + # Instructor name newInstructorName = "SELENIUM TEST INSTRUCTOR " + uuid.uuid4().hex - instructorNameInput = self.driver.find_element_by_id("id_ProfessorForm-name_text") + instructorNameInput = self.driver.find_element_by_name("ProfessorForm-name_text") instructorNameInput.send_keys(newInstructorName) # Click "Save" @@ -97,16 +103,21 @@ class AddCourseTest(LiveServerTestCase): self.driver.execute_script("javascript:window.scrollBy(0,200)") # Choose a school - self.selectAutocomplete("DepartmentForm-school_text", "northeastern u", 1) + self.selectAutocomplete("DepartmentForm-school_text", "northeastern u") # Course name newCourseName = "SELENIUM TEST COURSE " + uuid.uuid4().hex - courseNameInput = self.driver.find_element_by_id("id_CourseForm-name") + courseNameInput = self.driver.find_element_by_name("CourseForm-name") courseNameInput.send_keys(newCourseName) + # Department name + newDepartmentName = "SELENIUM TEST DEPARTMENT " + uuid.uuid4().hex + departmentNameInput = self.driver.find_element_by_name("DepartmentForm-name_text") + departmentNameInput.send_keys(newDepartmentName) + # Instructor name newInstructorName = "SELENIUM TEST INSTRUCTOR " + uuid.uuid4().hex - instructorNameInput = self.driver.find_element_by_id("id_ProfessorForm-name_text") + instructorNameInput = self.driver.find_element_by_name("ProfessorForm-name_text") instructorNameInput.send_keys(newInstructorName) # Click "Save" @@ -125,15 +136,26 @@ class AddCourseTest(LiveServerTestCase): self.driver.execute_script("javascript:window.scrollBy(0,200)") # Choose the SAME school - self.selectAutocomplete("DepartmentForm-school_text", "northeastern u", 1) + self.selectAutocomplete("DepartmentForm-school_text", "northeastern u") # The SAME course name - self.selectAutocomplete("id_CourseForm-name", newCourseName, 2) + # Choose the SAME school + self.selectAutocomplete("CourseForm-name", newCourseName) + #courseNameInput = self.driver.find_element_by_name("CourseForm-name") + #courseNameInput.send_keys(newCourseName) # The SAME instructor name - self.selectAutocomplete("id_ProfessorForm-name_text", newInstructorName, 3) + self.selectAutocomplete("ProfessorForm-name_text", newInstructorName) + # The SAME department name + self.selectAutocomplete("DepartmentForm-name_text", newDepartmentName) + #instructorNameInput = self.driver.find_element_by_name("ProfessorForm-name_text") + #instructorNameInput.send_keys(newInstructorName) + + saveButton = self.driver.find_element_by_id("save-btn") saveButton.click() + self.assertEqual(Course.objects.count(), 1, "Duplicated course not created") + diff --git a/karmaworld/templates/partial/add_course.html b/karmaworld/templates/partial/add_course.html index 0e25826..fd8c7aa 100644 --- a/karmaworld/templates/partial/add_course.html +++ b/karmaworld/templates/partial/add_course.html @@ -14,25 +14,22 @@ {% csrf_token %} {% if course_form.non_field_errors %} -
-
-
    {% for error in course_form.non_field_errors %} -
  • - {% endfor %}
+
+
+
    {% for error in course_form.non_field_errors %} +
  • + {% endfor %}
+
-
- {% endif %} - {{ course_form.as_p }} + + {{ course_form.as_p|safe }}
- - Looks like this course already exists on KarmaNotes! - Go To Existing Course
-- 2.25.1