WIP
This commit is contained in:
@@ -9,19 +9,18 @@ from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from inference.data.admin_db import AdminDB
|
||||
from inference.web.services.batch_upload import BatchUploadService
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_db():
|
||||
"""Mock admin database for testing."""
|
||||
class MockAdminDB:
|
||||
def batch_repo():
|
||||
"""Mock batch upload repository for testing."""
|
||||
class MockBatchUploadRepository:
|
||||
def __init__(self):
|
||||
self.batches = {}
|
||||
self.batch_files = {}
|
||||
|
||||
def create_batch_upload(self, admin_token, filename, file_size, upload_source):
|
||||
def create(self, admin_token, filename, file_size, upload_source):
|
||||
batch_id = uuid4()
|
||||
batch = type('BatchUpload', (), {
|
||||
'batch_id': batch_id,
|
||||
@@ -43,13 +42,13 @@ def admin_db():
|
||||
self.batches[batch_id] = batch
|
||||
return batch
|
||||
|
||||
def update_batch_upload(self, batch_id, **kwargs):
|
||||
def update(self, batch_id, **kwargs):
|
||||
if batch_id in self.batches:
|
||||
batch = self.batches[batch_id]
|
||||
for key, value in kwargs.items():
|
||||
setattr(batch, key, value)
|
||||
|
||||
def create_batch_upload_file(self, batch_id, filename, **kwargs):
|
||||
def create_file(self, batch_id, filename, **kwargs):
|
||||
file_id = uuid4()
|
||||
# Set defaults for attributes
|
||||
defaults = {
|
||||
@@ -68,7 +67,7 @@ def admin_db():
|
||||
self.batch_files[batch_id].append(file_record)
|
||||
return file_record
|
||||
|
||||
def update_batch_upload_file(self, file_id, **kwargs):
|
||||
def update_file(self, file_id, **kwargs):
|
||||
for files in self.batch_files.values():
|
||||
for file_record in files:
|
||||
if file_record.file_id == file_id:
|
||||
@@ -76,19 +75,19 @@ def admin_db():
|
||||
setattr(file_record, key, value)
|
||||
return
|
||||
|
||||
def get_batch_upload(self, batch_id):
|
||||
def get(self, batch_id):
|
||||
return self.batches.get(batch_id)
|
||||
|
||||
def get_batch_upload_files(self, batch_id):
|
||||
def get_files(self, batch_id):
|
||||
return self.batch_files.get(batch_id, [])
|
||||
|
||||
return MockAdminDB()
|
||||
return MockBatchUploadRepository()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def batch_service(admin_db):
|
||||
def batch_service(batch_repo):
|
||||
"""Batch upload service instance."""
|
||||
return BatchUploadService(admin_db)
|
||||
return BatchUploadService(batch_repo)
|
||||
|
||||
|
||||
def create_test_zip(files):
|
||||
@@ -194,7 +193,7 @@ INV002,F2024-002,2024-01-16,2500.00,7350087654321,123-4567,C124
|
||||
assert csv_data["INV001"]["Amount"] == "1500.00"
|
||||
assert csv_data["INV001"]["customer_number"] == "C123"
|
||||
|
||||
def test_get_batch_status(self, batch_service, admin_db):
|
||||
def test_get_batch_status(self, batch_service, batch_repo):
|
||||
"""Test getting batch upload status."""
|
||||
# Create a batch
|
||||
zip_content = create_test_zip({"INV001.pdf": b"%PDF-1.4 test"})
|
||||
|
||||
Reference in New Issue
Block a user