Skip to content

Commit 31d77d5

Browse files
committed
remove nosetest dependency and usage
1 parent ad9a5ad commit 31d77d5

File tree

7 files changed

+20
-98
lines changed

7 files changed

+20
-98
lines changed

docs/contributing/testing.md

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Available tasks:
5050
function.
5151
test.lint Linting with `pylint` and `autopep8`
5252
test.security Runs `bandit` and `safety check`
53-
unit.nose Unit testing: Runs unit tests using `nosetests`
5453
unit.pytest Unit testing: Runs unit tests using `pytest`
5554

5655

@@ -64,8 +63,6 @@ invoke integration.query
6463
invoke integration.write-policy
6564

6665
invoke test.security
67-
68-
invoke unit.nose
6966
```
7067

7168
Local Unit Testing and Integration Testing:
@@ -95,89 +92,37 @@ just run that quick command on your machine.
9592
Running the Test Suite
9693
----------------------
9794

98-
We use [Nose](https://nose.readthedocs.io/en/latest/) for unit testing.
99-
All tests are placed in the `tests` folder.
95+
We use [pytest](https://docs.pytest.org/en//) for unit testing.
96+
All tests are placed in the `test` folder.
10097

10198
- Just run the following:
10299

103100
```bash
104-
nosetests -v
101+
pytest -v
105102

106103
# This will output the print() statements in your test code
107-
nosetests -v --nocapture
104+
pytest -v --show-capture=no
108105

