Skip to content
Snippets Groups Projects
Commit 5b082ef2 authored by Neda Moeini's avatar Neda Moeini
Browse files

Add unit test for activity log.

parent 7264217a
No related branches found
No related tags found
1 merge request!4Feature/activity log
......@@ -5,6 +5,8 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls.base import reverse
from rest_framework.test import APIClient
from sage_validation.accounts.models import UserActivityLog
UPLOAD_FILE_URL = reverse("upload-file")
......@@ -57,7 +59,32 @@ def test_csv_export_with_data(api_client: APIClient) -> None:
response = api_client.get(url)
assert UserActivityLog.objects.count() == 1
assert response.status_code == 200
assert response["Content-Disposition"] == "attachment; filename=Validated_BK1234.csv"
assert b"AccountNumber,TransactionDate,TransactionReference" in response.content
assert b"12345,01/03/2024,BK1234" in response.content
@pytest.mark.django_db
def test_activity_log_creation_on_csv_export(api_client: APIClient) -> None:
"""Test that a UserActivityLog is created when exporting a CSV file."""
url = reverse("export-file")
# Simulate session data
session = api_client.session
session["validated_csv"] = [
{"AccountNumber": "12345", "TransactionDate": "01/03/2024", "TransactionReference": "BK1234"},
]
session["input_file_hash"] = "123456"
session.save()
response = api_client.get(url)
assert response.status_code == 200
log = UserActivityLog.objects.first()
assert log.action == "download"
assert log.input_file_hash == "123456"
assert log.output_file_hash == UserActivityLog.generate_file_hash(session["validated_csv"])
assert log.name == "Validated_BK1234.csv"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment