Updated existing tests
authorCharles Connell <charles@connells.org>
Fri, 14 Mar 2014 16:04:03 +0000 (12:04 -0400)
committerCharles Connell <charles@connells.org>
Fri, 14 Mar 2014 16:04:03 +0000 (12:04 -0400)
karmaworld/apps/courses/forms.py
karmaworld/apps/courses/test/test_selenium.py
karmaworld/templates/partial/add_course.html

index fc9719458317f81f44d9c8946f75ef686d909cd0..1d24ac69212698f693da05a329ac41c3660e190b 100644 (file)
@@ -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 <span class="required-field">(required)</span>'))
     # 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 <span class="required-field">(required)</span>'))
 
     def __init__(self, *args, **kwargs):
         """ Add a dynamically named field. """
index bb7015dd9152408a33fd656e273a00239342e776..326185b3fb14030ea304700f2743e4c60e18122b 100644 (file)
@@ -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")
+
 
 
 
index 0e2582617b99c84f274c9aa38f838672962a481d..fd8c7aa640ae8da2eca7a822c3bf97dbb0be83f8 100644 (file)
   {% csrf_token %}
 
     {% if course_form.non_field_errors %}
-    <div class="row">
-      <div class="small-12 columns">
-        <ul>{% for error in course_form.non_field_errors %}
-          <li><label class="validation_error">{{ error }}</label></li>
-        {% endfor %}</ul>
+      <div class="row">
+        <div class="small-12 columns">
+          <ul>{% for error in course_form.non_field_errors %}
+            <li><label class="validation_error">{{ error }}</label></li>
+          {% endfor %}</ul>
+        </div>
       </div>
-    </div>
-
     {% endif %}
-    {{ course_form.as_p }}
+
+    {{ course_form.as_p|safe }}
 
     <div class="row">
       <div class="small-4 large-8 columns small-centered text-center">
         <button id="save-btn" type="submit">
           <i class="fa fa-save"></i> Save
         </button>
-        <span id="existing-course-msg" class="hide">
-          Looks like this course already exists on KarmaNotes!
-          <a id="existing-course-btn" class="button">Go To Existing Course <i class="fa fa-arrow-right"></i></a></span>
       </div>
     </div>