Skip to content

Commit

Permalink
Merge pull request #514 from artoonie/upgrade-heroku-stack
Browse files Browse the repository at this point in the history
updates for new heroku stack
  • Loading branch information
artoonie authored Oct 22, 2024
2 parents 99aa8e0 + 6f68fba commit 4a9c37e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"MAGICK_CONFIGURE_PATH": "/app/infra/.magick",
"MOVIE_FONT_NAME": "AvantGarde-Book",
"IMAGEIO_FFMPEG_EXE": "/app/vendor/ffmpeg/ffmpeg",
"CHROMEDRIVER_PATH": "/app/.chrome-for-testing/chrome-linux64/chrome",

"AWS_POLLY_STORAGE_BUCKET": {
"description": "AWS bucket name for AWS Polly Speech Synth",
Expand Down Expand Up @@ -66,8 +67,7 @@
}
},
"buildpacks": [
{ "url": "heroku/chromedriver" },
{ "url": "https://github.com/artoonie/heroku-buildpack-google-chrome" },
{ "url": "heroku-community/chrome-for-testing" },
{ "url": "heroku/nodejs" },
{ "url": "heroku/python" },
{ "url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest" },
Expand Down
11 changes: 11 additions & 0 deletions common/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import json
import os
import tempfile
import uuid
from urllib.parse import urlparse
Expand All @@ -13,6 +14,7 @@
from django.contrib.auth.models import Permission

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from scraper.models import MultiScraper, Scraper
from visualizer.models import JsonConfig
from visualizer.tests import filenames
Expand Down Expand Up @@ -66,6 +68,15 @@ def get_headless_browser(cls):
""" Returns a headless browser """
chromeOptions = webdriver.chrome.options.Options()
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--no-sandbox")
chromeOptions.add_argument("--disable-dev-shm-usage")
chromeOptions.add_argument("--shm-size=512m")

if 'CHROMEDRIVER_PATH' in os.environ:
chromeOptions.add_argument("--remote-debugging-port=9222")
service = ChromeService(executable_path=os.environ["CHROMEDRIVER_PATH"])
return webdriver.Chrome(service=service, options=chromeOptions)

return webdriver.Chrome(options=chromeOptions)

# Or, Firefox
Expand Down
2 changes: 1 addition & 1 deletion infra/requirements-core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ django-sortedm2m==3.1.1
django-storages==1.13.2
Django==4.2.16
rcvformats==0.0.42
selenium==4.10.0
selenium==4.25.0
psycopg2-binary==2.9.6
pytz==2023.3
whitenoise==6.4.0
Expand Down
9 changes: 8 additions & 1 deletion movie/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.conf import settings
import requests
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService

from movie.creation.movieCreator import MovieCreationFactory
from visualizer.models import JsonConfig, MovieGenerationStatuses
Expand Down Expand Up @@ -54,8 +55,14 @@ def create_movie_task(pk, domain):
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--disable-dev-shm-usage")
chromeOptions.add_argument("--shm-size=512m")
chromeOptions.add_argument("--no-sandbox")
if 'CHROMEDRIVER_PATH' in os.environ:
chromeOptions.add_argument("--remote-debugging-port=9222")
service = ChromeService(executable_path=os.environ["CHROMEDRIVER_PATH"])
browser = webdriver.Chrome(service=service, options=chromeOptions)
else:
browser = webdriver.Chrome(options=chromeOptions)

browser = webdriver.Chrome(options=chromeOptions)
browser.implicitly_wait(10)

try:
Expand Down
21 changes: 18 additions & 3 deletions visualizer/tests/testLiveBrowserHeadless.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from mock import patch
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait

Expand Down Expand Up @@ -84,6 +85,8 @@ def _get_eliminated_color():
# Get an eliminated bar by its text
bargraph = self.browser.find_element(By.ID, 'bargraph-interactive-body')
cssSelector = "path[data-original-title=\"On Round 1, has 64 votes (16%)\"]"
WebDriverWait(self.browser, 5).until(
EC.presence_of_element_located((By.CSS_SELECTOR, cssSelector)))
lastBarInLastRoundList = bargraph.find_elements(By.CSS_SELECTOR, cssSelector)
self.assertEqual(len(lastBarInLastRoundList), 1)
lastBarInLastRound = lastBarInLastRoundList[0]
Expand All @@ -94,14 +97,22 @@ def _get_eliminated_color():
self._upload(filenames.MULTIWINNER)

gray = "rgb(204, 204, 204)"
WebDriverWait(self.browser, 5).until(
EC.visibility_of_element_located((By.ID, "barchart-tab")))
self._ensure_eventually_asserts(lambda: self.assertEqual(_get_eliminated_color(), gray))

# Change option to show a dim version of the last-round color
self._go_to_tab("settings-tab")
self.browser.find_elements(By.ID, "bargraphOptions")[0].click() # Open the dropdown

# Open the dropdown and wait for the animation to complete
self.browser.find_elements(By.ID, "bargraphOptions")[0].click()

# Select the element and submit
options = Select(self.browser.find_element(By.ID, "eliminationBarColor"))
options.select_by_index(2)
self.browser.find_elements(By.ID, "updateSettings")[0].click() # Hit submit
WebDriverWait(self.browser, 5).until(
EC.visibility_of_element_located((By.ID, "updateSettings")))
self.browser.find_elements(By.ID, "updateSettings")[0].submit()

notgray = "rgb(238, 237, 241)"
self._ensure_eventually_asserts(lambda: self.assertEqual(_get_eliminated_color(), notgray))
Expand Down Expand Up @@ -439,6 +450,8 @@ def test_sankey_hide_round_num(self):
# Check the box (the second one, which isn't hidden)
self.browser.find_elements(By.NAME, "showRoundNumbersOnSankey")[1].click()
self.browser.find_element(By.ID, "updateSettings").click() # Hit submit
WebDriverWait(self.browser, 5).until(
EC.visibility_of_element_located((By.ID, "sankey-tab")))

# Go to the bargraph, now it should be zero
self._go_to_tab("sankey-tab")
Expand Down Expand Up @@ -501,7 +514,8 @@ def click_activation_link():

# Try to login before activation: fails, and the username field is still there
login_via_upload_redirect()
self.assertEqual(len(self.browser.find_elements(By.ID, "id_username")), 1)
usernameFields = self.browser.find_elements(By.ID, "id_username")
self.assertEqual(len(usernameFields), 1)

# Assert an email was sent
self.assertEqual(len(test_mailbox.outbox), 1)
Expand All @@ -512,6 +526,7 @@ def click_activation_link():

# Now login should succeed, and upload has no username field
login_via_upload_redirect()
WebDriverWait(self.browser, 5).until(EC.staleness_of(usernameFields[0]))
self.assertEqual(len(self.browser.find_elements(By.ID, "id_username")), 0)

# And for good measure, upload a file
Expand Down

0 comments on commit 4a9c37e

Please sign in to comment.