diff --git a/rcamp/rcamp/projects/receivers.py b/rcamp/rcamp/projects/receivers.py index 9009bf4..3268c5a 100644 --- a/rcamp/rcamp/projects/receivers.py +++ b/rcamp/rcamp/projects/receivers.py @@ -5,7 +5,8 @@ from accounts.models import ( User, - AccountRequest + AccountRequest, + Intent ) from projects.models import Project diff --git a/rcamp/rcamp/tests/test_projects_receivers.py b/rcamp/rcamp/tests/test_projects_receivers.py index d41a589..dc07320 100644 --- a/rcamp/rcamp/tests/test_projects_receivers.py +++ b/rcamp/rcamp/tests/test_projects_receivers.py @@ -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) diff --git a/rcamp/rcamp/tests/utilities/functional.py b/rcamp/rcamp/tests/utilities/functional.py index 22af37e..14669d9 100644 --- a/rcamp/rcamp/tests/utilities/functional.py +++ b/rcamp/rcamp/tests/utilities/functional.py @@ -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 @@ -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): """ @@ -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):