Test added for purge_data unit
import asyncio
-from unittest.mock import patch, call
+from unittest.mock import patch, call, MagicMock
import pytest
import logging
-from foglamp.common.storage_client.storage_client import StorageClient
+from foglamp.common.storage_client.storage_client import ReadingsStorageClient, StorageClient
from foglamp.common.statistics import Statistics
from foglamp.tasks.purge.purge import Purge
from foglamp.common.process import FoglampProcess
@@ -44,13 +44,33 @@ class TestPurge:
mock_update.assert_has_calls([call('PURGED', 1), call('UNSNPURGED', 2)])
def test_insert_into_log(self):
+ # TODO: FOGL-701
pass
def test_set_configuration(self):
pass
- def test_purge_data(self):
- pass
+ config = [{"retainUnsent": {"value": "False"}, "age": {"value": "72"}, "size": {"value": "0"}},
+ {"retainUnsent": {"value": "True"}, "age": {"value": "0"}, "size": {"value": "100"}}]
+
+ @pytest.mark.parametrize("conf, flag", [
+ (config[0], "purge"),
+ (config[1], "retain")
+ ])
+ def test_purge_data(self, conf, flag):
+ """Test that purge_data calls Storage's purge with defined values"""
+ # TODO: FOGL-701 AuditLogger tests
+ with patch.object(FoglampProcess, '__init__'):
+ p = Purge()
+ p._storage = MagicMock(spec=StorageClient)
+ p._readings_storage = MagicMock(spec=ReadingsStorageClient)
+ p._insert_into_log = MagicMock()
+ with patch.object(p._readings_storage, 'purge') as mock_storage_purge:
+ with patch.object(p, '_insert_into_log') as mock_insert:
+ p.purge_data(conf)
+ assert mock_insert.called
+ mock_storage_purge.assert_has_calls([call(age=conf["age"]["value"], flag=flag, sent_id=0)],
+ [call(size=conf["size"]["value"], flag=flag, sent_id=0)])
def test_run(self):
pass
