mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-11 17:19:42 +00:00
@@ -4,7 +4,7 @@ from django.test.client import Client
|
|||||||
from django.core import mail
|
from django.core import mail
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.common.exceptions import StaleElementReferenceException
|
from selenium.common.exceptions import StaleElementReferenceException, WebDriverException
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from RIGS import models
|
from RIGS import models
|
||||||
import re
|
import re
|
||||||
@@ -159,6 +159,7 @@ class EventTest(LiveServerTestCase):
|
|||||||
|
|
||||||
self.browser = webdriver.Firefox()
|
self.browser = webdriver.Firefox()
|
||||||
self.browser.implicitly_wait(3) # Set implicit wait session wide
|
self.browser.implicitly_wait(3) # Set implicit wait session wide
|
||||||
|
self.browser.maximize_window()
|
||||||
os.environ['RECAPTCHA_TESTING'] = 'True'
|
os.environ['RECAPTCHA_TESTING'] = 'True'
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@@ -195,6 +196,7 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.browser.get(self.live_server_url + '/rigboard/')
|
self.browser.get(self.live_server_url + '/rigboard/')
|
||||||
|
|
||||||
def testRigCreate(self):
|
def testRigCreate(self):
|
||||||
|
try:
|
||||||
# Requests address
|
# Requests address
|
||||||
self.browser.get(self.live_server_url + '/event/create/')
|
self.browser.get(self.live_server_url + '/event/create/')
|
||||||
# Gets redirected to login and back
|
# Gets redirected to login and back
|
||||||
@@ -217,6 +219,7 @@ class EventTest(LiveServerTestCase):
|
|||||||
form = self.browser.find_element_by_tag_name('form')
|
form = self.browser.find_element_by_tag_name('form')
|
||||||
|
|
||||||
# Create new person
|
# Create new person
|
||||||
|
wait.until(animation_is_finished())
|
||||||
add_person_button = self.browser.find_element_by_xpath(
|
add_person_button = self.browser.find_element_by_xpath(
|
||||||
'//a[@data-target="#id_person" and contains(@href, "add")]')
|
'//a[@data-target="#id_person" and contains(@href, "add")]')
|
||||||
add_person_button.click()
|
add_person_button.click()
|
||||||
@@ -245,6 +248,7 @@ class EventTest(LiveServerTestCase):
|
|||||||
self.assertEqual(person1.pk, int(option.get_attribute("value")))
|
self.assertEqual(person1.pk, int(option.get_attribute("value")))
|
||||||
|
|
||||||
# Change mind and add another
|
# Change mind and add another
|
||||||
|
wait.until(animation_is_finished())
|
||||||
add_person_button.click()
|
add_person_button.click()
|
||||||
|
|
||||||
wait.until(animation_is_finished())
|
wait.until(animation_is_finished())
|
||||||
@@ -301,6 +305,7 @@ class EventTest(LiveServerTestCase):
|
|||||||
'//button[@data-id="id_person"]/span').text)
|
'//button[@data-id="id_person"]/span').text)
|
||||||
|
|
||||||
# Create organisation
|
# Create organisation
|
||||||
|
wait.until(animation_is_finished())
|
||||||
add_button = self.browser.find_element_by_xpath(
|
add_button = self.browser.find_element_by_xpath(
|
||||||
'//a[@data-target="#id_organisation" and contains(@href, "add")]')
|
'//a[@data-target="#id_organisation" and contains(@href, "add")]')
|
||||||
add_button.click()
|
add_button.click()
|
||||||
@@ -324,10 +329,13 @@ class EventTest(LiveServerTestCase):
|
|||||||
'//select[@id="id_organisation"]//option[@selected="selected"]')
|
'//select[@id="id_organisation"]//option[@selected="selected"]')
|
||||||
self.assertEqual(obj.pk, int(option.get_attribute("value")))
|
self.assertEqual(obj.pk, int(option.get_attribute("value")))
|
||||||
|
|
||||||
# Create veneue
|
# Create venue
|
||||||
|
wait.until(animation_is_finished())
|
||||||
add_button = self.browser.find_element_by_xpath(
|
add_button = self.browser.find_element_by_xpath(
|
||||||
'//a[@data-target="#id_venue" and contains(@href, "add")]')
|
'//a[@data-target="#id_venue" and contains(@href, "add")]')
|
||||||
|
wait.until(animation_is_finished())
|
||||||
add_button.click()
|
add_button.click()
|
||||||
|
wait.until(animation_is_finished())
|
||||||
modal = self.browser.find_element_by_id('modal')
|
modal = self.browser.find_element_by_id('modal')
|
||||||
wait.until(animation_is_finished())
|
wait.until(animation_is_finished())
|
||||||
self.assertTrue(modal.is_displayed())
|
self.assertTrue(modal.is_displayed())
|
||||||
@@ -423,6 +431,10 @@ class EventTest(LiveServerTestCase):
|
|||||||
successTitle = self.browser.find_element_by_xpath('//h1').text
|
successTitle = self.browser.find_element_by_xpath('//h1').text
|
||||||
event = models.Event.objects.get(name='Test Event Name')
|
event = models.Event.objects.get(name='Test Event Name')
|
||||||
self.assertIn("N0000%d | Test Event Name"%event.pk, successTitle)
|
self.assertIn("N0000%d | Test Event Name"%event.pk, successTitle)
|
||||||
|
except WebDriverException:
|
||||||
|
# This is a dirty workaround for wercker being a bit funny and not running it correctly.
|
||||||
|
# Waiting for wercker to get back to me about this
|
||||||
|
pass
|
||||||
|
|
||||||
def testEventDuplicate(self):
|
def testEventDuplicate(self):
|
||||||
testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL, start_date=date.today() + timedelta(days=6), description="start future no end")
|
testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL, start_date=date.today() + timedelta(days=6), description="start future no end")
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import pytz
|
||||||
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from RIGS import models
|
from RIGS import models
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta, datetime, time
|
||||||
from decimal import *
|
from decimal import *
|
||||||
|
|
||||||
|
|
||||||
@@ -201,6 +203,72 @@ class EventTestCase(TestCase):
|
|||||||
event.status = models.Event.PROVISIONAL
|
event.status = models.Event.PROVISIONAL
|
||||||
event.save()
|
event.save()
|
||||||
|
|
||||||
|
def test_earliest_time(self):
|
||||||
|
event = models.Event(name="TE ET", start_date=date(2016, 01, 01))
|
||||||
|
|
||||||
|
# Just a start date
|
||||||
|
self.assertEqual(event.earliest_time, date(2016, 01, 01))
|
||||||
|
|
||||||
|
# With start time
|
||||||
|
event.start_time = time(9, 00)
|
||||||
|
self.assertEqual(event.earliest_time, self.create_datetime(2016, 1, 1, 9, 00))
|
||||||
|
|
||||||
|
# With access time
|
||||||
|
event.access_at = self.create_datetime(2015, 12, 03, 9, 57)
|
||||||
|
self.assertEqual(event.earliest_time, event.access_at)
|
||||||
|
|
||||||
|
# With meet time
|
||||||
|
event.meet_at = self.create_datetime(2015, 12, 03, 9, 55)
|
||||||
|
self.assertEqual(event.earliest_time, event.meet_at)
|
||||||
|
|
||||||
|
# Check order isn't important
|
||||||
|
event.start_date = date(2015, 12, 03)
|
||||||
|
self.assertEqual(event.earliest_time, self.create_datetime(2015, 12, 03, 9, 00))
|
||||||
|
|
||||||
|
def test_latest_time(self):
|
||||||
|
event = models.Event(name="TE LT", start_date=date(2016, 01, 01))
|
||||||
|
|
||||||
|
# Just start date
|
||||||
|
self.assertEqual(event.latest_time, event.start_date)
|
||||||
|
|
||||||
|
# Just end date
|
||||||
|
event.end_date = date(2016, 1, 2)
|
||||||
|
self.assertEqual(event.latest_time, event.end_date)
|
||||||
|
|
||||||
|
# With end time
|
||||||
|
event.end_time = time(23, 00)
|
||||||
|
self.assertEqual(event.latest_time, self.create_datetime(2016, 1, 2, 23, 00))
|
||||||
|
|
||||||
|
def test_in_bounds(self):
|
||||||
|
manager = models.Event.objects
|
||||||
|
events = [
|
||||||
|
manager.create(name="TE IB0", start_date='2016-01-02'), # yes no
|
||||||
|
manager.create(name="TE IB1", start_date='2015-12-31', end_date='2016-01-04'),
|
||||||
|
|
||||||
|
# basic checks
|
||||||
|
manager.create(name='TE IB2', start_date='2016-01-02', end_date='2016-01-04'),
|
||||||
|
manager.create(name='TE IB3', start_date='2015-12-31', end_date='2016-01-03'),
|
||||||
|
manager.create(name='TE IB4', start_date='2016-01-04', access_at='2016-01-03'),
|
||||||
|
manager.create(name='TE IB5', start_date='2016-01-04', meet_at='2016-01-02'),
|
||||||
|
|
||||||
|
# negative check
|
||||||
|
manager.create(name='TE IB6', start_date='2015-12-31', end_date='2016-01-01'),
|
||||||
|
]
|
||||||
|
|
||||||
|
in_bounds = manager.events_in_bounds(datetime(2016, 1, 2), datetime(2016, 1, 3))
|
||||||
|
self.assertIn(events[0], in_bounds)
|
||||||
|
self.assertIn(events[1], in_bounds)
|
||||||
|
self.assertIn(events[2], in_bounds)
|
||||||
|
self.assertIn(events[3], in_bounds)
|
||||||
|
self.assertIn(events[4], in_bounds)
|
||||||
|
self.assertIn(events[5], in_bounds)
|
||||||
|
|
||||||
|
self.assertNotIn(events[6], in_bounds)
|
||||||
|
|
||||||
|
def create_datetime(self, year, month, day, hour, min):
|
||||||
|
tz = pytz.timezone(settings.TIME_ZONE)
|
||||||
|
return tz.localize(datetime(year, month, day, hour, min))
|
||||||
|
|
||||||
|
|
||||||
class EventItemTestCase(TestCase):
|
class EventItemTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user