Skip to content

Commit

Permalink
Download & install geckodriver; add oneRound regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Nov 10, 2019
1 parent 006bf89 commit cb464d0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
17 changes: 15 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
dist: xenial
services:
- xvfb

env:
global:
- MOZ_HEADLESS=1

git:
depth: 3

Expand All @@ -10,14 +18,19 @@ python:
- '3.6'

addons:
firefox: "latest"
firefox: "71.0"

before_install:
- wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
- mkdir geckodriver
- tar -xzf geckodriver-v0.26.0-linux64.tar.gz
- sudo mv geckodriver /usr/local/bin/

install:
- virtualenv venv
- source venv/bin/activate
- pip3 install -e .
- pip3 install -r requirements.txt
- sudo apt-get install geckodriver

script:
- python3 manage.py test
Expand Down
20 changes: 20 additions & 0 deletions testData/oneRound.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"config" : {
"contest" : "One round",
"date" : "2019-11-05",
"jurisdiction" : "Sample Data",
"office" : "Council",
"threshold" : "134"
},
"results" : [ {
"round" : 1,
"tally" : {
"Did Not Win" : "500",
"Won" : "501"
},
"tallyResults" : [ {
"elected" : "Won"
} ]
}
]
}
42 changes: 29 additions & 13 deletions visualizer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
FILENAME_MULTIWINNER = 'testData/macomb-multiwinner-surplus.json'
FILENAME_OPAVOTE = 'testData/opavote-fairvote.json'
FILENAME_BAD_DATA = 'testData/test-baddata.json'
FILENAME_ONE_ROUND = 'testData/oneRound.json'

class SimpleTests(TestCase):
def _get_data_for_view(self, fn):
Expand Down Expand Up @@ -70,7 +71,7 @@ class LiveBrowserTests(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.browser = Firefox(executable_path='/usr/local/bin/geckodriver')
cls.browser = Firefox()
cls.browser.implicitly_wait(10)

@classmethod
Expand All @@ -81,35 +82,50 @@ def tearDownClass(cls):
def open(self, url):
self.browser.get("%s%s" % (self.live_server_url, url))

def test_render(self):
def _upload(self, fn):
self.open('/upload.html')

fileUpload = self.browser.find_element_by_id("uploadFileInput")
fileUpload.send_keys(os.path.join(os.getcwd(), FILENAME_MULTIWINNER))
fileUpload.send_keys(os.path.join(os.getcwd(), fn))
uploadButton = self.browser.find_element_by_id("uploadButton")
uploadButton.click()

def getWidth(elementId):
return self.browser.find_elements_by_id(elementId)[0].size['width']
def _getWidth(self, elementId):
return self.browser.find_elements_by_id(elementId)[0].size['width']

def _getHeight(self, elementId):
return self.browser.find_elements_by_id(elementId)[0].size['height']

def assertWidth(elementId, width):
assert getWidth(elementId) == width

def test_render(self):
def fits_inside(element_width, page_width):
# Checks that the element takes up most or all of the page, but not more
PERCENT_ROOM_FOR_MARGINS = 0.1
min_width = page_width * (1-PERCENT_ROOM_FOR_MARGINS)
return element_width <= page_width and \
element_width > min_width

def testSaneResizingOf(elementId, maxSize):
self.browser.set_window_size(200,600)
assert getWidth(elementId) > 200 # don't make too small
assert self._getWidth(elementId) > 200 # don't make too small

self.browser.set_window_size(400,600)
assert getWidth(elementId) == 400 # should fit!
assert fits_inside(self._getWidth(elementId), 400)

self.browser.set_window_size(600,600)
assert getWidth(elementId) == 600 # should fit!
assert fits_inside(self._getWidth(elementId), 600)

self.browser.set_window_size(maxSize,600)
assert getWidth(elementId) < maxSize # don't make too big
assert self._getWidth(elementId) < maxSize # don't make too big

self._upload(FILENAME_MULTIWINNER)
testSaneResizingOf("bargraph-interactive-body", 1200)

assert getWidth("sankey-body") == 0 # not yet visible
assert self._getWidth("sankey-body") == 0 # not yet visible
self.browser.find_elements_by_id("sankey-tab")[0].click()
testSaneResizingOf("sankey-body", 3000) # sankey doesn't currently have an upper limit, though it should. Unit-driven testing? Fix this.

def test_oneround(self):
# Regression test
self.browser.set_window_size(800,800)
self._upload(FILENAME_ONE_ROUND)
assert self._getHeight("bargraph-interactive-body") < 800

0 comments on commit cb464d0

Please sign in to comment.