Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit a1f4d9d

Browse files
authored
update unit tests for additonal coverage (#184)
1 parent e2f3d48 commit a1f4d9d

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

sonar-project.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ sonar.sources= \
1414
source/api
1515

1616

17-
# sonar.exclusions=
17+
sonar.exclusions= \
18+
test/
1819

19-
# sonar.tests=source/
20+
sonar.tests= \
21+
test/unit
2022

2123
sonar.sourceEncoding=UTF-8
2224

test/unit/api/service_responses.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,34 @@
100100
},
101101
}
102102

103+
104+
efs_describe_file_systems_marker_response = {
105+
'FileSystems': [
106+
{
107+
'CreationTime': datetime.now(),
108+
'CreationToken': 'tokenstring',
109+
'FileSystemId': f'{test_filesystem_id}',
110+
'LifeCycleState': 'available',
111+
'Name': 'MyFileSystem',
112+
'NumberOfMountTargets': 1,
113+
'OwnerId': '012345678912',
114+
'PerformanceMode': 'generalPurpose',
115+
'SizeInBytes': {
116+
'Value': 6144,
117+
},
118+
'Tags': [
119+
{
120+
'Key': 'Name',
121+
'Value': 'MyFileSystem',
122+
},
123+
],
124+
},
125+
],
126+
'ResponseMetadata': {
127+
'...': '...',
128+
},
129+
}
130+
103131
efs_describe_mount_targets_response = {
104132
'MountTargets': [
105133
{
@@ -237,7 +265,7 @@
237265

238266

239267

240-
EFS = {'describe_file_systems_no_marker': efs_describe_file_systems_no_marker_response, 'describe_mount_targets': efs_describe_mount_targets_response, 'describe_mount_target_security_groups': efs_describe_mount_target_security_groups_response}
268+
EFS = {'describe_file_systems_no_marker': efs_describe_file_systems_no_marker_response, 'describe_file_systems_marker': efs_describe_file_systems_marker_response, 'describe_mount_targets': efs_describe_mount_targets_response, 'describe_mount_target_security_groups': efs_describe_mount_target_security_groups_response}
241269
CFN = {'describe_stacks': cfn_describe_stacks_response, 'create_stack': cfn_create_stack_response}
242270
LAMBDA = {'upload': lambda_invoke_upload_response, 'delete': lambda_invoke_delete_response, 'list': lambda_invoke_list_response, 'make_dir': lambda_invoke_make_dir_response, 'download': lambda_invoke_download_response}
243271
EC2 = {'describe_sec_rules': ec2_describe_security_group_rules_response}

test/unit/api/test_app.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,40 @@ def test_list_filesystems(test_client, efs_client_stub, cfn_client_stub):
4646
print('PASS')
4747

4848

49+
def test_list_filesystems_paginated(test_client, efs_client_stub, cfn_client_stub):
50+
print('GET /filesystems')
51+
52+
efs_client_stub.add_response(
53+
'describe_file_systems',
54+
expected_params={'MaxItems': 10, 'Marker': 'xyz'},
55+
service_response=EFS['describe_file_systems_marker']
56+
)
57+
58+
cfn_client_stub.add_response(
59+
'describe_stacks',
60+
expected_params={'StackName': f'testStackPrefix-ManagedResources-{test_filesystem_id}'},
61+
service_response=CFN['describe_stacks']
62+
)
63+
response = test_client.http.get('/filesystems?cursor=xyz')
64+
65+
formatted_response = json.loads(response.body)
66+
67+
print(formatted_response)
68+
69+
expected_response_keys = ['filesystems']
70+
71+
assert all(item in formatted_response.keys() for item in expected_response_keys)
72+
73+
filesystems = formatted_response['filesystems']
74+
75+
assert isinstance(filesystems, list)
76+
assert filesystems[0]['name'] == 'MyFileSystem'
77+
assert filesystems[0]['managed'] is True
78+
assert filesystems[0]['file_system_id'] == f'{test_filesystem_id}'
79+
80+
print('PASS')
81+
82+
4983
def test_get_netinfo_for_filesystem(test_client, efs_client_stub, ec2_client_stub):
5084
print(f'GET /filesystems/{test_filesystem_id}/netinfo')
5185

test/unit/coverage.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" ?>
2-
<coverage version="6.5.0" timestamp="1665697912978" lines-valid="413" lines-covered="330" line-rate="0.799" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
2+
<coverage version="6.5.0" timestamp="1665699515859" lines-valid="413" lines-covered="333" line-rate="0.8063" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
33
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
44
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
55
<sources>
@@ -133,9 +133,9 @@
133133
</class>
134134
</classes>
135135
</package>
136-
<package name=".Users.brandold.werkplace.solutions.simple-file-manager-for-amazon-efs.source.api" line-rate="0.8074" branch-rate="0" complexity="0">
136+
<package name=".Users.brandold.werkplace.solutions.simple-file-manager-for-amazon-efs.source.api" line-rate="0.8176" branch-rate="0" complexity="0">
137137
<classes>
138-
<class name="app.py" filename="/Users/brandold/werkplace/solutions/simple-file-manager-for-amazon-efs/source/api/app.py" complexity="0" line-rate="0.8074" branch-rate="0">
138+
<class name="app.py" filename="/Users/brandold/werkplace/solutions/simple-file-manager-for-amazon-efs/source/api/app.py" complexity="0" line-rate="0.8176" branch-rate="0">
139139
<methods/>
140140
<lines>
141141
<line number="13" hits="1"/>
@@ -266,13 +266,13 @@
266266
<line number="317" hits="1"/>
267267
<line number="319" hits="1"/>
268268
<line number="321" hits="1"/>
269-
<line number="322" hits="0"/>
270-
<line number="323" hits="0"/>
269+
<line number="322" hits="1"/>
270+
<line number="323" hits="1"/>
271271
<line number="324" hits="0"/>
272272
<line number="325" hits="0"/>
273273
<line number="327" hits="1"/>
274274
<line number="328" hits="1"/>
275-
<line number="329" hits="0"/>
275+
<line number="329" hits="1"/>
276276
<line number="334" hits="1"/>
277277
<line number="337" hits="0"/>
278278
<line number="338" hits="0"/>

0 commit comments

Comments
 (0)