forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_js.py
More file actions
182 lines (148 loc) · 7.36 KB
/
Copy pathtests_js.py
File metadata and controls
182 lines (148 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Copyright The IETF Trust 2014-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import sys
import time
from pyquery import PyQuery
from unittest import skipIf
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.urls import reverse as urlreverse
#from django.test.utils import override_settings
import debug # pyflakes:ignore
from ietf.doc.factories import DocumentFactory
from ietf.group import colors
from ietf.meeting.factories import SessionFactory
from ietf.meeting.test_data import make_meeting_test_data
from ietf.meeting.models import SchedTimeSessAssignment
from ietf.name.models import SessionStatusName
from ietf.utils.test_runner import set_coverage_checking
from ietf.utils.pipe import pipe
from ietf import settings
skip_selenium = getattr(settings,'SKIP_SELENIUM',None)
skip_message = ""
if skip_selenium:
skip_message = "settings.SKIP_SELENIUM = %s" % skip_selenium
else:
try:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
except ImportError as e:
skip_selenium = True
skip_message = "Skipping selenium tests: %s" % e
code, out, err = pipe('phantomjs -v')
if not code == 0:
skip_selenium = True
skip_message = "Skipping selenium tests: 'phantomjs' executable not found."
if skip_selenium:
sys.stderr.write(" "+skip_message+'\n')
def condition_data():
make_meeting_test_data()
colors.fg_group_colors['FARFUT'] = 'blue'
colors.bg_group_colors['FARFUT'] = 'white'
@skipIf(skip_selenium, skip_message)
class ScheduleEditTests(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
set_coverage_checking(False)
super(ScheduleEditTests, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(ScheduleEditTests, cls).tearDownClass()
set_coverage_checking(True)
def setUp(self):
self.driver = webdriver.PhantomJS(port=0, service_log_path=settings.TEST_GHOSTDRIVER_LOG_PATH)
self.driver.set_window_size(1024,768)
condition_data()
def tearDown(self):
self.driver.close()
def debugSnapshot(self,filename='debug_this.png'):
self.driver.execute_script("document.body.bgColor = 'white';")
self.driver.save_screenshot(filename)
def absreverse(self,*args,**kwargs):
return '%s%s'%(self.live_server_url,urlreverse(*args,**kwargs))
def login(self):
url = '%s%s'%(self.live_server_url, urlreverse('ietf.ietfauth.views.login'))
self.driver.get(url)
self.driver.find_element_by_name('username').send_keys('plain')
self.driver.find_element_by_name('password').send_keys('plain+password')
self.driver.find_element_by_xpath('//button[@type="submit"]').click()
def testUnschedule(self):
self.assertEqual(SchedTimeSessAssignment.objects.filter(session__meeting__number=72,session__group__acronym='mars',schedule__name='test-schedule').count(),1)
self.login()
url = self.absreverse('ietf.meeting.views.edit_schedule',kwargs=dict(num='72',name='test-schedule',owner='plain@example.com'))
self.driver.get(url)
q = PyQuery(self.driver.page_source)
self.assertEqual(len(q('#sortable-list #session_1')),0)
element = self.driver.find_element_by_id('session_1')
target = self.driver.find_element_by_id('sortable-list')
ActionChains(self.driver).drag_and_drop(element,target).perform()
q = PyQuery(self.driver.page_source)
self.assertTrue(len(q('#sortable-list #session_1'))>0)
time.sleep(0.1) # The API that modifies the database runs async
self.assertEqual(SchedTimeSessAssignment.objects.filter(session__meeting__number=72,session__group__acronym='mars',schedule__name='test-schedule').count(),0)
@skipIf(skip_selenium, skip_message)
class SlideReorderTests(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
set_coverage_checking(False)
super(SlideReorderTests, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(SlideReorderTests, cls).tearDownClass()
set_coverage_checking(True)
def setUp(self):
self.driver = webdriver.PhantomJS(port=0, service_log_path=settings.TEST_GHOSTDRIVER_LOG_PATH)
self.driver.set_window_size(1024,768)
# this is a temporary fix - we should have these name in the
# database already at this point
SessionStatusName.objects.get_or_create(slug='schedw')
SessionStatusName.objects.get_or_create(slug='sched')
self.session = SessionFactory(meeting__type_id='ietf', status_id='sched')
self.session.sessionpresentation_set.create(document=DocumentFactory(type_id='slides',name='one'),order=1)
self.session.sessionpresentation_set.create(document=DocumentFactory(type_id='slides',name='two'),order=2)
self.session.sessionpresentation_set.create(document=DocumentFactory(type_id='slides',name='three'),order=3)
def tearDown(self):
self.driver.close()
def absreverse(self,*args,**kwargs):
return '%s%s'%(self.live_server_url,urlreverse(*args,**kwargs))
def secr_login(self):
url = '%s%s'%(self.live_server_url, urlreverse('ietf.ietfauth.views.login'))
self.driver.get(url)
self.driver.find_element_by_name('username').send_keys('secretary')
self.driver.find_element_by_name('password').send_keys('secretary+password')
self.driver.find_element_by_xpath('//button[@type="submit"]').click()
#@override_settings(DEBUG=True)
def testReorderSlides(self):
return
url = self.absreverse('ietf.meeting.views.session_details',
kwargs=dict(
num=self.session.meeting.number,
acronym = self.session.group.acronym,))
self.secr_login()
self.driver.get(url)
#debug.show('unicode(self.driver.page_source)')
second = self.driver.find_element_by_css_selector('#slides tr:nth-child(2)')
third = self.driver.find_element_by_css_selector('#slides tr:nth-child(3)')
ActionChains(self.driver).drag_and_drop(second,third).perform()
time.sleep(0.1) # The API that modifies the database runs async
names=self.session.sessionpresentation_set.values_list('document__name',flat=True)
self.assertEqual(list(names),['one','three','two'])
# The following are useful debugging tools
# If you add this to a LiveServerTestCase and run just this test, you can browse
# to the test server with the data loaded by setUp() to debug why, for instance,
# a particular view isn't giving you what you expect
# def testJustSitThere(self):
# time.sleep(10000)
# The LiveServerTestCase server runs in a mode like production - it hides crashes with the
# user-friendly message about mail being sent to the maintainers, and eats that mail.
# Loading the page that crashed with just a TestCase will at least let you see the
# traceback.
#
#from ietf.utils.test_utils import TestCase
#class LookAtCrashTest(TestCase):
# def setUp(self):
# condition_data()
#
# def testOpenSchedule(self):
# url = urlreverse('ietf.meeting.views.edit_schedule', kwargs=dict(num='72',name='test-schedule'))
# r = self.client.get(url)