Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
communications-backbone
Commits
caf957c9
Unverified
Commit
caf957c9
authored
2 years ago
by
Dan Jones
Browse files
Options
Download
Email Patches
Plain Diff
tests: mock getmtime for all client tests
parent
655bff35
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
tests/api_client_test.py
tests/api_client_test.py
+15
-5
tests/models/client_model_test.py
tests/models/client_model_test.py
+11
-9
No files found.
tests/api_client_test.py
View file @
caf957c9
...
...
@@ -11,7 +11,9 @@ def test_get_client(mock_clients):
app
=
create_app
()
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
,
app
.
test_client
()
as
app_test_client
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
,
app
.
test_client
()
as
app_test_client
:
response
=
app_test_client
.
get
(
"/client"
)
assert
response
.
status_code
==
200
assert
len
(
response
.
json
.
keys
())
==
2
...
...
@@ -23,7 +25,9 @@ def test_get_client_1(mock_clients):
app
=
create_app
()
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
,
app
.
test_client
()
as
app_test_client
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
,
app
.
test_client
()
as
app_test_client
:
response
=
app_test_client
.
get
(
"/client/client-1"
)
assert
response
.
status_code
==
200
assert
"client_id"
in
response
.
json
...
...
@@ -37,7 +41,9 @@ def test_post_client(mock_clients, mock_new_client):
app
=
create_app
()
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
,
app
.
test_client
()
as
app_test_client
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
,
app
.
test_client
()
as
app_test_client
:
response
=
app_test_client
.
post
(
"/client"
,
json
=
mock_new_client
)
assert
response
.
status_code
==
201
assert
"client_id"
in
response
.
json
...
...
@@ -51,7 +57,9 @@ def test_put_client_1(mock_clients):
app
=
create_app
()
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
,
app
.
test_client
()
as
app_test_client
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
,
app
.
test_client
()
as
app_test_client
:
response
=
app_test_client
.
get
(
"/client/client-1"
)
client_1
=
response
.
json
print
(
client_1
)
...
...
@@ -71,6 +79,8 @@ def test_delete_client_1(mock_clients):
app
=
create_app
()
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
,
app
.
test_client
()
as
app_test_client
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
,
app
.
test_client
()
as
app_test_client
:
response
=
app_test_client
.
delete
(
"/client/client-1"
)
assert
response
.
status_code
==
204
This diff is collapsed.
Click to expand it.
tests/models/client_model_test.py
View file @
caf957c9
...
...
@@ -11,7 +11,7 @@ def test_init_with_clients(mock_clients):
# File is read on __init__
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
assert
len
(
clients_file
.
clients
.
keys
())
==
2
assert
"client-1"
in
clients_file
.
clients
.
keys
()
...
...
@@ -19,7 +19,9 @@ def test_init_with_clients(mock_clients):
def
test_init_no_clients_file
():
# Handles FileNotFound on __init__
with
patch
(
"builtins.open"
,
side_effect
=
FileNotFoundError
())
as
mock_file_open
:
with
patch
(
"builtins.open"
,
side_effect
=
FileNotFoundError
()
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
assert
len
(
clients_file
.
clients
.
keys
())
==
0
assert
"client-1"
not
in
clients_file
.
clients
.
keys
()
...
...
@@ -52,7 +54,7 @@ def test_get_modified(mock_clients):
def
test_find_existing
(
mock_clients
):
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
client
=
clients_file
.
find
(
"client-1"
)
assert
client
is
not
None
...
...
@@ -63,7 +65,7 @@ def test_find_existing(mock_clients):
def
test_find_nonexisting
(
mock_clients
):
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
client
=
clients_file
.
find
(
"client-3"
)
assert
client
is
None
...
...
@@ -73,7 +75,7 @@ def test_find_nonexisting(mock_clients):
def
test_add
(
mock_clients
,
mock_new_client
):
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
client
=
clients_file
.
add
(
mock_new_client
)
assert
client
[
"client_id"
]
in
clients_file
.
clients
...
...
@@ -84,7 +86,7 @@ def test_add(mock_clients, mock_new_client):
def
test_remove
(
mock_clients
):
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
client
=
clients_file
.
find
(
"client-2"
)
clients_file
.
remove
(
client
)
...
...
@@ -96,7 +98,7 @@ def test_remove(mock_clients):
def
test_update
(
mock_clients
):
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
client
=
clients_file
.
find
(
"client-1"
)
assert
client
[
"subscription"
]
==
"soar.#"
...
...
@@ -111,7 +113,7 @@ def test_update(mock_clients):
def
test_save
(
mock_clients
):
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
clients_file
=
ClientModel
()
mock_file_open
.
assert_any_call
(
"./data/clients.json"
,
"r"
)
clients_file
.
save
()
...
...
@@ -123,7 +125,7 @@ def test_save(mock_clients):
def
test_secret
(
mock_clients
):
with
patch
(
"builtins.open"
,
mock_open
(
read_data
=
json
.
dumps
(
mock_clients
))
)
as
mock_file_open
:
)
as
mock_file_open
,
patch
(
"os.path.getmtime"
,
return_value
=
3
)
as
mock_getmtime
:
secret_pattern
=
"^[A-Za-z0-9]+$"
clients_file
=
ClientModel
()
secret
=
clients_file
.
secret
()
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment