willisapi-client 1.0__tar.gz → 1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {willisapi_client-1.0 → willisapi_client-1.1}/PKG-INFO +1 -1
- willisapi_client-1.1/setup.py +37 -0
- willisapi_client-1.1/tests/test_auth.py +161 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/tests/test_csv_validation.py +86 -39
- {willisapi_client-1.0 → willisapi_client-1.1}/tests/test_download.py +13 -21
- willisapi_client-1.1/tests/test_upload.py +86 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/__init__.py +1 -6
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/__version__.py +1 -1
- willisapi_client-1.1/willisapi_client/logging_setup.py +4 -0
- willisapi_client-1.1/willisapi_client/services/__init__.py +1 -0
- willisapi_client-1.1/willisapi_client/services/api.py +6 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/auth/auth_utils.py +18 -11
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/auth/login_manager.py +18 -6
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/auth/user_manager.py +29 -8
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/download/download_handler.py +8 -3
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/download/download_utils.py +93 -32
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/exceptions.py +5 -1
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/upload/csv_validation.py +115 -57
- willisapi_client-1.1/willisapi_client/services/upload/language_choices.py +82 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/upload/multipart_upload_handler.py +14 -8
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/upload/upload_utils.py +97 -56
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/upload/utils.py +1 -1
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/timer.py +6 -4
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/willisapi_client.py +11 -12
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client.egg-info/PKG-INFO +1 -1
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client.egg-info/SOURCES.txt +1 -0
- willisapi_client-1.0/setup.py +0 -36
- willisapi_client-1.0/tests/test_auth.py +0 -130
- willisapi_client-1.0/tests/test_upload.py +0 -43
- willisapi_client-1.0/willisapi_client/logging_setup.py +0 -4
- willisapi_client-1.0/willisapi_client/services/__init__.py +0 -1
- willisapi_client-1.0/willisapi_client/services/api.py +0 -13
- {willisapi_client-1.0 → willisapi_client-1.1}/LICENSE +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/MANIFEST.in +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/README.md +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/RELEASE.md +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/requirements.txt +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/setup.cfg +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/auth/__init__.py +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/download/__init__.py +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client/services/upload/__init__.py +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client.egg-info/dependency_links.txt +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client.egg-info/not-zip-safe +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client.egg-info/requires.txt +0 -0
- {willisapi_client-1.0 → willisapi_client-1.1}/willisapi_client.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# website: https://www.brooklyn.health
|
|
2
|
+
|
|
3
|
+
import setuptools
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
# Version details
|
|
7
|
+
current_dir = os.path.abspath(os.path.dirname(__file__))
|
|
8
|
+
details = {}
|
|
9
|
+
with open(os.path.join(current_dir, "willisapi_client", "__version__.py"), "r") as fv:
|
|
10
|
+
exec(fv.read(), details)
|
|
11
|
+
|
|
12
|
+
# Long description
|
|
13
|
+
with open("README.md", "r") as fh:
|
|
14
|
+
long_description = fh.read()
|
|
15
|
+
|
|
16
|
+
# Dependencies
|
|
17
|
+
with open("requirements.txt", "r") as fp:
|
|
18
|
+
install_requires = fp.read().split("\n")
|
|
19
|
+
while "" in install_requires:
|
|
20
|
+
install_requires.remove("")
|
|
21
|
+
|
|
22
|
+
setuptools.setup(
|
|
23
|
+
name=details["__client__"],
|
|
24
|
+
version=details["__latestVersion__"],
|
|
25
|
+
description=details["__short_description__"],
|
|
26
|
+
long_description=long_description,
|
|
27
|
+
long_description_content_type=details["__content_type__"],
|
|
28
|
+
url=details["__url__"],
|
|
29
|
+
author="bklynhlth",
|
|
30
|
+
python_requires=">=3.9",
|
|
31
|
+
install_requires=install_requires,
|
|
32
|
+
author_email="admin@brooklyn.health",
|
|
33
|
+
packages=setuptools.find_packages(exclude=["tests*"]),
|
|
34
|
+
include_package_data=True,
|
|
35
|
+
zip_safe=False,
|
|
36
|
+
license="Apache",
|
|
37
|
+
)
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
from willisapi_client.services.auth.login_manager import login
|
|
2
|
+
from willisapi_client.services.auth.user_manager import create_user
|
|
3
|
+
from unittest.mock import patch
|
|
4
|
+
from datetime import timedelta, datetime
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestLoginFunction:
|
|
8
|
+
def setup_method(self):
|
|
9
|
+
self.dt = datetime.now()
|
|
10
|
+
self.username = "dummy"
|
|
11
|
+
self.password = "password"
|
|
12
|
+
self.id_token = "dummy_token"
|
|
13
|
+
self.expires_in = 100
|
|
14
|
+
self.expires_in_date = str(
|
|
15
|
+
self.dt.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
16
|
+
+ timedelta(seconds=self.expires_in)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.login")
|
|
20
|
+
def test_login_failed(self, mocked_login):
|
|
21
|
+
mocked_login.return_value = {}
|
|
22
|
+
key, expire_in = login("", "")
|
|
23
|
+
assert key == None
|
|
24
|
+
assert expire_in == None
|
|
25
|
+
|
|
26
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.login")
|
|
27
|
+
def test_login_success(self, mocked_login):
|
|
28
|
+
mocked_login.return_value = {
|
|
29
|
+
"status_code": 200,
|
|
30
|
+
"result": {"id_token": self.id_token, "expires_in": self.expires_in},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
key, expire_in = login(self.username, self.password)
|
|
34
|
+
expire_in = str(self.dt.replace(hour=0, minute=1, second=40, microsecond=0))
|
|
35
|
+
assert key == self.id_token
|
|
36
|
+
assert expire_in == self.expires_in_date
|
|
37
|
+
|
|
38
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.login")
|
|
39
|
+
def test_login_400_status(self, mocked_login):
|
|
40
|
+
mocked_login.return_value = {
|
|
41
|
+
"status_code": 400,
|
|
42
|
+
"result": {"id_token": self.id_token, "expires_in": self.expires_in},
|
|
43
|
+
}
|
|
44
|
+
key, expire_in = login(self.username, self.password)
|
|
45
|
+
assert key == None
|
|
46
|
+
assert expire_in == None
|
|
47
|
+
|
|
48
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.login")
|
|
49
|
+
def test_login_403_status(self, mocked_login):
|
|
50
|
+
mocked_login.return_value = {
|
|
51
|
+
"status_code": 403,
|
|
52
|
+
"result": {"id_token": self.id_token, "expires_in": self.expires_in},
|
|
53
|
+
}
|
|
54
|
+
key, expire_in = login(self.username, self.password)
|
|
55
|
+
assert key == None
|
|
56
|
+
assert expire_in == None
|
|
57
|
+
|
|
58
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.login")
|
|
59
|
+
def test_login_500_status(self, mocked_login):
|
|
60
|
+
mocked_login.return_value = {
|
|
61
|
+
"status_code": 500,
|
|
62
|
+
"result": {"id_token": self.id_token, "expires_in": self.expires_in},
|
|
63
|
+
}
|
|
64
|
+
key, expire_in = login(self.username, self.password)
|
|
65
|
+
assert key == None
|
|
66
|
+
assert expire_in == None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class TestSignupFunction:
|
|
70
|
+
def setup_method(self):
|
|
71
|
+
self.username = "dummy"
|
|
72
|
+
self.password = "password"
|
|
73
|
+
self.admin_key = "admin_key"
|
|
74
|
+
self.non_admin_key = "non_admin_key"
|
|
75
|
+
self.client_email = "client@email.com"
|
|
76
|
+
self.client_name = "client"
|
|
77
|
+
self.first_name = "First"
|
|
78
|
+
self.last_name = "Last"
|
|
79
|
+
|
|
80
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.signup")
|
|
81
|
+
def test_signup_failed(self, mocked_signup):
|
|
82
|
+
mocked_signup.return_value = {
|
|
83
|
+
"status_code": 200,
|
|
84
|
+
"message": "Not an admin user",
|
|
85
|
+
}
|
|
86
|
+
message = create_user(
|
|
87
|
+
self.non_admin_key,
|
|
88
|
+
self.client_email,
|
|
89
|
+
self.client_name,
|
|
90
|
+
self.first_name,
|
|
91
|
+
self.last_name,
|
|
92
|
+
)
|
|
93
|
+
assert message == "Not an admin user"
|
|
94
|
+
|
|
95
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.signup")
|
|
96
|
+
def test_signup_success(self, mocked_signup):
|
|
97
|
+
mocked_signup.return_value = {"status_code": 200, "message": "User created"}
|
|
98
|
+
message = create_user(
|
|
99
|
+
self.admin_key,
|
|
100
|
+
self.client_email,
|
|
101
|
+
self.client_name,
|
|
102
|
+
self.first_name,
|
|
103
|
+
self.last_name,
|
|
104
|
+
)
|
|
105
|
+
assert message == "User created"
|
|
106
|
+
|
|
107
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.signup")
|
|
108
|
+
def test_signup_failed_400_status(self, mocked_signup):
|
|
109
|
+
mocked_signup.return_value = {
|
|
110
|
+
"status_code": 400,
|
|
111
|
+
}
|
|
112
|
+
message = create_user(
|
|
113
|
+
self.admin_key,
|
|
114
|
+
self.client_email,
|
|
115
|
+
self.client_name,
|
|
116
|
+
self.first_name,
|
|
117
|
+
self.last_name,
|
|
118
|
+
)
|
|
119
|
+
assert message == None
|
|
120
|
+
|
|
121
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.signup")
|
|
122
|
+
def test_signup_failed_500_status(self, mocked_signup):
|
|
123
|
+
mocked_signup.return_value = {
|
|
124
|
+
"status_code": 500,
|
|
125
|
+
}
|
|
126
|
+
message = create_user(
|
|
127
|
+
self.admin_key,
|
|
128
|
+
self.client_email,
|
|
129
|
+
self.client_name,
|
|
130
|
+
self.first_name,
|
|
131
|
+
self.last_name,
|
|
132
|
+
)
|
|
133
|
+
assert message == None
|
|
134
|
+
|
|
135
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.signup")
|
|
136
|
+
def test_signup_failed_401_status(self, mocked_signup):
|
|
137
|
+
mocked_signup.return_value = {
|
|
138
|
+
"status_code": 401,
|
|
139
|
+
}
|
|
140
|
+
message = create_user(
|
|
141
|
+
self.admin_key,
|
|
142
|
+
self.client_email,
|
|
143
|
+
self.client_name,
|
|
144
|
+
self.first_name,
|
|
145
|
+
self.last_name,
|
|
146
|
+
)
|
|
147
|
+
assert message == None
|
|
148
|
+
|
|
149
|
+
@patch("willisapi_client.services.auth.login_manager.AuthUtils.signup")
|
|
150
|
+
def test_signup_failed_403_status(self, mocked_signup):
|
|
151
|
+
mocked_signup.return_value = {
|
|
152
|
+
"status_code": 403,
|
|
153
|
+
}
|
|
154
|
+
message = create_user(
|
|
155
|
+
self.admin_key,
|
|
156
|
+
self.client_email,
|
|
157
|
+
self.client_name,
|
|
158
|
+
self.first_name,
|
|
159
|
+
self.last_name,
|
|
160
|
+
)
|
|
161
|
+
assert message == None
|
|
@@ -2,6 +2,7 @@ from willisapi_client.services.upload.csv_validation import CSVValidation
|
|
|
2
2
|
|
|
3
3
|
from unittest.mock import patch
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
class TestCSVValidation:
|
|
6
7
|
def test_directory(self):
|
|
7
8
|
csv = CSVValidation(file_path="/")
|
|
@@ -15,8 +16,10 @@ class TestCSVValidation:
|
|
|
15
16
|
csv = CSVValidation(file_path="/metadata.csv")
|
|
16
17
|
assert csv._is_valid() == False
|
|
17
18
|
|
|
18
|
-
@patch(
|
|
19
|
-
|
|
19
|
+
@patch(
|
|
20
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
21
|
+
)
|
|
22
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
20
23
|
def test_correct_csv_file(self, mocked_headers, mocked_file):
|
|
21
24
|
mocked_headers.return_value = True
|
|
22
25
|
mocked_file.return_value = True
|
|
@@ -26,10 +29,16 @@ class TestCSVValidation:
|
|
|
26
29
|
assert csv._is_valid_file_ext() == True
|
|
27
30
|
assert csv.get_filename() == "metadata.csv"
|
|
28
31
|
|
|
29
|
-
@patch(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
@patch(
|
|
33
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
34
|
+
)
|
|
35
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
36
|
+
@patch(
|
|
37
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_file_path_valid"
|
|
38
|
+
)
|
|
39
|
+
def test_csv_row_validation_success(
|
|
40
|
+
self, mocked_upload_file, mocked_file, mocked_headers
|
|
41
|
+
):
|
|
33
42
|
mocked_headers.return_value = True
|
|
34
43
|
mocked_file.return_value = True
|
|
35
44
|
mocked_upload_file.return_value = (True, "")
|
|
@@ -41,14 +50,21 @@ class TestCSVValidation:
|
|
|
41
50
|
"workflow_tags": "speech_characteristics",
|
|
42
51
|
"pt_id_external": "qwerty",
|
|
43
52
|
"time_collected": "2023-02-02",
|
|
44
|
-
|
|
53
|
+
"language": "en-US",
|
|
54
|
+
}
|
|
45
55
|
is_valid, _ = csv.validate_row(row)
|
|
46
56
|
assert is_valid == True
|
|
47
57
|
|
|
48
|
-
@patch(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
@patch(
|
|
59
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
60
|
+
)
|
|
61
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
62
|
+
@patch(
|
|
63
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_file_path_valid"
|
|
64
|
+
)
|
|
65
|
+
def test_csv_row_validation_fail_empty_project(
|
|
66
|
+
self, mocked_upload_file, mocked_file, mocked_headers
|
|
67
|
+
):
|
|
52
68
|
mocked_headers.return_value = True
|
|
53
69
|
mocked_file.return_value = True
|
|
54
70
|
mocked_upload_file.return_value = (True, "")
|
|
@@ -60,14 +76,20 @@ class TestCSVValidation:
|
|
|
60
76
|
"workflow_tags": "speech_characteristics",
|
|
61
77
|
"pt_id_external": "qwerty",
|
|
62
78
|
"time_collected": "2023-02-02",
|
|
63
|
-
}
|
|
79
|
+
}
|
|
64
80
|
is_valid, _ = csv.validate_row(row)
|
|
65
81
|
assert is_valid == False
|
|
66
|
-
|
|
67
|
-
@patch(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
|
|
83
|
+
@patch(
|
|
84
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
85
|
+
)
|
|
86
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
87
|
+
@patch(
|
|
88
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_file_path_valid"
|
|
89
|
+
)
|
|
90
|
+
def test_csv_row_validation_failed_incorrect_file(
|
|
91
|
+
self, mocked_upload_file, mocked_file, mocked_headers
|
|
92
|
+
):
|
|
71
93
|
mocked_headers.return_value = True
|
|
72
94
|
mocked_file.return_value = True
|
|
73
95
|
mocked_upload_file.return_value = (False, "Error")
|
|
@@ -79,14 +101,20 @@ class TestCSVValidation:
|
|
|
79
101
|
"workflow_tags": "speech_characteristics",
|
|
80
102
|
"pt_id_external": "qwerty",
|
|
81
103
|
"time_collected": "2023-02-02",
|
|
82
|
-
}
|
|
104
|
+
}
|
|
83
105
|
is_valid, _ = csv.validate_row(row)
|
|
84
106
|
assert is_valid == False
|
|
85
107
|
|
|
86
|
-
@patch(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
108
|
+
@patch(
|
|
109
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
110
|
+
)
|
|
111
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
112
|
+
@patch(
|
|
113
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_file_path_valid"
|
|
114
|
+
)
|
|
115
|
+
def test_csv_row_validation_failed_incorrect_wfts(
|
|
116
|
+
self, mocked_upload_file, mocked_file, mocked_headers
|
|
117
|
+
):
|
|
90
118
|
mocked_headers.return_value = True
|
|
91
119
|
mocked_file.return_value = True
|
|
92
120
|
mocked_upload_file.return_value = (True, None)
|
|
@@ -98,14 +126,20 @@ class TestCSVValidation:
|
|
|
98
126
|
"workflow_tags": "wrong_tag",
|
|
99
127
|
"pt_id_external": "qwerty",
|
|
100
128
|
"time_collected": "2023-02-02",
|
|
101
|
-
}
|
|
129
|
+
}
|
|
102
130
|
is_valid, _ = csv.validate_row(row)
|
|
103
131
|
assert is_valid == False
|
|
104
132
|
|
|
105
|
-
@patch(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
133
|
+
@patch(
|
|
134
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
135
|
+
)
|
|
136
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
137
|
+
@patch(
|
|
138
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_file_path_valid"
|
|
139
|
+
)
|
|
140
|
+
def test_csv_row_validation_dynamic_wfts(
|
|
141
|
+
self, mocked_upload_file, mocked_file, mocked_headers
|
|
142
|
+
):
|
|
109
143
|
mocked_headers.return_value = True
|
|
110
144
|
mocked_file.return_value = True
|
|
111
145
|
mocked_upload_file.return_value = (True, None)
|
|
@@ -117,14 +151,21 @@ class TestCSVValidation:
|
|
|
117
151
|
"workflow_tags": "scale_abc,speech_transcription_dummy",
|
|
118
152
|
"pt_id_external": "qwerty",
|
|
119
153
|
"time_collected": "2023-02-02",
|
|
120
|
-
|
|
154
|
+
"language": None,
|
|
155
|
+
}
|
|
121
156
|
is_valid, _ = csv.validate_row(row)
|
|
122
157
|
assert is_valid == True
|
|
123
158
|
|
|
124
|
-
@patch(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
159
|
+
@patch(
|
|
160
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
161
|
+
)
|
|
162
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
163
|
+
@patch(
|
|
164
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_file_path_valid"
|
|
165
|
+
)
|
|
166
|
+
def test_csv_row_validation_failed_empty_pt_id(
|
|
167
|
+
self, mocked_upload_file, mocked_file, mocked_headers
|
|
168
|
+
):
|
|
128
169
|
mocked_headers.return_value = True
|
|
129
170
|
mocked_file.return_value = True
|
|
130
171
|
mocked_upload_file.return_value = (True, None)
|
|
@@ -136,14 +177,20 @@ class TestCSVValidation:
|
|
|
136
177
|
"workflow_tags": "speech_characteristics",
|
|
137
178
|
"pt_id_external": "",
|
|
138
179
|
"time_collected": "2023-02-02",
|
|
139
|
-
}
|
|
180
|
+
}
|
|
140
181
|
is_valid, _ = csv.validate_row(row)
|
|
141
182
|
assert is_valid == False
|
|
142
183
|
|
|
143
|
-
@patch(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
184
|
+
@patch(
|
|
185
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_valid_headers"
|
|
186
|
+
)
|
|
187
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_file")
|
|
188
|
+
@patch(
|
|
189
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation._is_file_path_valid"
|
|
190
|
+
)
|
|
191
|
+
def test_csv_row_validation_failed_incorrect_time_collected(
|
|
192
|
+
self, mocked_upload_file, mocked_file, mocked_headers
|
|
193
|
+
):
|
|
147
194
|
mocked_headers.return_value = True
|
|
148
195
|
mocked_file.return_value = True
|
|
149
196
|
mocked_upload_file.return_value = (True, None)
|
|
@@ -155,6 +202,6 @@ class TestCSVValidation:
|
|
|
155
202
|
"workflow_tags": "speech_characteristics",
|
|
156
203
|
"pt_id_external": "",
|
|
157
204
|
"time_collected": "20-02-02",
|
|
158
|
-
}
|
|
205
|
+
}
|
|
159
206
|
is_valid, _ = csv.validate_row(row)
|
|
160
|
-
assert is_valid == False
|
|
207
|
+
assert is_valid == False
|
|
@@ -4,42 +4,37 @@ import json
|
|
|
4
4
|
|
|
5
5
|
from willisapi_client.services.download.download_handler import download
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
class TestDownloadFunction:
|
|
8
9
|
def setup(self):
|
|
9
10
|
self.key = "dummy"
|
|
10
11
|
self.project_name = "project"
|
|
11
12
|
|
|
12
|
-
@patch(
|
|
13
|
+
@patch("willisapi_client.services.download.download_utils.DownloadUtils.request")
|
|
13
14
|
def test_download_failed(self, mocked_data):
|
|
14
15
|
mocked_data.return_value = {}
|
|
15
16
|
data = download(self.key, self.project_name)
|
|
16
17
|
assert data.empty == True
|
|
17
18
|
|
|
18
|
-
@patch(
|
|
19
|
+
@patch("willisapi_client.services.download.download_utils.DownloadUtils.request")
|
|
19
20
|
def test_download_unauthorised(self, mocked_data):
|
|
20
|
-
mocked_data.return_value = {
|
|
21
|
-
"status_code": 403
|
|
22
|
-
}
|
|
21
|
+
mocked_data.return_value = {"status_code": 403}
|
|
23
22
|
data = download(self.key, self.project_name)
|
|
24
23
|
assert data.empty == True
|
|
25
24
|
|
|
26
|
-
@patch(
|
|
25
|
+
@patch("willisapi_client.services.download.download_utils.DownloadUtils.request")
|
|
27
26
|
def test_download_missing_auth(self, mocked_data):
|
|
28
|
-
mocked_data.return_value = {
|
|
29
|
-
"status_code": 401
|
|
30
|
-
}
|
|
27
|
+
mocked_data.return_value = {"status_code": 401}
|
|
31
28
|
data = download(self.key, self.project_name)
|
|
32
29
|
assert data.empty == True
|
|
33
30
|
|
|
34
|
-
@patch(
|
|
31
|
+
@patch("willisapi_client.services.download.download_utils.DownloadUtils.request")
|
|
35
32
|
def test_download_500_status(self, mocked_data):
|
|
36
|
-
mocked_data.return_value = {
|
|
37
|
-
"status_code": 500
|
|
38
|
-
}
|
|
33
|
+
mocked_data.return_value = {"status_code": 500}
|
|
39
34
|
data = download(self.key, self.project_name)
|
|
40
35
|
assert data.empty == True
|
|
41
36
|
|
|
42
|
-
@patch(
|
|
37
|
+
@patch("willisapi_client.services.download.download_utils.DownloadUtils.request")
|
|
43
38
|
def test_download_no_items_from_api(self, mocked_data):
|
|
44
39
|
mocked_data.return_value = {
|
|
45
40
|
"status_code": 200,
|
|
@@ -48,16 +43,13 @@ class TestDownloadFunction:
|
|
|
48
43
|
data = download(self.key, self.project_name)
|
|
49
44
|
assert data.empty == True
|
|
50
45
|
|
|
51
|
-
@patch(
|
|
46
|
+
@patch("willisapi_client.services.download.download_utils.DownloadUtils.request")
|
|
52
47
|
def test_download_success(self, mocked_data):
|
|
53
|
-
with open(
|
|
48
|
+
with open("tests/test.json") as json_file:
|
|
54
49
|
data = json.load(json_file)
|
|
55
50
|
mocked_data.return_value = data
|
|
56
51
|
data = download(self.key, self.project_name)
|
|
57
52
|
assert data.empty == False
|
|
58
|
-
assert data.filename.tolist()[0] ==
|
|
59
|
-
assert data.pt_id_external.tolist()[0] ==
|
|
53
|
+
assert data.filename.tolist()[0] == "test_video.mp4"
|
|
54
|
+
assert data.pt_id_external.tolist()[0] == "pt_id_external"
|
|
60
55
|
assert len(data.index) == 1
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
from willisapi_client.services.upload.multipart_upload_handler import upload
|
|
5
|
+
from willisapi_client.services.upload.csv_validation import CSVValidation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestUpload:
|
|
9
|
+
def setup(self):
|
|
10
|
+
self.key = "dummy key"
|
|
11
|
+
self.metadata = "data.csv"
|
|
12
|
+
self.df_row = [
|
|
13
|
+
"dev_testing",
|
|
14
|
+
"video.mp4",
|
|
15
|
+
"tags",
|
|
16
|
+
"qwerty",
|
|
17
|
+
"2023-22-22",
|
|
18
|
+
]
|
|
19
|
+
self.df_cols = [
|
|
20
|
+
"project_name",
|
|
21
|
+
"file_path",
|
|
22
|
+
"workflow_tags",
|
|
23
|
+
"pt_id_external",
|
|
24
|
+
"time_collected",
|
|
25
|
+
]
|
|
26
|
+
self.response_df_cols = ["filename", "upload_status", "upload_message"]
|
|
27
|
+
|
|
28
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation.validate_row")
|
|
29
|
+
@patch(
|
|
30
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation.get_dataframe"
|
|
31
|
+
)
|
|
32
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_valid")
|
|
33
|
+
def test_upload_row_validation_failed(
|
|
34
|
+
self, mock_valid_csv, mocked_df, mock_row_validation
|
|
35
|
+
):
|
|
36
|
+
mock_valid_csv.return_value = True
|
|
37
|
+
mocked_df.return_value = pd.DataFrame([self.df_row], columns=self.df_cols)
|
|
38
|
+
mock_row_validation.return_value = False, "Err"
|
|
39
|
+
df = upload(self.key, self.metadata)
|
|
40
|
+
num = len(df[df["upload_status"] == "fail"])
|
|
41
|
+
assert num == 1
|
|
42
|
+
assert list(df.columns) == self.response_df_cols
|
|
43
|
+
assert df.iloc[0].filename == "video.mp4"
|
|
44
|
+
assert df.iloc[0].upload_status == "fail"
|
|
45
|
+
|
|
46
|
+
@patch("willisapi_client.services.upload.upload_utils.UploadUtils.upload")
|
|
47
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation.validate_row")
|
|
48
|
+
@patch(
|
|
49
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation.get_dataframe"
|
|
50
|
+
)
|
|
51
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_valid")
|
|
52
|
+
def test_upload_success(
|
|
53
|
+
self, mock_valid_csv, mocked_df, mock_row_validation, mocked_upload
|
|
54
|
+
):
|
|
55
|
+
mock_valid_csv.return_value = True
|
|
56
|
+
mocked_df.return_value = pd.DataFrame([self.df_row], columns=self.df_cols)
|
|
57
|
+
mock_row_validation.return_value = True, None
|
|
58
|
+
mocked_upload.return_value = True, None
|
|
59
|
+
df = upload(self.key, self.metadata)
|
|
60
|
+
num = len(df[df["upload_status"] == "success"])
|
|
61
|
+
assert num == 1
|
|
62
|
+
assert list(df.columns) == self.response_df_cols
|
|
63
|
+
assert df.iloc[0].filename == "video.mp4"
|
|
64
|
+
assert df.iloc[0].upload_status == "success"
|
|
65
|
+
assert df.iloc[0].upload_message == None
|
|
66
|
+
|
|
67
|
+
@patch("willisapi_client.services.upload.upload_utils.UploadUtils.upload")
|
|
68
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation.validate_row")
|
|
69
|
+
@patch(
|
|
70
|
+
"willisapi_client.services.upload.csv_validation.CSVValidation.get_dataframe"
|
|
71
|
+
)
|
|
72
|
+
@patch("willisapi_client.services.upload.csv_validation.CSVValidation._is_valid")
|
|
73
|
+
def test_re_upload_success(
|
|
74
|
+
self, mock_valid_csv, mocked_df, mock_row_validation, mocked_upload
|
|
75
|
+
):
|
|
76
|
+
mock_valid_csv.return_value = True
|
|
77
|
+
mocked_df.return_value = pd.DataFrame([self.df_row], columns=self.df_cols)
|
|
78
|
+
mock_row_validation.return_value = True, None
|
|
79
|
+
mocked_upload.return_value = True, None
|
|
80
|
+
df = upload(self.key, self.metadata, reupload="force")
|
|
81
|
+
num = len(df[df["upload_status"] == "success"])
|
|
82
|
+
assert num == 1
|
|
83
|
+
assert list(df.columns) == self.response_df_cols
|
|
84
|
+
assert df.iloc[0].filename == "video.mp4"
|
|
85
|
+
assert df.iloc[0].upload_status == "success"
|
|
86
|
+
assert df.iloc[0].upload_message == None
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
# website: https://www.brooklyn.health
|
|
2
2
|
|
|
3
3
|
# import the required packages
|
|
4
|
-
from willisapi_client.services.api import
|
|
5
|
-
login,
|
|
6
|
-
create_user,
|
|
7
|
-
upload,
|
|
8
|
-
download
|
|
9
|
-
)
|
|
4
|
+
from willisapi_client.services.api import login, create_user, upload, download
|
|
10
5
|
|
|
11
6
|
__all__ = ["login", "create_user", "upload", "download"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Version details for willisapi_client
|
|
2
2
|
"""
|
|
3
3
|
__client__ = "willisapi_client"
|
|
4
|
-
__latestVersion__ = "1.
|
|
4
|
+
__latestVersion__ = "1.1"
|
|
5
5
|
__url__ = "https://github.com/bklynhlth/willsiapi_client"
|
|
6
6
|
__short_description__ = "A Python client for willisapi"
|
|
7
7
|
__content_type__ = "text/markdown"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# website: http://www.brooklyn.health
|