Skip to content

Commit 6552b33

Browse files
committed
pytest updates
1 parent 4d115bb commit 6552b33

6 files changed

Lines changed: 72 additions & 28 deletions

File tree

TECH_README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Environment variables that should be set for testing include the following.
4242

4343
Create `./testing-variables.txt` and load what you need so you can easily re-create the needed variables. This file is in `.gitignore`.
4444

45+
Package the code locally with `pip install -e .` so pytest can run against the python package.
46+
Then `pytest tests/ -v` to perform the testing.
47+
4548
The identity used for testing will require access to at least one profile to test `checkout` and `checkin`.
4649
Additionally, the identity will need access to 2 secrets
4750
* one standard secret with path `/pybritive-test-standard` to test `view` - the value of the secret should be generic note with note of `test`

src/pybritive/helpers/cloud_credential_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def print_gcloudauth(self):
237237
else: # we need to parse out/sanitize what was provided
238238
path = Path(self.gcloud_key_file).expanduser().absolute()
239239

240-
# key file does not yet exist, create it as an empty file
240+
# key file does not yet exist so write to it
241241
path.parent.mkdir(exist_ok=True, parents=True)
242242
path.write_text(json.dumps(self.credentials, indent=2))
243243

tests/test_0200_configure.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,73 +45,73 @@ def common_asserts(result, substring=None, exit_code=0):
4545

4646

4747
def test_configure_tenant_via_flags_no_alias(runner, cli):
48-
result = runner.invoke(cli, 'configure tenant -t test1 -f yaml'.split(' '))
49-
common_asserts(result, substring='[tenant-test1]')
48+
result = runner.invoke(cli, 'configure tenant -t pybritivetest1.dev -f yaml'.split(' '))
49+
common_asserts(result, substring='[tenant-pybritivetest1.dev]')
5050

5151

5252
def test_configure_tenant_via_flags_no_alias_no_format(runner, cli):
53-
result = runner.invoke(cli, 'configure tenant -t test2'.split(' '))
54-
common_asserts(result, substring='[tenant-test2]')
53+
result = runner.invoke(cli, 'configure tenant -t pybritivetest2.dev'.split(' '))
54+
common_asserts(result, substring='[tenant-pybritivetest2.dev]')
5555

5656

5757
def test_configure_tenant_via_flags_yes_alias(runner, cli):
58-
result = runner.invoke(cli, 'configure tenant -t test -f yaml -a testalias1'.split(' '))
58+
result = runner.invoke(cli, 'configure tenant -t pybritivetest1.dev -f yaml -a testalias1'.split(' '))
5959
common_asserts(result, substring='[tenant-testalias1]')
6060

6161

6262
def test_configure_tenant_via_flags_yes_alias_no_format(runner, cli):
63-
result = runner.invoke(cli, 'configure tenant -t test -a testalias2'.split(' '))
63+
result = runner.invoke(cli, 'configure tenant -t pybritivetest2.dev -a testalias2'.split(' '))
6464
common_asserts(result, substring='[tenant-testalias2]')
6565

6666

6767
def test_configure_tenant_via_prompt_no_alias(runner, cli):
68-
result = runner.invoke(cli, 'configure tenant'.split(' '), input='test3\n\njson\n')
69-
common_asserts(result, substring='[tenant-test3]')
68+
result = runner.invoke(cli, 'configure tenant'.split(' '), input='pybritivetest3.dev\n\njson\n')
69+
common_asserts(result, substring='[tenant-pybritivetest3.dev]')
7070

7171

7272
def test_configure_tenant_via_prompt_no_alias_no_format(runner, cli):
73-
result = runner.invoke(cli, 'configure tenant'.split(' '), input='test4\n\n\n')
74-
common_asserts(result, substring='[tenant-test4]')
73+
result = runner.invoke(cli, 'configure tenant'.split(' '), input='pybritivetest4.dev\n\n\n')
74+
common_asserts(result, substring='[tenant-pybritivetest4.dev]')
7575

7676

7777
def test_configure_tenant_via_prompt_yes_alias(runner, cli):
78-
result = runner.invoke(cli, ['configure', 'tenant'], input='test4\ntestalias3\nyaml\n')
78+
result = runner.invoke(cli, ['configure', 'tenant'], input='pybritivetest3.dev\ntestalias3\nyaml\n')
7979
common_asserts(result, substring='[tenant-testalias3]')
8080

8181

8282
def test_configure_tenant_via_prompt_yes_alias_no_format(runner, cli):
83-
result = runner.invoke(cli, ['configure', 'tenant'], input='test4\ntestalias4\n\n')
83+
result = runner.invoke(cli, ['configure', 'tenant'], input='pybritivetest4.dev\ntestalias4\n\n')
8484
common_asserts(result, substring='[tenant-testalias4]')
8585

8686

8787
def test_configure_global_via_flags_file_backend(runner, cli):
88-
result = runner.invoke(cli, 'configure global -t test1 -f table -b file'.split(' '))
89-
common_asserts(result, substring=['default_tenant=test1', 'output_format=table', 'credential_backend=file'])
88+
result = runner.invoke(cli, 'configure global -t pybritivetest1.dev -f table -b file'.split(' '))
89+
common_asserts(result, substring=['default_tenant=pybritivetest1.dev', 'output_format=table', 'credential_backend=file'])
9090

9191

