summaryrefslogtreecommitdiff
path: root/service/test/unit/config
diff options
context:
space:
mode:
authorBruno Wagner <bwgpro@gmail.com>2015-06-04 19:11:46 -0300
committerBruno Wagner <bwgpro@gmail.com>2015-06-04 19:12:08 -0300
commit7a8e9cc142ad368434031e4e008b40281d68150b (patch)
tree7f789e34c34bfa92d788aecd30e0808907b4a3a3 /service/test/unit/config
parent881b2bc3da468a22fc0e11bcfda60a7feec99ab9 (diff)
Config dispatcher and config_ua are now in credentials
Diffstat (limited to 'service/test/unit/config')
-rw-r--r--service/test/unit/config/test_credentials.py30
-rw-r--r--service/test/unit/config/test_dispatcher.py59
2 files changed, 30 insertions, 59 deletions
diff --git a/service/test/unit/config/test_credentials.py b/service/test/unit/config/test_credentials.py
new file mode 100644
index 00000000..61cfac53
--- /dev/null
+++ b/service/test/unit/config/test_credentials.py
@@ -0,0 +1,30 @@
+import json
+import unittest
+import sys
+from mockito import mock, when
+from pixelated.config.args import parse_user_agent_args
+from pixelated.config import credentials
+
+
+class TestReadCredentials(unittest.TestCase):
+
+ def setUp(self):
+ self.test_data = {'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'}
+
+ def test_organization_mode_reads_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', '--organization-mode']
+ args = parse_user_agent_args()
+
+ provider, user, password = credentials.read(args.organization_mode, 'not_used')
+
+ self.assertEquals('test_provider', provider)
+ self.assertEquals('test_user', user)
+ self.assertEquals('test_password', password)
+ finally:
+ sys.stdin = orig_stdin
diff --git a/service/test/unit/config/test_dispatcher.py b/service/test/unit/config/test_dispatcher.py
deleted file mode 100644
index e154ac22..00000000
--- a/service/test/unit/config/test_dispatcher.py
+++ /dev/null
@@ -1,59 +0,0 @@
-import json
-import unittest
-import thread
-import sys
-from mockito import mock, when
-import os
-from pixelated.config.config import Config
-from pixelated.config.args import parse_user_agent_args
-
-from pixelated.config.dispatcher import config_dispatcher
-
-
-class TestConfigDispatcher(unittest.TestCase):
-
- def setUp(self):
- self.config = Config()
- 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_user_agent_args()
-
- self._mkfifo(fifo_path)
-
- provider, user, password = config_dispatcher(args.dispatcher)
-
- self.assertEquals('test_provider', provider)
- self.assertEquals('test_user', user)
- self.assertEquals('test_password', 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_user_agent_args()
-
- provider, user, password = config_dispatcher(args.dispatcher)
-
- self.assertEquals('test_provider', provider)
- self.assertEquals('test_user', user)
- self.assertEquals('test_password', 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,))