109106
# This will include the debug logging statements in the test output
110-
nosetests -v --logging-level=DEBUG
107+
pytest -v --log-level=DEBUG
111108
```
112109

113110
- Alternatively, you can use `invoke`, as mentioned above:
114111

115112
```bash
116-
invoke unit.nose
113+
invoke unit.pytest
117114
```
118115

119116
Output:
120117

121118
```text
122-
test_overrides_yml_config: Tests the format of the overrides yml file for the RAM service ... ok
123-
test_passing_overall_iam_action_override: Tests iam:CreateAccessKey ... ok
124-
test_get_dependent_actions_double (test_actions.ActionsTestCase) ... ok
125-
test_get_dependent_actions_several (test_actions.ActionsTestCase) ... ok
126-
test_get_dependent_actions_single (test_actions.ActionsTestCase) ... ok
127-
test_analyze_by_access_level: Test out calling this as a library ... ok
128-
test_determine_risky_actions_from_list: Test comparing requested actions to a list of risky actions ... ok
129-
test_get_actions_from_policy: Verify that the get_actions_from_policy function is grabbing the actions ... ok
130-
test_get_actions_from_policy_file_with_explicit_actions: Verify that we can get a list of actions from a ... ok
131-
test_get_actions_from_policy_file_with_wildcards: Verify that we can read the actions from a file, ... ok
132-
test_remove_actions_not_matching_access_level: Verify remove_actions_not_matching_access_level is working as expected ... ok
133-
test_get_findings: Ensure that finding.get_findings() combines two risk findings for one policy properly. ... ok
134-
test_get_findings_by_policy_name: Testing out the 'Findings' object ... ok
135-
test_add_s3_permissions_management_arn (test_arn_action_group.ArnActionGroupTestCase) ... ok
136-
test_get_policy_elements (test_arn_action_group.ArnActionGroupTestCase) ... ok
137-
test_update_actions_for_raw_arn_format (test_arn_action_group.ArnActionGroupTestCase) ... ok
138-
test_does_arn_match_case_1 (test_arns.ArnsTestCase) ... ok
139-
test_does_arn_match_case_2 (test_arns.ArnsTestCase) ... ok
140-
test_does_arn_match_case_4 (test_arns.ArnsTestCase) ... ok
141-
test_does_arn_match_case_5 (test_arns.ArnsTestCase) ... ok
142-
test_does_arn_match_case_6 (test_arns.ArnsTestCase) ... ok
143-
test_does_arn_match_case_bucket (test_arns.ArnsTestCase) ... ok
144-
test_determine_actions_to_expand: provide expanded list of actions, like ecr:* ... ok
145-
test_minimize_statement_actions (test_minimize_wildcard_actions.MinimizeWildcardActionsTestCase) ... ok
146-
test_get_action_data: Tests function that gets details on a specific IAM Action. ... ok
147-
test_get_actions_at_access_level_that_support_wildcard_arns_only: Test function that gets a list of ... ok
148-
test_get_actions_for_service: Tests function that gets a list of actions per AWS service. ... ok
149-
test_get_actions_matching_condition_crud_and_arn: Get a list of IAM Actions matching condition key, ... ok
150-
test_get_actions_matching_condition_crud_and_wildcard_arn: Get a list of IAM Actions matching condition key ... ok
151-
test_get_actions_matching_condition_key: Tests a function that gathers all instances in ... ok
152-
test_get_actions_that_support_wildcard_arns_only: Tests function that shows all ... ok
153-
test_get_actions_with_access_level: Tests function that gets a list of actions in a ... ok
154-
test_get_actions_with_arn_type_and_access_level: Tests a function that gets a list of ... ok
155-
test_get_all_actions_with_access_level: Get all actions with a given access level ... ok
156-
test_get_arn_type_details: Tests function that grabs details about a specific ARN name ... ok
157-
test_get_arn_types_for_service: Tests function that grabs arn_type and raw_arn pairs ... ok
158-
test_get_condition_key_details: Tests function that grabs details about a specific condition key ... ok
159-
test_get_condition_keys_for_service: Tests function that grabs a list of condition keys per service. ... ok
160-
test_get_raw_arns_for_service: Tests function that grabs a list of raw ARNs per service ... ok
161-
test_remove_actions_that_are_not_wildcard_arn_only: Tests function that removes actions from a list that ... ok
162-
test_actions_template (test_template.TemplateTestCase) ... ok
163-
test_crud_template (test_template.TemplateTestCase) ... ok
164-
test_actions_schema: Validates that the user-supplied YAML is working for CRUD mode ... ok
165-
test_actions_schema: Validates that the user-supplied YAML is working for CRUD mode ... ok
166-
test_print_policy_with_actions_having_dependencies (test_write_policy.WritePolicyActionsTestCase) ... ok
167-
test_write_policy (test_write_policy.WritePolicyCrudTestCase) ... ok
168-
test_write_policy_beijing: Tests ARNs with the partiion `aws-cn` instead of just `aws` ... ok
169-
test_write_policy_govcloud: Tests ARNs with the partition `aws-us-gov` instead of `aws` ... ok
170-
test_wildcard_when_not_necessary: Attempts bypass of CRUD mode wildcard-only ... ok
171-
test_write_actions_policy_with_library_only: Write an actions mode policy without using the command line at all (library only) ... ok
172-
test_write_crud_policy_with_library_only: Write an actions mode policy without using the command line at all (library only) ... ok
173-
test_actions_missing_actions: write-policy actions if the actions block is missing ... ok
174-
test_allow_missing_access_level_categories_in_cfg: write-policy when the YAML file ... ok
175-
test_allow_empty_access_level_categories_in_cfg: If the content of a list is an empty string, it should sysexit ... ok
176-
test_actions_missing_arn: write-policy actions command when YAML file block is missing an ARN ... ok
177-
test_actions_missing_description: write-policy when the YAML file is missing a description ... ok
178-
test_actions_missing_name: write-policy when the YAML file is missing a name ... ok
179-
180-
Ran 57 tests in 2.694s
181-
182-
OK
119+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_a_determine_actions_to_expand_not_upper_camelcase PASSED [ 0%]
120+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_analyze_by_access_level PASSED [ 1%]
121+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_analyze_statement_by_access_level PASSED [ 2%]
122+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_determine_actions_to_expand PASSED [ 2%]
123+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_gh_162 PASSED [ 3%]
124+
test/analysis/test_expand.py::PolicyExpansionTestCase::test_policy_expansion PASSED [ 4%]
125+
...
126+
127+
========================================================= 134 passed in 51.04s ============================================================
183128
```

policy_sentry/shared/awsdocs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def header_matches(string, table):
4242

4343
def get_links_from_base_actions_resources_conditions_page():
4444
"""Gets the links from the actions, resources, and conditions keys page, and returns their filenames."""
45-
html = requests.get(BASE_DOCUMENTATION_URL)
45+
html = requests.get(BASE_DOCUMENTATION_URL, timeout=300)
4646
soup = BeautifulSoup(html.content, "html.parser")
4747
html_filenames = []
4848
for i in soup.find("div", {"class": "highlights"}).findAll("a"):
@@ -85,7 +85,7 @@ def update_html_docs_directory(html_docs_destination):
8585
# html_filenames = [sub.replace(".html", ".partial.html") for sub in html_filenames]
8686

8787
for page in html_filenames:
88-
response = requests.get(link_url_prefix + page, allow_redirects=False)
88+
response = requests.get(link_url_prefix + page, allow_redirects=False, timeout=300)
8989
# Replace the CSS stuff. Basically this:
9090
"""
9191
<link href='href="https://docs.aws.amazon.com/images/favicon.ico"' rel="icon" type="image/ico"/>

requirements-dev.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Unit Testing
2-
pytest==7.1.1
2+
pytest==7.4.0
33
pylint==2.13.5
4-
nose==1.3.7
5-
coverage==6.3.2
4+
coverage==7.3.0
65
# Integration tests and tasks
76
invoke==2.2.0
87
# Security testing
98
safety==1.10.3
10-
bandit==1.7.4
9+
bandit==1.7.5
1110
# Formatting
1211
black==22.3.0
1312
# Other? Maybe this is from the docs? Not sure.

setup.cfg

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
[nosetests]
2-
exe = True
3-
tests = test/, test/analysis/, test/command/, test/querying/, test/util/, test/writing/
4-
verbosity=2
5-
61
[tool:pytest]
72
testpaths = test test/analysis test/command test/querying test/util test/writing
83
python_files=test/*/test_*.py

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
VERSION_RE = re.compile(r'''__version__ = ['"]([0-9.]+)['"]''')
88
TESTS_REQUIRE = [
99
'coverage',
10-
'nose',
1110
'pytest'
1211
]
1312
REQUIRED_PACKAGES = [

tasks.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,6 @@ def run_linter(c):
243243

244244

245245
# UNIT TESTING
246-
@task
247-
def run_nosetests(c):
248-
"""Unit testing: Runs unit tests using `nosetests`"""
249-
c.run('echo "Running Unit tests"')
250-
try:
251-
c.run('nosetests -v --logging-level=CRITICAL')
252-
except UnexpectedExit as u_e:
253-
logger.critical(f"FAIL! UnexpectedExit: {u_e}")
254-
sys.exit(1)
255-
except Failure as f_e:
256-
logger.critical(f"FAIL: Failure: {f_e}")
257-
sys.exit(1)
258-
259-
260246
@task
261247
def run_pytest(c):
262248
"""Unit testing: Runs unit tests using `pytest`"""
@@ -287,7 +273,6 @@ def build_docker(c):
287273
integration.add_task(query, 'query')
288274
integration.add_task(query_with_yaml, 'query-yaml')
289275

290-
unit.add_task(run_nosetests, 'nose')
291276
unit.add_task(run_pytest, 'pytest')
292277

293278
docs.add_task(build_docs, "build-docs")

utils/run_tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ invoke build.uninstall-package
99
invoke build.install-package
1010
invoke integration.clean
1111
invoke integration.version
12-
#invoke unit.nose
1312
invoke unit.pytest
1413
invoke integration.query
1514
invoke integration.query-yaml

0 commit comments

Comments
 (0)