summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authorDuda Dornelles <dudassdornelles@gmail.com>2015-01-27 16:08:03 -0200
committerPixpoa pairing <pixpoapairing@pixelated-project.org>2015-01-27 16:08:03 -0200
commit26b85d8e523f2b6aafbe18132efcd617ae892228 (patch)
tree0dbdf0cef276aef577d028391543e3f3c5354160 /service/test
parent4713741e6cbd9ad7fe20925120f6e25bc6b538e7 (diff)
#237 #232 #196 syncing user data once before starting the UA. Displaying a loading screen in the meantime. The initial sync will make sure the user has a single key pair
Diffstat (limited to 'service/test')
-rw-r--r--service/test/functional/features/environment.py4
-rw-r--r--service/test/support/integration/app_test_client.py3
-rw-r--r--service/test/unit/config/test_app_factory.py13
-rw-r--r--service/test/unit/config/test_dispatcher.py59
-rw-r--r--service/test/unit/test_runserver.py88
5 files changed, 72 insertions, 95 deletions
diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py
index 5e93c840..d78083d0 100644
--- a/service/test/functional/features/environment.py
+++ b/service/test/functional/features/environment.py
@@ -38,8 +38,8 @@ def after_all(context):
def before_feature(context, feature):
- # context.browser = webdriver.Firefox()
- context.browser = webdriver.PhantomJS()
+ context.browser = webdriver.Firefox()
+ # context.browser = webdriver.PhantomJS()
context.browser.set_window_size(1280, 1024)
context.browser.implicitly_wait(5)
context.browser.set_page_load_timeout(60) # wait for data
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index e8f79d2b..fba9ba9c 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -27,6 +27,7 @@ from pixelated.adapter.services.mail_service import MailService
from pixelated.adapter.services.mailboxes import Mailboxes
from pixelated.adapter.soledad.soledad_querier import SoledadQuerier
from pixelated.adapter.services.tag_service import TagService
+from pixelated.config import App
from pixelated.resources.root_resource import RootResource
import pixelated.runserver
from pixelated.adapter.model.mail import PixelatedMail
@@ -53,7 +54,7 @@ class AppTestClient:
SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
- self.app = pixelated.runserver.app
+ self.app = App()
self.soledad_querier = SoledadQuerier(self.soledad)
self.soledad_querier.get_index_masterkey = lambda: self.INDEX_KEY
diff --git a/service/test/unit/config/test_app_factory.py b/service/test/unit/config/test_app_factory.py
index a42c7c83..b09ffd4c 100644
--- a/service/test/unit/config/test_app_factory.py
+++ b/service/test/unit/config/test_app_factory.py
@@ -13,20 +13,25 @@ class AppFactoryTest(unittest.TestCase):
self.host = host
self.sslkey = sslkey
self.sslcert = sslcert
+ self.home = 'leap_home'
+ @patch('pixelated.config.app_factory.init_app')
@patch('pixelated.config.app_factory.reactor')
- def test_that_create_app_binds_to_tcp_port_if_no_ssl_options(self, reactor_mock):
+ def test_that_create_app_binds_to_tcp_port_if_no_ssl_options(self, reactor_mock, init_app_mock):
app_mock = MagicMock()
+ leap_session = MagicMock()
- create_app(app_mock, AppFactoryTest.MockConfig(12345, '127.0.0.1'))
+ create_app(app_mock, AppFactoryTest.MockConfig(12345, '127.0.0.1'), leap_session)
reactor_mock.listenTCP.assert_called_once_with(12345, ANY, interface='127.0.0.1')
+ @patch('pixelated.config.app_factory.init_app')
@patch('pixelated.config.app_factory.reactor')
- def test_that_create_app_binds_to_ssl_if_ssl_options(self, reactor_mock):
+ def test_that_create_app_binds_to_ssl_if_ssl_options(self, reactor_mock, init_app_mock):
app_mock = MagicMock()
+ leap_session = MagicMock()
pixelated.config.app_factory._ssl_options = lambda _: 'options'
- create_app(app_mock, AppFactoryTest.MockConfig(12345, '127.0.0.1', sslkey="sslkey", sslcert="sslcert"))
+ create_app(app_mock, AppFactoryTest.MockConfig(12345, '127.0.0.1', sslkey="sslkey", sslcert="sslcert"), leap_session)
reactor_mock.listenSSL.assert_called_once_with(12345, ANY, 'options', interface='127.0.0.1')
diff --git a/service/test/unit/config/test_dispatcher.py b/service/test/unit/config/test_dispatcher.py
new file mode 100644
index 00000000..ad85a63c
--- /dev/null
+++ b/service/test/unit/config/test_dispatcher.py
@@ -0,0 +1,59 @@
+import json
+import unittest
+import thread
+import sys
+from mockito import mock, when
+import os
+from pixelated.config import App
+from pixelated.config.args import parse as parse_args
+
+from pixelated.config.dispatcher import config_dispatcher
+
+
+class TestConfigDispatcher(unittest.TestCase):
+
+ def setUp(self):
+ self.app = App()
+ self.test_data = {'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'}
+
+ def test_that_organization_switch_reads_the_credentials_from_pipe(self):
+ fifo_path = '/tmp/credentials-pipe'
+
+ sys.argv = ['tmp/does_not_exist', '--dispatcher', fifo_path]
+ args = parse_args()
+
+ self._mkfifo(fifo_path)
+
+ config_dispatcher(self.app, args)
+
+ self.assertEquals('test_provider', self.app['LEAP_SERVER_NAME'])
+ self.assertEquals('test_user', self.app['LEAP_USERNAME'])
+ self.assertEquals('test_password', self.app['LEAP_PASSWORD'])
+
+ def test_that_organization_switch_reads_the_credentials_from_stdin(self):
+ data = json.dumps({'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'})
+ orig_stdin = sys.stdin
+ sys.stdin = mock()
+ when(sys.stdin).read().thenReturn(data)
+
+ try:
+ sys.argv = ['tmp/does_not_exist', '--dispatcher-stdin']
+ args = parse_args()
+
+ config_dispatcher(self.app, args)
+
+ self.assertEquals('test_provider', self.app['LEAP_SERVER_NAME'])
+ self.assertEquals('test_user', self.app['LEAP_USERNAME'])
+ self.assertEquals('test_password', self.app['LEAP_PASSWORD'])
+ finally:
+ sys.stdin = orig_stdin
+
+ def _spin_up_fifo(self, test_fifo):
+ with open(test_fifo, 'w') as fifo:
+ fifo.write(json.dumps(self.test_data))
+
+ def _mkfifo(self, fifo_path):
+ if os.path.exists(fifo_path):
+ os.remove(fifo_path)
+ os.mkfifo('/tmp/credentials-pipe')
+ thread.start_new_thread(self._spin_up_fifo, (fifo_path,))
diff --git a/service/test/unit/test_runserver.py b/service/test/unit/test_runserver.py
deleted file mode 100644
index 99b502f1..00000000
--- a/service/test/unit/test_runserver.py
+++ /dev/null
@@ -1,88 +0,0 @@
-#
-# Copyright (c) 2014 ThoughtWorks, Inc.
-#
-# Pixelated is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pixelated is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# 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 unittest
-import sys
-import thread
-import json
-
-import os
-import pixelated.config.app_factory
-import pixelated.runserver
-from mockito import *
-import pixelated.config.app_factory as app_factory
-from leap.common.events import server as events_server
-
-
-class RunserverTest(unittest.TestCase):
-
- def setUp(self):
- events_server.ensure_server = lambda port=None: None
- when(app_factory).create_app().thenReturn(None)
-
- def tearDown(self):
- unstub()
-
- def test_that_config_file_can_be_specified_on_command_line(self):
- self.config_file_loaded = None
-
- def _mock_parse_config_from_file(config_file):
- self.config_file_loaded = config_file
- return 1, 2, 3
-
- pixelated.runserver.parse_config_from_file = _mock_parse_config_from_file
- sys.argv = ['pixelated-user-agent', '--config', 'pixelated.cfg']
-
- pixelated.runserver.setup()
-
- self.assertEquals('pixelated.cfg', self.config_file_loaded)
-
- def test_that_organization_switch_reads_the_credentials_from_pipe(self):
- fifo_path = '/tmp/credentials-pipe'
- if os.path.exists(fifo_path):
- os.remove(fifo_path)
- test_fifo = os.mkfifo('/tmp/credentials-pipe')
- thread.start_new_thread(self.spin_up_fifo, (fifo_path,))
- sys.argv = ['tmp/does_not_exist', '--dispatcher', fifo_path]
- pixelated.runserver.setup()
-
- def test_that_organization_switch_reads_the_credentials_from_stdin(self):
- data = json.dumps({'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'})
- orig_stdin = sys.stdin
- try:
- sys.stdin = Mock()
- when(sys.stdin).read().thenReturn(data)
-
- sys.argv = ['tmp/does_not_exist', '--dispatcher-stdin']
- pixelated.runserver.setup()
-
- self.assertEquals('test_provider', pixelated.runserver.app.config['LEAP_SERVER_NAME'])
- self.assertEquals('test_user', pixelated.runserver.app.config['LEAP_USERNAME'])
- self.assertEquals('test_password', pixelated.runserver.app.config['LEAP_PASSWORD'])
- finally:
- sys.stdin = orig_stdin
-
- def test_start_services_pass_args_through(self):
- args = {}
- when(app_factory).create_app(any(), args).thenReturn(None)
-
- pixelated.runserver.start_services(args)
-
- verify(app_factory).create_app(any(), args)
-
- def spin_up_fifo(self, test_fifo):
- with open(test_fifo, 'w') as fifo:
- fifo.write(json.dumps({'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'}))