Test added for get_backup_status and restore_backup
import json
from unittest.mock import MagicMock, patch
+from collections import Counter
from aiohttp import web
import pytest
-import asyncio
-from collections import Counter
from foglamp.services.core import routes
from foglamp.services.core import connect
from foglamp.plugins.storage.postgres.backup_restore.backup_postgres import Backup
@@ -18,7 +17,6 @@ from foglamp.plugins.storage.postgres.backup_restore import exceptions
from foglamp.services.core.api import backup_restore
from foglamp.common.storage_client.storage_client import StorageClient
-
__author__ = "Vaibhav Singhal"
__copyright__ = "Copyright (c) 2017 OSIsoft, LLC"
__license__ = "Apache 2.0"
@@ -28,7 +26,8 @@ __version__ = "${VERSION}"
@pytest.allure.feature("unit")
@pytest.allure.story("api", "core")
class TestBackup:
-
+ """Unit test the Backup functionality
+ """
@pytest.fixture
def client(self, loop, test_client):
app = web.Application(loop=loop)
@@ -164,3 +163,32 @@ class TestBackup:
resp = await client.delete('/foglamp/backup/{}'.format('BLA'))
assert 400 == resp.status
assert "Invalid backup id" == resp.reason
+
+ async def test_get_backup_status(self, client):
+ resp = await client.get('/foglamp/backup/status')
+ assert 200 == resp.status
+ result = await resp.text()
+ json_response = json.loads(result)
+ assert {'backupStatus': [{'index': 1, 'name': 'RUNNING'},
+ {'index': 2, 'name': 'COMPLETED'},
+ {'index': 3, 'name': 'CANCELED'},
+ {'index': 4, 'name': 'INTERRUPTED'},
+ {'index': 5, 'name': 'FAILED'},
+ {'index': 6, 'name': 'RESTORED'}]} == json_response
+
+
+class TestRestore:
+ """Unit test the Restore functionality
+ """
+ @pytest.fixture
+ def client(self, loop, test_client):
+ app = web.Application(loop=loop)
+ # fill the routes table
+ routes.setup(app)
+ return loop.run_until_complete(test_client(app))
+
+ # TODO: FOGL-861
+ async def test_restore_backup(self, client):
+ resp = await client.put('/foglamp/backup/{}/restore'.format(1))
+ assert 501 == resp.status
+ assert "Restore backup method is not implemented yet." == resp.reason
