Add API tests for utility check route. Fixes #3790

This commit is contained in:
Murtuza Zabuawala 2018-11-30 09:56:41 +00:00 committed by Dave Page
parent d801ed5008
commit 9a3047c89c
6 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,41 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import sys
import json
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils.test_utils import\
check_binary_path_or_skip_test
if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch
class TestUtilityCheckRouteCase(BaseTestGenerator):
"""Test to checks the utility route for Backup"""
scenarios = [
('Check utility path route for backup utility', {
'url': '/backup/utility_exists/{0}/objects',
'expected_success_value': 1
})
]
def setUp(self):
check_binary_path_or_skip_test(self)
@patch('pgadmin.tools.backup.is_utility_exists')
def runTest(self, is_utility_exists_mock):
is_utility_exists_mock.return_value = False
response = self.tester.get(self.url.format(1))
self.assertEquals(response.status_code, 200)
response = json.loads(response.data.decode('utf-8'))
self.assertEquals(self.expected_success_value, response['success'])

View File

@ -0,0 +1,8 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################

View File

@ -0,0 +1,41 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import sys
import json
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils.test_utils import\
check_binary_path_or_skip_test
if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch
class TestUtilityCheckRouteCase(BaseTestGenerator):
"""Test to checks the utility route for Import-Export"""
scenarios = [
('Check utility path route for import export utility', {
'url': '/import_export/utility_exists/{0}',
'expected_success_value': 1
})
]
def setUp(self):
check_binary_path_or_skip_test(self)
@patch('pgadmin.tools.import_export.is_utility_exists')
def runTest(self, is_utility_exists_mock):
is_utility_exists_mock.return_value = False
response = self.tester.get(self.url.format(1))
self.assertEquals(response.status_code, 200)
response = json.loads(response.data.decode('utf-8'))
self.assertEquals(self.expected_success_value, response['success'])

View File

@ -0,0 +1,41 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import sys
import json
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils.test_utils import\
check_binary_path_or_skip_test
if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch
class TestUtilityCheckRouteCase(BaseTestGenerator):
"""Test to checks the utility route for maintenance"""
scenarios = [
('Check utility path route for maintenance utility', {
'url': '/maintenance/utility_exists/{0}',
'expected_success_value': 1
})
]
def setUp(self):
check_binary_path_or_skip_test(self)
@patch('pgadmin.tools.maintenance.is_utility_exists')
def runTest(self, is_utility_exists_mock):
is_utility_exists_mock.return_value = False
response = self.tester.get(self.url.format(1))
self.assertEquals(response.status_code, 200)
response = json.loads(response.data.decode('utf-8'))
self.assertEquals(self.expected_success_value, response['success'])

View File

@ -0,0 +1,41 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import sys
import json
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils.test_utils import\
check_binary_path_or_skip_test
if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch
class TestUtilityCheckRouteCase(BaseTestGenerator):
"""Test to checks the utility route for Restore"""
scenarios = [
('Check utility path route for restore utility', {
'url': '/restore/utility_exists/{0}',
'expected_success_value': 1
})
]
def setUp(self):
check_binary_path_or_skip_test(self)
@patch('pgadmin.tools.restore.is_utility_exists')
def runTest(self, is_utility_exists_mock):
is_utility_exists_mock.return_value = False
response = self.tester.get(self.url.format(1))
self.assertEquals(response.status_code, 200)
response = json.loads(response.data.decode('utf-8'))
self.assertEquals(self.expected_success_value, response['success'])

View File

@ -964,3 +964,15 @@ def get_server_type(server):
return 'pg'
except Exception:
traceback.print_exc(file=sys.stderr)
def check_binary_path_or_skip_test(cls):
if 'default_binary_paths' not in cls.server or \
cls.server['default_binary_paths'] is None or \
cls.server['type'] not in cls.server['default_binary_paths'] or \
cls.server['default_binary_paths'][cls.server['type']] == '':
cls.skipTest(
"default_binary_paths is not set for the server {0}".format(
cls.server['name']
)
)