Exemple #1
0
 def test_packs_authorize_params(self, mock_pack_params):
     load_prefs(_fixture_path('happy_authorize_params.yaml'))
     mock_pack_params.assert_any_call([
         'a=b',
         'c=d',
         'a=e',
     ])
Exemple #2
0
 def test_loads_variables_as_flat_str_dict(self, mock_flat_str_dict):
     load_prefs(_fixture_path('happy_variables.yaml'))
     mock_flat_str_dict.assert_any_call('variable', {
         'simle_str': 'is probably most common',
         'ints': 2,
         3: 3,
         'true': 'true',
     },
                                        check_special_chars=True)
 def test_writes_new_token_if_re_authenticating(self, mock_auth_resp_url,
                                                mock_open, mock_get):
     mock_auth_resp_url.return_value = (
         f'{FAKE_API_URL}/?code=banana&state={FAKE_STATE}')
     send_request(self.sesh, self.prefs, self.opts, TEMP_FILE)
     prefs = load_prefs(TEMP_FILE)
     assert prefs['oauth2']['access_token'] == NEW_ACCESS_TOKEN
Exemple #4
0
 def test_validates_required_fields(self):
     try:
         prefs = load_prefs(_fixture_path('missing_fields.yaml'))
     except APIBuddyException as err:
         assert 'schema' in err.title
         assert 'api_url' in err.message
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #5
0
 def test_requires_known_oauth_type(self):
     try:
         prefs = load_prefs(_fixture_path('oauth3.yaml'))
     except APIBuddyException as err:
         assert 'auth_type' in err.title
         assert 'should be one of these' in err.message
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #6
0
 def test_wont_allow_unrecognized_theme(self):
     try:
         prefs = load_prefs(_fixture_path('bad_theme.yaml'))
     except APIBuddyException as err:
         assert 'theme' in err.title
         assert 'one of these instead:' in err.message  # helpful suggestion
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #7
0
 def test_can_load_from_a_yaml_file(self):
     prefs = load_prefs(_fixture_path('test.yaml'))
     assert prefs['api_url'] == 'https://api.doggos.com'
     assert prefs['oauth2']['client_id'] == 'my_favorite_client_id'
     assert prefs['oauth2']['client_secret'] == 'my_favorite_client_secret'
     assert prefs['oauth2']['scopes'] == ['dogs', 'kibbles']
     assert prefs['oauth2']['state'] is None
     assert prefs['auth_test_status'] == 403
Exemple #8
0
 def test_file_must_contain_valid_yaml(self):
     try:
         prefs = load_prefs(_fixture_path('bad.yaml'))
     except APIBuddyException as err:
         assert 'problem reading' in err.title
         assert 'valid yaml' in err.message
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #9
0
 def test_validates_field_types(self):
     try:
         prefs = load_prefs(_fixture_path('bad_types.yaml'))
     except APIBuddyException as err:
         assert 'schema' in err.title
         assert 'client_id' in err.message
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #10
0
 def test_file_cant_be_empty(self):
     try:
         prefs = load_prefs(_fixture_path('empty.yaml'))
     except APIBuddyException as err:
         assert 'empty' in err.title
         assert (f'{EXAMPLE_PREFS["api_url"]}' in err.message)
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #11
0
 def test_doesnt_allow_variable_names_with_special_characters(self):
     try:
         prefs = load_prefs(
             _fixture_path('special_chars_variable_name.yaml'))
     except APIBuddyException as err:
         assert 'my_#{bad}_variable' in err.title
         assert 'special characters' in err.message
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #12
0
 def test_doesnt_allow_query_string_in_api_url(self):
     try:
         prefs = load_prefs(_fixture_path('api_url_with_query_string.yaml'))
     except APIBuddyException as err:
         assert 'query parameters' in err.title
         # helpful suggestion
         assert CAT_FACTS_API_URL in err.message
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #13
0
 def test_doesnt_allow_hash_fragments_in_api_url(self):
     try:
         prefs = load_prefs(
             _fixture_path('api_url_with_hash_fragment.yaml'))
     except APIBuddyException as err:
         assert 'hash fragments' in err.title
         # helpful suggestion
         assert CAT_FACTS_API_URL in err.message
     else:
         assert False, f'{LOADED_MSG}{prefs}'
Exemple #14
0
 def test_merges_yaml_with_defaults(self):
     prefs = load_prefs(_fixture_path('test.yaml'))
     # retains non-default
     assert prefs['oauth2']['client_id'] == 'my_favorite_client_id'
     # not specified
     assert (prefs['oauth2']['redirect_uri'] ==
             DEFAULT_OAUTH2_PREFS['redirect_uri'])
     # not specified
     assert prefs['api_version'] == DEFAULT_PREFS['api_version']
     # overwritten default
     assert prefs['auth_test_status'] == 403
Exemple #15
0
 def test_allows_no_theme(self):
     prefs = load_prefs(_fixture_path('no_theme.yaml'))
     assert prefs['theme'] is None
Exemple #16
0
 def test_when_api_version_is_not_none_it_coerces_to_str(self):
     prefs = load_prefs(_fixture_path('api_version_as_int.yaml'))
     assert prefs['api_version'] == '3'
Exemple #17
0
 def test_when_file_doesnt_exist_it_writes_example_prefs(self):
     assert not path.isfile(TEMP_FILE)
     prefs = load_prefs(TEMP_FILE)
     assert path.isfile(TEMP_FILE)
     for key, example_val in EXAMPLE_PREFS.items():
         assert prefs[key] == example_val
Exemple #18
0
 def test_can_save_to_a_new_file(self):
     loaded_prefs = load_prefs(TEMP_FILE)
     assert loaded_prefs['api_url'] == NEW_PREFS['api_url']
Exemple #19
0
 def test_loads_headers_as_flat_str_dict(self, mock_flat_str_dict):
     load_prefs(_fixture_path('happy_headers.yaml'))
     mock_flat_str_dict.assert_any_call('header', {
         'Accept': 'text/html',
         'Authorization': 'Basic ab1c23d4',
     })
Exemple #20
0
 def test_adds_default_api_url_scheme_if_missing(self):
     prefs = load_prefs(_fixture_path('api_url_without_scheme.yaml'))
     assert prefs['api_url'] == CAT_FACTS_API_URL
Exemple #21
0
 def test_allows_pygment_themes(self):
     prefs = load_prefs(_fixture_path('pygment_theme.yaml'))
     assert prefs['theme'] == 'paraiso-dark'
Exemple #22
0
 def test_allows_shellectric_theme(self):
     prefs = load_prefs(_fixture_path('shellectric_theme.yaml'))
     assert prefs['theme'] == SHELLECTRIC
Exemple #23
0
 def test_supports_string_api_versions(self):
     prefs = load_prefs(_fixture_path('api_version_as_str.yaml'))
     assert prefs['api_version'] == 'three'
Exemple #24
0
 def test_auth_type_can_be_none(self):
     prefs = load_prefs(_fixture_path('no_auth.yaml'))
     assert prefs['auth_type'] is None