Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rcamp/rcamp/projects/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from accounts.models import (
User,
AccountRequest
AccountRequest,
Intent
)
from projects.models import Project

Expand Down
22 changes: 22 additions & 0 deletions rcamp/rcamp/tests/test_projects_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,25 @@ def test_check_general_eligibility_suffixed(self):

project = Project.objects.get()
self.assertIn(auth_user,project.collaborators.all())

def test_check_general_eligibility_no_intent(self):
user_defaults = get_ldap_user_defaults()

auth_user_defaults = dict(
username=user_defaults['username'],
first_name=user_defaults['first_name'],
last_name=user_defaults['last_name'],
email=user_defaults['email']
)
auth_user = User.objects.create(**auth_user_defaults)

account_request_defaults = dict(
username=auth_user.username,
first_name=auth_user.first_name,
last_name=auth_user.last_name,
email=auth_user.email,
organization='ucb'
)
account_request = AccountRequest.objects.create(**account_request_defaults)

check_general_eligibility(account_request.__class__,account_request=account_request)
41 changes: 27 additions & 14 deletions rcamp/rcamp/tests/utilities/functional.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.conf import settings
from selenium import webdriver
from selenium.common import exceptions
import datetime
import unittest
import copy
Expand All @@ -18,6 +19,27 @@
)


class PhantomJSWithRetry(webdriver.PhantomJS):
"""
Pulled from https://github.com/chris48s/UK-Polling-Stations/blob/66e96b52ce6bb6e9c0d864a8eb7e9bd53192f8b8/polling_stations/apps/data_finder/features/index.py
to get around https://github.com/ariya/phantomjs/issues/11526#issuecomment-133570834
and https://github.com/travis-ci/travis-ci/issues/3251.

Override execute() so it will retry if we get a selenium.common.exceptions.TimeoutException
this is a hack to work around an underlying issue in selenium and phantomjs running within a
Docker container.
"""
def execute(self, driver_command, params=None):
for _ in range(3):
try:
return super(PhantomJSWithRetry,self).execute(driver_command, params)
except exceptions.TimeoutException as e:
print('trying again...')
error = e
print('giving up! :(')
raise error


@unittest.skipUnless(_assert_test_env_or_false(),"Tests are not being run against a safe test environment!")
class SafeStaticLiveServerTestCase(StaticLiveServerTestCase):
"""
Expand All @@ -36,28 +58,19 @@ class SafeStaticLiveServerTestCase(StaticLiveServerTestCase):

All RCAMP functional tests should inherit from this class.
"""
@classmethod
def setUpClass(cls):
assert_test_env()
# Start the web driver
cls.browser = webdriver.PhantomJS()
cls.browser.set_window_size(1366, 768)
super(SafeStaticLiveServerTestCase,cls).setUpClass()

@classmethod
def tearDownClass(cls):
cls.browser.quit()
assert_test_env()
super(SafeStaticLiveServerTestCase,cls).tearDownClass()

def setUp(self):
assert_test_env()
self.browser = PhantomJSWithRetry()
self.browser.set_page_load_timeout(10)
self.browser.set_script_timeout(10)
self.browser.set_window_size(1366, 768)
_purge_ldap_objects()
super(SafeStaticLiveServerTestCase,self).setUp()

def tearDown(self):
assert_test_env()
_purge_ldap_objects()
self.browser.quit()
super(SafeStaticLiveServerTestCase,self).tearDown()

class UserAuthenticatedLiveServerTestCase(SafeStaticLiveServerTestCase):
Expand Down