generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from amosproj/131-analysis-module-filter-back…
…up-data-by-backup-tasks-ids 131 analysis module filter backup data by backup tasks ids
- Loading branch information
Showing
17 changed files
with
271 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
class MockDatabase: | ||
def __init__(self, results): | ||
self.results = results | ||
def __init__(self, results, tasks = []): | ||
self.results = results | ||
self.tasks = tasks | ||
|
||
def get_results(self): | ||
return iter(self.results) | ||
def get_results(self): | ||
return iter(self.results) | ||
|
||
def get_tasks(self): | ||
return iter(self.tasks) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +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, 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 | ||
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")) | ||
mock_results = [mock_result1, mock_result2, mock_result3, mock_result4] | ||
|
||
database = MockDatabase(mock_results) | ||
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" | ||
}, { | ||
"id": mock_result2.uuid, | ||
"sizeMB": mock_result2.data_size / 1_000_000, | ||
"creationDate": mock_result2.start_time.isoformat(), | ||
"type": "DIFFERENTIAL" | ||
}, { | ||
"id": mock_result3.uuid, | ||
"sizeMB": mock_result3.data_size / 1_000_000, | ||
"creationDate": mock_result3.start_time.isoformat(), | ||
"type": "INCREMENTAL" | ||
}, { | ||
"id": mock_result4.uuid, | ||
"sizeMB": mock_result4.data_size / 1_000_000, | ||
"creationDate": mock_result4.start_time.isoformat(), | ||
"type": "COPY" | ||
}] | ||
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' | ||
}] | ||
|
||
assert backend.tasks == [ | ||
{ | ||
"id": "1", | ||
"displayName": "task1" | ||
}, | ||
{ | ||
"id": "123", | ||
"displayName": "task123" | ||
} | ||
] | ||
|
||
|
||
def test_update_data_not_a_backup(): | ||
mock_result1 = _create_mock_result("foo", "1", "F", 100_000_000, datetime.fromisoformat("2000-01-01"), 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 == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.