9292
def test_configure_global_via_flags_encrypted_file_backend(runner, cli):
93-
result = runner.invoke(cli, 'configure global -t test2 -f yaml -b encrypted-file'.split(' '))
93+
result = runner.invoke(cli, 'configure global -t pybritivetest2.dev -f yaml -b encrypted-file'.split(' '))
9494
common_asserts(
9595
result,
9696
substring=[
97-
'default_tenant=test2',
97+
'default_tenant=pybritivetest2.dev',
9898
'output_format=yaml',
9999
'credential_backend=encrypted-file'
100100
]
101101
)
102102

103103

104104
def test_configure_global_via_prompt_file_backend(runner, cli):
105-
result = runner.invoke(cli, 'configure global'.split(' '), input='test1\ntable-pretty\nfile\n')
106-
common_asserts(result, substring=['default_tenant=test1', 'output_format=table-pretty', 'credential_backend=file'])
105+
result = runner.invoke(cli, 'configure global'.split(' '), input='pybritivetest1.dev\ntable-pretty\nfile\n')
106+
common_asserts(result, substring=['default_tenant=pybritivetest1.dev', 'output_format=table-pretty', 'credential_backend=file'])
107107

108108

109109
def test_configure_global_via_prompt_encrypted_file_backend(runner, cli):
110-
result = runner.invoke(cli, 'configure global'.split(' '), input='test2\n\nencrypted-file\n')
110+
result = runner.invoke(cli, 'configure global'.split(' '), input='pybritivetest2.dev\n\nencrypted-file\n')
111111
common_asserts(
112112
result,
113113
substring=[
114-
'default_tenant=test2',
114+
'default_tenant=pybritivetest2.dev',
115115
'output_format=json',
116116
'credential_backend=encrypted-file'
117117
]
@@ -124,8 +124,8 @@ def test_configure_global_with_invalid_format(runner, cli):
124124

125125

126126
def test_configure_global_with_invalid_tenant(runner, cli):
127-
result = runner.invoke(cli, 'configure global -t incorect'.split(' '))
128-
assert "Invalid global field default_tenant value incorect provided. Tenant not found." in result.output
127+
result = runner.invoke(cli, 'configure global -t incorrect'.split(' '))
128+
assert "Invalid global field default_tenant value incorrect provided. Tenant not found." in result.output
129129

130130

131131
def test_configure_import_simple(runner, cli):
@@ -166,7 +166,7 @@ def test_configure_update_global_correct_data(runner, cli):
166166

167167
def test_configure_update_tenant_correct_data(runner, cli):
168168
tenant = os.getenv('PYBRITIVE_TEST_TENANT')
169-
result = runner.invoke(cli, f'configure update tenant-{tenant} name test'.split(' '))
170-
common_asserts(result, substring=['name=test'])
169+
result = runner.invoke(cli, f'configure update tenant-{tenant} name pybritivetest1.dev'.split(' '))
170+
common_asserts(result, substring=['name=pybritivetest1.dev'])
171171
# set it back
172172
runner.invoke(cli, f'configure update tenant-{tenant} name {tenant}'.split(' '))

tests/test_0850_clear.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
from pathlib import Path
3+
import json
4+
5+
6+
def test_clear_cache(runner, cli):
7+
result = runner.invoke(cli, 'clear cache'.split(' '))
8+
local_home = os.getenv('PYBRITIVE_HOME_DIR')
9+
path = Path(Path(local_home) / '.britive' / 'pybritive.cache')
10+
with open(str(path), 'r') as f:
11+
data = json.loads(f.read())
12+
assert result.exit_code == 0
13+
assert 'profiles' in data.keys()
14+
assert len(data['profiles']) == 0
15+
16+
17+
def test_clear_gcloud_key_files(runner, cli):
18+
local_home = os.getenv('PYBRITIVE_HOME_DIR')
19+
path = Path(local_home) / '.britive' / 'pybritive-gcloud-key-files'
20+
file1 = path / 'file1.json'
21+
file2 = path / 'file2.json'
22+
23+
path.mkdir(exist_ok=True, parents=True)
24+
file1.write_text('')
25+
file2.write_text('')
26+
27+
assert path.is_dir()
28+
assert file1.is_file()
29+
assert file2.is_file()
30+
31+
result = runner.invoke(cli, 'clear gcloud-auth-key-files'.split(' '))
32+
assert result.exit_code == 0
33+
assert not file1.is_file()
34+
assert not file2.is_file()
35+
assert not path.is_dir()
36+
37+
38+
39+
40+
41+

tests/test_0900_login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_login_interactive(runner, cli, unset_api_token_env_var):
1212
result = runner.invoke(cli, ['login'])
1313
assert result.exit_code == 0
1414
local_home = os.getenv('PYBRITIVE_HOME_DIR')
15-
path = Path(Path(local_home) / '.britive' / 'pybritive.credentials')
15+
path = Path(Path(local_home) / '.britive' / 'pybritive.credentials.encrypted')
1616
with open(str(path), 'r') as f:
1717
data = f.read()
1818
assert 'accessToken=' in data

tests/test_1000_logout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import os
33

44

5-
def test_logout(runner, cli, profile):
5+
def test_logout(runner, cli):
66
result = runner.invoke(cli, ['logout'])
77
assert result.exit_code == 0
88
local_home = os.getenv('PYBRITIVE_HOME_DIR')
9-
path = Path(Path(local_home) / '.britive' / 'pybritive.credentials')
9+
path = Path(Path(local_home) / '.britive' / 'pybritive.credentials.encrypted')
1010
with open(str(path), 'r') as f:
1111
data = f.read()
1212
assert len(data) == 0

0 commit comments

Comments
 (0)