Skip to content

Commit

Permalink
Bugfix for query-endpoints output formatting, add tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Caroline Russell <[email protected]>
  • Loading branch information
cerrussell committed Apr 4, 2024
1 parent 08d3894 commit 958642d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion atom_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
A cli, classes and functions for converting an atom slice to a different format
"""
__version__ = '0.5.1'
__version__ = '0.5.2'
3 changes: 2 additions & 1 deletion atom_tools/cli/commands/query_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ def handle(self):
line_filter = ()
if self.option('filter-lines'):
line_filter = get_ln_range(self.option('filter-lines'))
output_endpoints(result, self.option('sparse'), line_filter)
output = output_endpoints(result, self.option('sparse'), line_filter)
print(output)
8 changes: 4 additions & 4 deletions atom_tools/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def export_json(data: Dict, outfile: str, indent: int | None = None) -> None:
json.dump(data, f, indent=indent, sort_keys=True)


def output_endpoints(data: Dict, names_only: bool, line_range: Tuple[int, int] | Tuple) -> None:
def output_endpoints(data: Dict, names_only: bool, line_range: Tuple[int, int] | Tuple) -> str:
"""Outputs endpoints"""
to_print = ''
for endpoint, values in data.get('paths', {}).items():
Expand All @@ -48,9 +48,9 @@ def output_endpoints(data: Dict, names_only: bool, line_range: Tuple[int, int] |
for i in v:
if not line_range or line_range[0] <= i <= line_range[1]:
to_print += f':{k}:{i}'
break
to_print += '\n'
print(to_print)
break
to_print += '\n'
return to_print


def remove_duplicates_list(obj: List[Dict]) -> List[Dict]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "atom-tools"
version = "0.5.1"
version = "0.5.2"
description = "Collection of tools for use with AppThreat/atom."
authors = [
{ name = "Caroline Russell", email = "[email protected]" },
Expand Down
27 changes: 26 additions & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from atom_tools.lib.utils import add_params_to_cmd, remove_duplicates_list
from atom_tools.lib.slices import AtomSlice
from atom_tools.lib.utils import add_params_to_cmd, output_endpoints, remove_duplicates_list


def test_add_params_to_cmd():
Expand All @@ -18,3 +19,27 @@ def test_remove_duplicates_list():
{'code': None, 'function_name': ':program', 'line_number': 1},
{'code': 'app.ts::program:require', 'function_name': 'require', 'line_number': 6}
]


def test_output_endpoints():
data = {'openapi': '3.1.0', 'info': {'title': 'OpenAPI Specification for data', 'version': '1.0.0'}, 'paths': {'/uaa/users': {'post': {'responses': {}}, 'x-atom-usages': {'call': {'account-service/src/main/java/com/piggymetrics/account/client/AuthServiceClient.java': [12]}}}, '/statistics/{accountName}': {'parameters': [{'name': 'accountName', 'in': 'path', 'required': True}], 'put': {'responses': {}}, 'x-atom-usages': {'call': {'account-service/src/main/java/com/piggymetrics/account/client/StatisticsServiceClient.java': [13]}}}, '/current': {'put': {'responses': {}}, 'x-atom-usages': {'call': {'account-service/src/main/java/com/piggymetrics/account/controller/AccountController.java': [30, 25], 'auth-service/src/main/java/com/piggymetrics/auth/controller/UserController.java': [22], 'notification-service/src/main/java/com/piggymetrics/notification/controller/RecipientController.java': [26, 21], 'statistics-service/src/main/java/com/piggymetrics/statistics/controller/StatisticsController.java': [20]}, 'target': {'account-service/src/main/java/com/piggymetrics/account/controller/AccountController.java': [30], 'auth-service/src/main/java/com/piggymetrics/auth/controller/UserController.java': [22], 'notification-service/src/main/java/com/piggymetrics/notification/controller/RecipientController.java': [26]}}, 'get': {'responses': {}}}, '/': {'post': {'responses': {}}, 'x-atom-usages': {'call': {'account-service/src/main/java/com/piggymetrics/account/controller/AccountController.java': [35]}}}, '/{name}': {'parameters': [{'name': 'name', 'in': 'path', 'required': True}], 'get': {'responses': {}}, 'x-atom-usages': {'call': {'account-service/src/main/java/com/piggymetrics/account/controller/AccountController.java': [20]}}}, '/accounts/{accountName}': {'parameters': [{'name': 'accountName', 'in': 'path', 'required': True}], 'get': {'responses': {}}, 'x-atom-usages': {'call': {'notification-service/src/main/java/com/piggymetrics/notification/client/AccountServiceClient.java': [12]}}}, '/latest': {'get': {'responses': {}}, 'x-atom-usages': {'call': {'statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java': [13]}}}, '/{accountName}': {'parameters': [{'name': 'accountName', 'in': 'path', 'required': True}], 'put': {'responses': {}}, 'x-atom-usages': {'call': {'statistics-service/src/main/java/com/piggymetrics/statistics/controller/StatisticsController.java': [32, 26]}, 'target': {'statistics-service/src/main/java/com/piggymetrics/statistics/controller/StatisticsController.java': [32]}}, 'get': {'responses': {}}}}}
assert output_endpoints(data, False, ()) == (
'/uaa/users:account-service/src/main/java/com/piggymetrics/account/client/AuthServiceClient.java:12\n'
'/statistics/{accountName}:account-service/src/main/java/com/piggymetrics/account/client/StatisticsServiceClient.java:13\n'
'/current:account-service/src/main/java/com/piggymetrics/account/controller/AccountController.java:30:auth-service/src/main/java/com/piggymetrics/auth/controller/UserController.java:22:notification-service/src/main/java/com/piggymetrics/notification/controller/RecipientController.java:26:statistics-service/src/main/java/com/piggymetrics/statistics/controller/StatisticsController.java:20\n'
'/:account-service/src/main/java/com/piggymetrics/account/controller/AccountController.java:35\n'
'/{name}:account-service/src/main/java/com/piggymetrics/account/controller/AccountController.java:20\n'
'/accounts/{accountName}:notification-service/src/main/java/com/piggymetrics/notification/client/AccountServiceClient.java:12\n'
'/latest:statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java:13\n'
'/{accountName}:statistics-service/src/main/java/com/piggymetrics/statistics/controller/StatisticsController.java:32\n')
assert output_endpoints(data, True, ()) == ('/uaa/users\n/statistics/{'
'accountName}\n/current\n/\n/{name}\n/accounts/{'
'accountName}\n/latest\n/{accountName}\n')
assert output_endpoints(data, False, (1, 14)) == (
'/uaa/users:account-service/src/main/java/com/piggymetrics/account/client'
'/AuthServiceClient.java:12\n/statistics/{'
'accountName}:account-service/src/main/java/com/piggymetrics/account/client'
'/StatisticsServiceClient.java:13\n/current\n/\n/{name}\n/accounts/{'
'accountName}:notification-service/src/main/java/com/piggymetrics/notification/client'
'/AccountServiceClient.java:12\n/latest:statistics-service/src/main/java/com'
'/piggymetrics/statistics/client/ExchangeRatesClient.java:13\n/{accountName}\n')

0 comments on commit 958642d

Please sign in to comment.