summaryrefslogtreecommitdiff
path: root/service/test/unit/config/test_credentials.py
blob: 6c25c5bf4741be1f04c8b64fa13e175d6b66f3ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
import unittest
import sys
from mockito import mock, when
from pixelated.config import arguments
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 = arguments.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