API - add missing tests on user data export
This commit is contained in:
parent
d57133f839
commit
8549547db4
@ -3035,11 +3035,38 @@ class TestGetUserDataExportRequest(ApiTestCaseMixin):
|
|||||||
assert data["status"] == "success"
|
assert data["status"] == "success"
|
||||||
assert data["request"] is None
|
assert data["request"] is None
|
||||||
|
|
||||||
def test_it_returns_existing_request(
|
def test_it_does_not_return_another_user_existing_request(
|
||||||
self,
|
self,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
user_2: User,
|
user_2: User,
|
||||||
|
) -> None:
|
||||||
|
export_expiration = app.config["DATA_EXPORT_EXPIRATION"]
|
||||||
|
completed_export_request = UserDataExport(
|
||||||
|
user_id=user_2.id,
|
||||||
|
created_at=datetime.utcnow() - timedelta(hours=export_expiration),
|
||||||
|
)
|
||||||
|
db.session.add(completed_export_request)
|
||||||
|
db.session.commit()
|
||||||
|
client, auth_token = self.get_test_client_and_auth_token(
|
||||||
|
app, user_1.email
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.get(
|
||||||
|
'/api/auth/account/export',
|
||||||
|
content_type='application/json',
|
||||||
|
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
data = json.loads(response.data.decode())
|
||||||
|
assert data["status"] == "success"
|
||||||
|
assert data["request"] is None
|
||||||
|
|
||||||
|
def test_it_returns_existing_request_for_authenticated_user(
|
||||||
|
self,
|
||||||
|
app: Flask,
|
||||||
|
user_1: User,
|
||||||
) -> None:
|
) -> None:
|
||||||
export_expiration = app.config["DATA_EXPORT_EXPIRATION"]
|
export_expiration = app.config["DATA_EXPORT_EXPIRATION"]
|
||||||
completed_export_request = UserDataExport(
|
completed_export_request = UserDataExport(
|
||||||
|
@ -190,6 +190,7 @@ class TestUserDataExporterArchive(CallArgsMixin):
|
|||||||
secrets_mock: Mock,
|
secrets_mock: Mock,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
|
user_2: User,
|
||||||
) -> None:
|
) -> None:
|
||||||
exporter = UserDataExporter(user_1)
|
exporter = UserDataExporter(user_1)
|
||||||
|
|
||||||
@ -212,6 +213,7 @@ class TestUserDataExporterArchive(CallArgsMixin):
|
|||||||
secrets_mock: Mock,
|
secrets_mock: Mock,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
|
user_2: User,
|
||||||
) -> None:
|
) -> None:
|
||||||
exporter = UserDataExporter(user_1)
|
exporter = UserDataExporter(user_1)
|
||||||
token_urlsafe = random_string()
|
token_urlsafe = random_string()
|
||||||
@ -237,6 +239,7 @@ class TestUserDataExporterArchive(CallArgsMixin):
|
|||||||
secrets_mock: Mock,
|
secrets_mock: Mock,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
|
user_2: User,
|
||||||
) -> None:
|
) -> None:
|
||||||
exporter = UserDataExporter(user_1)
|
exporter = UserDataExporter(user_1)
|
||||||
token_urlsafe = random_string()
|
token_urlsafe = random_string()
|
||||||
@ -265,6 +268,7 @@ class TestUserDataExporterArchive(CallArgsMixin):
|
|||||||
secrets_mock: Mock,
|
secrets_mock: Mock,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
|
user_2: User,
|
||||||
sport_1_cycling: Sport,
|
sport_1_cycling: Sport,
|
||||||
gpx_file: str,
|
gpx_file: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -287,6 +291,38 @@ class TestUserDataExporterArchive(CallArgsMixin):
|
|||||||
)
|
)
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
@patch.object(secrets, 'token_urlsafe')
|
||||||
|
@patch.object(UserDataExporter, 'export_data')
|
||||||
|
@patch('fittrackee.users.export_data.ZipFile')
|
||||||
|
def test_it_does_not_call_zipfile_for_another_user_gpx_file(
|
||||||
|
self,
|
||||||
|
zipfile_mock: Mock,
|
||||||
|
export_data: Mock,
|
||||||
|
secrets_mock: Mock,
|
||||||
|
app: Flask,
|
||||||
|
user_1: User,
|
||||||
|
user_2: User,
|
||||||
|
sport_1_cycling: Sport,
|
||||||
|
gpx_file: str,
|
||||||
|
) -> None:
|
||||||
|
_, workout_short_id = post_a_workout(app, gpx_file)
|
||||||
|
workout = Workout.query.first()
|
||||||
|
expected_path = os.path.join(
|
||||||
|
app.config['UPLOAD_FOLDER'],
|
||||||
|
workout.gpx,
|
||||||
|
)
|
||||||
|
exporter = UserDataExporter(user_2)
|
||||||
|
|
||||||
|
exporter.generate_archive()
|
||||||
|
|
||||||
|
# fmt: off
|
||||||
|
assert (
|
||||||
|
call(expected_path, f"gpx/{workout.gpx.split('/')[-1]}")
|
||||||
|
not in zipfile_mock.return_value.__enter__.
|
||||||
|
return_value.write.call_args_list
|
||||||
|
)
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
@patch.object(secrets, 'token_urlsafe')
|
@patch.object(secrets, 'token_urlsafe')
|
||||||
@patch.object(UserDataExporter, 'export_data')
|
@patch.object(UserDataExporter, 'export_data')
|
||||||
@patch('fittrackee.users.export_data.ZipFile')
|
@patch('fittrackee.users.export_data.ZipFile')
|
||||||
@ -297,6 +333,7 @@ class TestUserDataExporterArchive(CallArgsMixin):
|
|||||||
secrets_mock: Mock,
|
secrets_mock: Mock,
|
||||||
app: Flask,
|
app: Flask,
|
||||||
user_1: User,
|
user_1: User,
|
||||||
|
user_2: User,
|
||||||
sport_1_cycling: Sport,
|
sport_1_cycling: Sport,
|
||||||
gpx_file: str,
|
gpx_file: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -321,6 +358,40 @@ class TestUserDataExporterArchive(CallArgsMixin):
|
|||||||
)
|
)
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
@patch.object(secrets, 'token_urlsafe')
|
||||||
|
@patch.object(UserDataExporter, 'export_data')
|
||||||
|
@patch('fittrackee.users.export_data.ZipFile')
|
||||||
|
def test_it_does_not_call_zipfile_for_another_user_profile_image(
|
||||||
|
self,
|
||||||
|
zipfile_mock: Mock,
|
||||||
|
export_data: Mock,
|
||||||
|
secrets_mock: Mock,
|
||||||
|
app: Flask,
|
||||||
|
user_1: User,
|
||||||
|
user_2: User,
|
||||||
|
sport_1_cycling: Sport,
|
||||||
|
gpx_file: str,
|
||||||
|
) -> None:
|
||||||
|
user_1.picture = random_string()
|
||||||
|
expected_path = os.path.join(
|
||||||
|
app.config['UPLOAD_FOLDER'],
|
||||||
|
user_1.picture,
|
||||||
|
)
|
||||||
|
exporter = UserDataExporter(user_2)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
'fittrackee.users.export_data.os.path.isfile', return_value=True
|
||||||
|
):
|
||||||
|
exporter.generate_archive()
|
||||||
|
|
||||||
|
# fmt: off
|
||||||
|
assert (
|
||||||
|
call(expected_path, user_1.picture.split('/')[-1])
|
||||||
|
not in zipfile_mock.return_value.__enter__.
|
||||||
|
return_value.write.call_args_list
|
||||||
|
)
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
@patch.object(secrets, 'token_urlsafe')
|
@patch.object(secrets, 'token_urlsafe')
|
||||||
def test_it_test_it_generates_a_zip_archive(
|
def test_it_test_it_generates_a_zip_archive(
|
||||||
self,
|
self,
|
||||||
|
Loading…
Reference in New Issue
Block a user