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
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
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='',
# 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. """
+import time
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
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()
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")
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"
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"
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")
+