summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authorTulio Casagrande <tuliocasagrande@gmail.com>2017-02-20 14:43:10 -0300
committerGitHub <noreply@github.com>2017-02-20 14:43:10 -0300
commit5a61fe569d469629922d3425cb580086d1d65433 (patch)
treed58745a528422f90bb53f59b8078bd1dde2bddba /service/test
parent48a1ca5f8310ef6fb61dc821c38d435617b19d5c (diff)
parent8177127b6b7282f816cb64595249ef1cb42ec0d8 (diff)
Merge pull request #980 from pixelated/interstitial-errors
[#907] Convert login page to react
Diffstat (limited to 'service/test')
-rw-r--r--service/test/functional/features/environment.py2
-rw-r--r--service/test/functional/features/steps/attachments.py10
-rw-r--r--service/test/functional/features/steps/common.py2
-rw-r--r--service/test/functional/features/steps/tag_list.py21
-rw-r--r--service/test/unit/resources/test_helpers.py7
-rw-r--r--service/test/unit/resources/test_login_resource.py53
6 files changed, 61 insertions, 34 deletions
diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py
index d49016b6..821a762b 100644
--- a/service/test/functional/features/environment.py
+++ b/service/test/functional/features/environment.py
@@ -63,7 +63,7 @@ def before_all(context):
def _setup_webdriver(context):
- browser = context.config.userdata.get('webdriver', 'phantomjs')
+ browser = context.config.userdata.get('webdriver', 'chrome')
supported_webdrivers = {
'phantomjs': webdriver.PhantomJS,
'firefox': webdriver.Firefox,
diff --git a/service/test/functional/features/steps/attachments.py b/service/test/functional/features/steps/attachments.py
index 8852b787..37fabb6a 100644
--- a/service/test/functional/features/steps/attachments.py
+++ b/service/test/functional/features/steps/attachments.py
@@ -13,6 +13,8 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+import os
+
from email.MIMEMultipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
@@ -67,8 +69,10 @@ def find_icon(context):
def upload_big_file(context):
base_dir = "test/functional/features/files/"
fname = "over_5mb.data"
+ path = os.path.abspath(os.path.join(base_dir, fname))
+
context.browser.execute_script("$('#fileupload').removeAttr('hidden');")
- fill_by_css_selector(context, '#fileupload', base_dir + fname)
+ fill_by_css_selector(context, '#fileupload', path)
find_element_by_css_selector(context, '#upload-error-message')
@@ -97,7 +101,9 @@ def should_not_show_upload_error_message(context):
def upload_attachment(context):
base_dir = "test/functional/features/files/"
fname = "5mb.data"
- fill_by_css_selector(context, '#fileupload', base_dir + fname)
+ path = os.path.abspath(os.path.join(base_dir, fname))
+
+ fill_by_css_selector(context, '#fileupload', path)
attachment_list_item = find_element_by_css_selector(context, '#attachment-list-item li a')
assert attachment_list_item.text == "%s (5.00 Mb)" % fname
diff --git a/service/test/functional/features/steps/common.py b/service/test/functional/features/steps/common.py
index edfe2a50..3e1e995e 100644
--- a/service/test/functional/features/steps/common.py
+++ b/service/test/functional/features/steps/common.py
@@ -61,7 +61,7 @@ def _wait_until_elements_are_visible_by_locator(context, locator_tuple, timeout=
def _wait_until_element_is_visible_by_locator(context, locator_tuple, timeout=TIMEOUT_IN_S):
wait = WebDriverWait(context.browser, timeout)
- wait.until(EC.presence_of_element_located(locator_tuple))
+ wait.until(EC.visibility_of_element_located(locator_tuple))
return context.browser.find_element(locator_tuple[0], locator_tuple[1])
diff --git a/service/test/functional/features/steps/tag_list.py b/service/test/functional/features/steps/tag_list.py
index daea416d..e3382a61 100644
--- a/service/test/functional/features/steps/tag_list.py
+++ b/service/test/functional/features/steps/tag_list.py
@@ -14,11 +14,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from behave import when
-from selenium.common.exceptions import TimeoutException
+from selenium.common.exceptions import TimeoutException, StaleElementReferenceException
from common import (
find_element_by_class_name,
- find_element_by_id,
find_element_by_css_selector,
wait_for_user_alert_to_disapear)
@@ -37,12 +36,11 @@ def expand_side_nav(context):
if is_side_nav_expanded(context):
return
- toggle = find_element_by_class_name(context, 'side-nav-toggle')
- toggle.click()
+ find_element_by_css_selector(context, '.side-nav-toggle-icon i').click()
@when('I select the tag \'{tag}\'')
-def impl(context, tag):
+def select_tag(context, tag):
wait_for_user_alert_to_disapear(context)
expand_side_nav(context)
@@ -53,23 +51,14 @@ def impl(context, tag):
try:
find_element_by_css_selector(context, '#tag-%s' % tag)
- e = find_element_by_id(context, 'tag-%s' % tag)
+ e = find_element_by_css_selector(context, '#tag-%s .tag-label' % tag)
e.click()
find_element_by_css_selector(context, ".mail-list-entry__item[href*='%s']" % tag)
success = True
- except TimeoutException:
+ except (TimeoutException, StaleElementReferenceException):
pass
finally:
try_again -= 1
assert success
-
-
-@when('I am in \'{tag}\'')
-def impl(context, tag):
- expand_side_nav(context)
-
- find_element_by_css_selector(context, '#tag-%s' % tag)
- e = find_element_by_id(context, 'tag-%s' % tag)
- assert "selected" in e.get_attribute("class")
diff --git a/service/test/unit/resources/test_helpers.py b/service/test/unit/resources/test_helpers.py
index e21c5373..6c456f51 100644
--- a/service/test/unit/resources/test_helpers.py
+++ b/service/test/unit/resources/test_helpers.py
@@ -18,6 +18,7 @@ from twisted.trial import unittest
import re
from pixelated.resources import respond_json, respond_json_deferred
+from pixelated.resources import get_public_static_folder, get_protected_static_folder
from test.unit.resources import DummySite
from twisted.web.test.requesthelper import DummyRequest
@@ -44,3 +45,9 @@ class TestHelpers(unittest.TestCase):
self.assertEqual(b"{\"test\": \"yep\"}", request.written[0])
self.assertEqual([b"application/json"],
request.responseHeaders.getRawHeaders("Content-Type"))
+
+ def test_getting_public_folder_returns_path(self):
+ self.assertIn('web-ui/dist/public', get_public_static_folder())
+
+ def test_getting_protected_folder_returns_path(self):
+ self.assertIn('web-ui/dist/protected', get_protected_static_folder())
diff --git a/service/test/unit/resources/test_login_resource.py b/service/test/unit/resources/test_login_resource.py
index 834b9710..bd0f9122 100644
--- a/service/test/unit/resources/test_login_resource.py
+++ b/service/test/unit/resources/test_login_resource.py
@@ -23,7 +23,7 @@ from twisted.internet import defer
from twisted.trial import unittest
from twisted.web.test.requesthelper import DummyRequest
-from pixelated.resources.login_resource import LoginResource
+from pixelated.resources.login_resource import LoginResource, LoginStatusResource
from pixelated.resources.login_resource import parse_accept_language
from test.unit.resources import DummySite
@@ -87,23 +87,15 @@ class TestLoginResource(unittest.TestCase):
d = self.web.get(request)
- def assert_form_rendered(_):
+ def assert_login_page_rendered(_):
self.assertEqual(200, request.responseCode)
- form_action = 'action="/login"'
- form_method = 'method="post"'
- input_username = 'name="username"'
- input_password = 'name="password"'
- input_submit = 'name="login"'
+ title = 'Pixelated - Login'
default_disclaimer = 'Some disclaimer'
written_response = ''.join(request.written)
- self.assertIn(form_action, written_response)
- self.assertIn(form_method, written_response)
- self.assertIn(input_password, written_response)
- self.assertIn(input_submit, written_response)
- self.assertIn(input_username, written_response)
+ self.assertIn(title, written_response)
self.assertIn(default_disclaimer, written_response)
- d.addCallback(assert_form_rendered)
+ d.addCallback(assert_login_page_rendered)
return d
def _write(self, filename, content):
@@ -238,7 +230,7 @@ class TestLoginPOST(unittest.TestCase):
def assert_interstitial_in_response(_):
mock_authenticate.assert_called_once_with(self.username, self.password)
- interstitial_js_in_template = '<script src="startup-assets/Interstitial.js"></script>'
+ interstitial_js_in_template = '<script src="/public/interstitial.js"></script>'
self.assertIn(interstitial_js_in_template, self.request.written[0])
d.addCallback(assert_interstitial_in_response)
@@ -314,3 +306,36 @@ class TestLoginPOST(unittest.TestCase):
d.addCallback(assert_login_error_called)
return d
+
+
+class TestLoginStatus(unittest.TestCase):
+ def setUp(self):
+ self.services_factory = mock()
+ self.resource = LoginStatusResource(self.services_factory)
+ self.web = DummySite(self.resource)
+
+ self.request = DummyRequest(['/status'])
+
+ def test_login_status_completed_when_single_user(self):
+ self.services_factory.mode = mock()
+ self.services_factory.mode.is_single_user = True
+ d = self.web.get(self.request)
+
+ def assert_login_completed(_):
+ self.assertIn('completed', self.request.written[0])
+
+ d.addCallback(assert_login_completed)
+ return d
+
+ @patch('pixelated.resources.session.PixelatedSession.check_login_status')
+ def test_login_status_when_multi_user_returns_check_login_status(self, mock_login_status):
+ self.services_factory.mode = mock()
+ self.services_factory.mode.is_single_user = False
+ mock_login_status.return_value = 'started'
+ d = self.web.get(self.request)
+
+ def assert_login_completed(_):
+ self.assertIn('started', self.request.written[0])
+
+ d.addCallback(assert_login_completed)
+ return d