diff options
author | Duda Dornelles <dudassdornelles@gmail.com> | 2015-01-27 16:08:03 -0200 |
---|---|---|
committer | Pixpoa pairing <pixpoapairing@pixelated-project.org> | 2015-01-27 16:08:03 -0200 |
commit | 26b85d8e523f2b6aafbe18132efcd617ae892228 (patch) | |
tree | 0dbdf0cef276aef577d028391543e3f3c5354160 /service/test/unit/config/test_dispatcher.py | |
parent | 4713741e6cbd9ad7fe20925120f6e25bc6b538e7 (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/unit/config/test_dispatcher.py')
-rw-r--r-- | service/test/unit/config/test_dispatcher.py | 59 |
1 files changed, 59 insertions, 0 deletions
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,)) |