def test_alternative_domains(registry): """Make sure we can specify an alternative domain.""" payload = { 'jwt': 'big-token', 'username': '******' } manager = ConfigManager() manager.set('cloud:server', 'https://testcloud.com') with requests_mock.Mocker() as mocker: mocker.post('https://testcloud.com/api/v1/auth/login/', json=payload) link_cloud(manager, '*****@*****.**', 'password') assert registry.get_config('arch:cloud_user') == 'user1' assert registry.get_config('arch:cloud_token') == 'big-token' cloud = IOTileCloud() payload = { 'token': 'new-token' } with requests_mock.Mocker() as mocker: mocker.post('https://testcloud.com/api/v1/auth/api-jwt-refresh/', json=payload) cloud.refresh_token() assert registry.get_config('arch:cloud_token') == 'new-token'
def test_getting_and_setting(): """Test setting and getting variables with correct types """ man = ConfigManager() man.add_variable('test:var', 'bool', 'test variable', 'false') val = man.get('test:var') assert val is False man.set('test:var', 'true') assert man.get('test:var') is True # Make sure we can get and set without a default value man.add_variable('test:var2', 'bool', 'test variable') with pytest.raises(ArgumentError): man.get('test:var2') man.set('test:var2', 'True') assert man.get('test:var2') is True man.set('test:var2', 'False') assert man.get('test:var2') is False # Make sure removing a variable works man.remove('test:var2') with pytest.raises(ArgumentError): man.get('test:var2') man.remove('test:var') assert man.get('test:var') is False