Skip to content

Commit

Permalink
Added Analyzer Test
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Oberndörfer <[email protected]>
  • Loading branch information
flo0852 committed Dec 7, 2024
1 parent 0839b75 commit da5edc3
Showing 1 changed file with 77 additions and 51 deletions.
128 changes: 77 additions & 51 deletions apps/analyzer/tests/test_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,90 @@
from datetime import datetime

from metadata_analyzer.analyzer import Analyzer
from metadata_analyzer.models import Result
from metadata_analyzer.models import Result, Tasks
from tests.mock_backend import MockBackend
from tests.mock_database import MockDatabase

def _create_mock_result(task, uuid, fdi_type, data_size, start_time, task_uuid = None, is_backup=1):
mock_result = Result()
mock_result.task = task
mock_result.uuid = uuid
mock_result.fdi_type = fdi_type
mock_result.data_size = data_size
mock_result.start_time = start_time
mock_result.is_backup = is_backup
mock_result.task_uuid = task_uuid
return mock_result

def _create_mock_result(task, uuid, fdi_type, data_size, start_time, task_uuid=None, is_backup=1):
mock_result = Result()
mock_result.task = task
mock_result.uuid = uuid
mock_result.fdi_type = fdi_type
mock_result.data_size = data_size
mock_result.start_time = start_time
mock_result.is_backup = is_backup
mock_result.task_uuid = task_uuid
return mock_result


def _create_mock_task(uuid, task):
mock_task = Tasks()
mock_task.uuid = uuid
mock_task.task = task
return mock_task


def test_update_data_all_types():
mock_result1 = _create_mock_result("foo", "1", "F", 100_000_000, datetime.fromisoformat("2000-01-01"))
mock_result2 = _create_mock_result("foo", "2", "D", 150_000_000, datetime.fromisoformat("2000-01-02"))
mock_result3 = _create_mock_result("foo", "3", "I", 200_000_000, datetime.fromisoformat("2000-01-03"))
mock_result4 = _create_mock_result("foo", "4", "C", 250_000_000, datetime.fromisoformat("2000-01-04"), '123')
mock_results = [mock_result1, mock_result2, mock_result3, mock_result4]
mock_result1 = _create_mock_result("foo", "1", "F", 100_000_000, datetime.fromisoformat("2000-01-01"))
mock_result2 = _create_mock_result("foo", "2", "D", 150_000_000, datetime.fromisoformat("2000-01-02"))
mock_result3 = _create_mock_result("foo", "3", "I", 200_000_000, datetime.fromisoformat("2000-01-03"))
mock_result4 = _create_mock_result("foo", "4", "C", 250_000_000, datetime.fromisoformat("2000-01-04"), '123')
mock_results = [mock_result1, mock_result2, mock_result3, mock_result4]

mock_task1 = _create_mock_task("1", "task1")
mock_task2 = _create_mock_task("123", "task123")
mock_tasks = [mock_task1, mock_task2]

database = MockDatabase(mock_results, mock_tasks)
backend = MockBackend()
Analyzer.init(database, backend, None, None)
Analyzer.update_data()

assert backend.backups == [{
"id": mock_result1.uuid,
"sizeMB": mock_result1.data_size / 1_000_000,
"creationDate": mock_result1.start_time.isoformat(),
"type": "FULL",
"taskId": None
}, {
"id": mock_result2.uuid,
"sizeMB": mock_result2.data_size / 1_000_000,
"creationDate": mock_result2.start_time.isoformat(),
"type": "DIFFERENTIAL",
"taskId": None
}, {
"id": mock_result3.uuid,
"sizeMB": mock_result3.data_size / 1_000_000,
"creationDate": mock_result3.start_time.isoformat(),
"type": "INCREMENTAL",
"taskId": None
}, {
"id": mock_result4.uuid,
"sizeMB": mock_result4.data_size / 1_000_000,
"creationDate": mock_result4.start_time.isoformat(),
"type": "COPY",
"taskId": '123'
}]

database = MockDatabase(mock_results, [])
backend = MockBackend()
Analyzer.init(database, backend, None, None)
Analyzer.update_data()
assert backend.tasks == [
{
"id": "1",
"displayName": "task1"
},
{
"id": "123",
"displayName": "task123"
}
]

assert backend.backups == [{
"id": mock_result1.uuid,
"sizeMB": mock_result1.data_size / 1_000_000,
"creationDate": mock_result1.start_time.isoformat(),
"type": "FULL",
"taskId": None
}, {
"id": mock_result2.uuid,
"sizeMB": mock_result2.data_size / 1_000_000,
"creationDate": mock_result2.start_time.isoformat(),
"type": "DIFFERENTIAL",
"taskId": None
}, {
"id": mock_result3.uuid,
"sizeMB": mock_result3.data_size / 1_000_000,
"creationDate": mock_result3.start_time.isoformat(),
"type": "INCREMENTAL",
"taskId": None
}, {
"id": mock_result4.uuid,
"sizeMB": mock_result4.data_size / 1_000_000,
"creationDate": mock_result4.start_time.isoformat(),
"type": "COPY",
"taskId": '123'
}]

def test_update_data_not_a_backup():
mock_result1 = _create_mock_result("foo", "1", "F", 100_000_000, datetime.fromisoformat("2000-01-01"), None, 0)
mock_result1 = _create_mock_result("foo", "1", "F", 100_000_000, datetime.fromisoformat("2000-01-01"), None, 0)

database = MockDatabase([mock_result1], [])
backend = MockBackend()
Analyzer.init(database, backend, None, None)
Analyzer.update_data()
database = MockDatabase([mock_result1], [])
backend = MockBackend()
Analyzer.init(database, backend, None, None)
Analyzer.update_data()

assert backend.backups == []
assert backend.backups == []

0 comments on commit da5edc3

Please sign in to comment.