Initial version of a regression test framework

This commit is contained in:
Priyanka Shendge 2016-04-17 10:39:08 -04:00 committed by Dave Page
parent ffa348fe5d
commit 98d473a7ec
20 changed files with 907 additions and 32 deletions

View File

@ -1,31 +1,45 @@
alabaster==0.7.6
Babel==1.3
beautifulsoup4==4.3.2
blinker==1.3
django-htmlmin==0.8.0
docutils==0.12
extras==0.0.3
fixtures==2.0.0
Flask==0.10.1
Flask-Babel==0.9
Flask-Gravatar==0.4.2
Flask-Login==0.2.11
Flask-Mail==0.9.1
Flask-Principal==0.4.0
Flask-SQLAlchemy==2.0
Flask-Security==1.7.4
Flask-SQLAlchemy==2.0
Flask-WTF==0.11
Jinja2==2.7.3
MarkupSafe==0.23
SQLAlchemy==0.9.8
WTForms==2.0.2
Werkzeug==0.9.6
argparse==1.3.0
beautifulsoup4==4.3.2
blinker==1.3
django-htmlmin==0.8.0
html5lib==1.0b3
itsdangerous==0.24
passlib==1.6.2
psycopg2==2.5.2
pytz==2014.10
six==1.9.0
speaklater==1.3
pycrypto==2.6.1
wsgiref==0.1.2
simplejson==3.6.5
importlib==1.0.3
itsdangerous==0.24
Jinja2==2.7.3
linecache2==1.0.0
MarkupSafe==0.23
passlib==1.6.2
pbr==1.9.1
psycopg2==2.5.2
pycrypto==2.6.1
Pygments==2.0.2
pyrsistent==0.11.13
python-dateutil==2.5.0
python-mimeparse==1.5.1
pytz==2014.10
simplejson==3.6.5
six==1.9.0
snowballstemmer==1.2.0
speaklater==1.3
Sphinx==1.3.3
sphinx-rtd-theme==0.1.9
SQLAlchemy==0.9.8
testscenarios==0.5.0
testtools==2.0.0
traceback2==1.4.0
unittest2==1.1.0
Werkzeug==0.9.6
WTForms==2.0.2

View File

@ -1,29 +1,39 @@
Babel==1.3
beautifulsoup4==4.4.1
blinker==1.3
django-htmlmin==0.8.0
extras==0.0.3
fixtures==2.0.0
Flask==0.10.1
Flask-Babel==0.9
Flask-Gravatar==0.4.2
Flask-Login==0.2.11
Flask-Mail==0.9.1
Flask-Principal==0.4.0
Flask-SQLAlchemy==2.0
Flask-Security==1.7.4
Flask-SQLAlchemy==2.0
Flask-WTF==0.11
Jinja2==2.7.3
MarkupSafe==0.23
SQLAlchemy==0.9.8
WTForms==2.0.2
Werkzeug==0.9.6
argparse==1.3.0
beautifulsoup4==4.4.1
blinker==1.3
django-htmlmin==0.8.0
html5lib==1.0b3
itsdangerous==0.24
Jinja2==2.7.3
linecache2==1.0.0
MarkupSafe==0.23
passlib==1.6.2
pbr==1.9.1
psycopg2==2.5.2
pycrypto==2.6.1
pyrsistent==0.11.13
python-dateutil==2.5.0
python-mimeparse==1.5.1
pytz==2014.10
simplejson==3.6.5
six==1.9.0
speaklater==1.3
pycrypto==2.6.1
simplejson==3.6.5
python-dateutil==2.5.0
SQLAlchemy==0.9.8
testscenarios==0.5.0
testtools==2.0.0
traceback2==1.4.0
unittest2==1.1.0
Werkzeug==0.9.6
wheel==0.24.0
WTForms==2.0.2

View File

@ -0,0 +1,15 @@
# ##########################################################################
#
# #pgAdmin 4 - PostgreSQL Tools
#
# #Copyright (C) 2013 - 2016, The pgAdmin Development Team
# #This software is released under the PostgreSQL Licence
#
# ##########################################################################
from pgadmin.utils.route import BaseTestGenerator
class ServerGenerateTestCase(BaseTestGenerator):
def runTest(self):
print ("In ServerGenerateTestCase...")

View File

@ -0,0 +1,53 @@
# ##########################################################################
#
# #pgAdmin 4 - PostgreSQL Tools
#
# #Copyright (C) 2013 - 2016, The pgAdmin Development Team
# #This software is released under the PostgreSQL Licence
#
# ##########################################################################
import json
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
class ServersAddTestCase(LoginTestCase):
"""
This class will add the servers under default server group and verify with
server's name.
"""
priority = 4
scenarios = [
# Fetch the default url for server object
('Default Server Node url', dict(url='/browser/server/obj/'))
]
def runTest(self):
"""
This function will add the server under default server group.
Verify the added server with response code as well as server name.
"""
srv_grp = config_data['test_server_group']
for srv in config_data['test_server_credentials']:
data = {"name": srv['test_name'],
"comment": "",
"host": srv['test_host'],
"port": srv['test_db_port'],
"db": srv['test_maintenance_db'],
"username": srv['test_db_username'],
"role": "",
"sslmode": srv['test_sslmode']}
url = self.url + str(srv_grp) + "/"
response = self.tester.post(url, data=json.dumps(data),
content_type='html/json')
self.assertTrue(response.status_code, 200)
respdata = json.loads(response.data)
self.assertTrue(respdata['node']['label'], srv['test_name'])

View File

@ -0,0 +1,57 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
import json
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
class ServersDeleteTestCase(LoginTestCase):
"""
This class will check server node present on the object browser's tree node
by response code.
"""
priority = 7
scenarios = [
# Fetching the default url for server node
('Default Server Node url', dict(url='/browser/server/obj/'))
]
def runTest(self):
"""
This function will get all available servers under object browser
and delete the servers using server id.
"""
srv_grp = config_data['test_server_group']
for srv in config_data['test_server_credentials']:
data = {"name": srv['test_name'],
"host": srv['test_host'],
"port": srv['test_db_port'],
"db": srv['test_maintenance_db'],
"username": srv['test_db_username'],
"role": "",
"sslmode": srv['test_sslmode']}
url = self.url + str(srv_grp) + "/"
response = self.tester.get(url, data=json.dumps(data),
content_type='html/json')
self.assertTrue(response.status_code, 200)
respdata = json.loads(response.data)
for server in respdata:
response = self.tester.delete(url + json.dumps(server['id']))
self.assertTrue(response.status_code, 200)
respdata = json.loads(response.data)
self.assertTrue(respdata['success'], 1)

View File

@ -0,0 +1,49 @@
# ##########################################################################
#
# #pgAdmin 4 - PostgreSQL Tools
#
# #Copyright (C) 2013 - 2016, The pgAdmin Development Team
# #This software is released under the PostgreSQL Licence
#
# ##########################################################################
import json
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
class ServersGetTestCase(LoginTestCase):
"""
This class will check server node present on the object browser's tree node
by response code.
"""
priority = 5
scenarios = [
# Fetch the default url for server node
('Default Server Node url', dict(url='/browser/server/obj/'))
]
def runTest(self):
"""
This function will get all available servers present under
object browser.
"""
srv_grp = config_data['test_server_group']
for srv in config_data['test_server_credentials']:
data = {"name": srv['test_name'],
"host": srv['test_host'],
"port": srv['test_db_port'],
"db": srv['test_maintenance_db'],
"username": srv['test_db_username'],
"role": "",
"sslmode": srv['test_sslmode']}
url = self.url + str(srv_grp) + "/"
response = self.tester.get(url, data=json.dumps(data),
content_type='html/json')
self.assertTrue(response.status_code, 200)

View File

@ -0,0 +1,65 @@
# ##########################################################################
#
# #pgAdmin 4 - PostgreSQL Tools
#
# #Copyright (C) 2013 - 2016, The pgAdmin Development Team
# #This software is released under the PostgreSQL Licence
#
# ##########################################################################
import json
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
class ServersUpdateTestCase(LoginTestCase):
"""
This class will check server node present on the object browser's tree node
by response code.
"""
priority = 6
scenarios = [
# Fetching the default url for server node
('Default Server Node url', dict(url='/browser/server/obj/'))
]
def runTest(self):
"""
This function will edit and update the server's comment field
by the server id.
"""
srv_grp = config_data['test_server_group']
for srv in config_data['test_server_credentials']:
data = {"name": srv['test_name'],
"host": srv['test_host'],
"port": srv['test_db_port'],
"db": srv['test_maintenance_db'],
"username": srv['test_db_username'],
"role": "",
"sslmode": srv['test_sslmode']}
url = self.url + str(srv_grp) + "/"
response = self.tester.get(url, data=json.dumps(data),
content_type='html/json')
self.assertTrue(response.status_code, 200)
respdata = json.loads(response.data)
for server in respdata:
url = self.url + str(srv_grp) + "/" + json.dumps(server['id'])
for server in config_data['test_server_update_data']:
data = {"comment": server['test_comment']}
response = self.tester.put(url, data=json.dumps(data),
content_type='html/json')
self.assertTrue(response.status_code, 200)
respdata = json.loads(response.data)
self.assertTrue(respdata['success'], 1)

View File

@ -0,0 +1,15 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
from pgadmin.utils.route import BaseTestGenerator
class SGGenerateTestCase(BaseTestGenerator):
def runTest(self):
print ("In SGGenerateTestCase...")

View File

@ -0,0 +1,36 @@
###########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
###########################################################################
import json
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
class SgNodeTestCase(LoginTestCase):
"""
This class will check available server groups in pgAdmin.
"""
priority = 1
scenarios = [
# Fetching the default url for server group node
('Check Server Group Node', dict(url='/browser/server-group/obj/'))
]
def runTest(self):
"""This function will check available server groups."""
i = config_data['test_server_group']
response = self.tester.get(self.url + str(i), content_type='html/json')
self.assertTrue(response.status_code, 200)
respdata = json.loads(response.data)
self.assertTrue(respdata['id'], i)

View File

@ -0,0 +1,15 @@
#############################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##############################################################
from pgadmin.utils.route import BaseTestGenerator
class BrowserGenerateTestCase(BaseTestGenerator):
def runTest(self):
print ("In BrowserGenerateTestCase...")

View File

@ -0,0 +1,93 @@
# ##########################################################################
#
# #pgAdmin 4 - PostgreSQL Tools
#
# #Copyright (C) 2013 - 2016, The pgAdmin Development Team
# #This software is released under the PostgreSQL Licence
#
# ##########################################################################
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
import uuid
class ChangePasswordTestCase(LoginTestCase):
"""
This class validates the change password functionality
by defining change password scenarios; where dict of
parameters describes the scenario appended by test name.
"""
priority = 2
scenarios = [
# This testcase validates invalid confirmation password
('TestCase for Validating Incorrect_New_Password', dict(
password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
new_password=(config_data['pgAdmin4_login_credentials']
['test_new_password']),
new_password_confirm=str(uuid.uuid4())[4:8],
respdata='Passwords do not match')),
# This testcase validates if confirmation password is less than
# minimum length
('TestCase for Validating New_Password_Less_Than_Min_Length',
dict(password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
new_password=str(uuid.uuid4())[4:8],
new_password_confirm=str(uuid.uuid4())[4:8],
respdata='Password must be at least 6 characters')),
# This testcase validates if both password fields are left blank
('TestCase for Validating Empty_New_Password', dict(
password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
new_password='', new_password_confirm='',
respdata='Password not provided')),
# This testcase validates if current entered password
# is incorrect
('TestCase for Validating Incorrect_Current_Password', dict(
password=str(uuid.uuid4())[4:8],
new_password=(config_data['pgAdmin4_login_credentials']
['test_new_password']),
new_password_confirm=(
config_data['pgAdmin4_login_credentials']
['test_new_password']),
respdata='Invalid password')),
# This testcase checks for valid password
('TestCase for Changing Valid_Password', dict(
password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
new_password=(config_data['pgAdmin4_login_credentials']
['test_new_password']),
new_password_confirm=(
config_data['pgAdmin4_login_credentials']
['test_new_password']),
respdata='You successfully changed your password.')),
('Reassigning_Password', dict(
password=(config_data['pgAdmin4_login_credentials']
['test_new_password']),
new_password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
new_password_confirm=(
config_data['pgAdmin4_login_credentials']
['test_login_password']),
respdata='You successfully changed your password.'))
]
def runTest(self):
"""This function will check change password functionality."""
response = self.tester.get('/change', follow_redirects=True)
self.assertIn('pgAdmin 4 Password Change', response.data)
response = self.tester.post('/change', data=dict(
password=self.password,
new_password=self.new_password,
new_password_confirm=self.new_password_confirm),
follow_redirects=True)
self.assertIn(self.respdata, response.data)

View File

@ -0,0 +1,79 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import uuid
from pgadmin.utils.route import BaseTestGenerator
from regression.config import config_data
class LoginTestCase(BaseTestGenerator):
"""
This class checks login functionality by validating different scenarios.
Login scenarios are defined in dictionary; where dict of parameters
describe the scenario appended by test name.
"""
priority = 0
scenarios = [
# This test case validates the invalid/incorrect password
('TestCase for Checking Invalid_Password', dict(
email=(config_data['pgAdmin4_login_credentials']
['test_login_username']),
password=str(uuid.uuid4())[4:8],
respdata='Invalid password')),
# This test case validates the empty password field
('Empty_Password', dict(
email=(config_data['pgAdmin4_login_credentials']
['test_login_username']), password='',
respdata='Password not provided')),
# This test case validates blank email field
('Empty_Email', dict(
email='', password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
respdata='Email not provided')),
# This test case validates empty email and password
('Empty_Creadentials', dict(
email='', password='',
respdata='Email not provided')),
# This test case validates the invalid/incorrect email id
('Invalid_Email', dict(
email=str(uuid.uuid4())[1:6] + '@xyz.com',
password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
respdata='Specified user does not exist')),
# This test case validates invalid email and password
('Invalid_Creadentials', dict(
email=str(uuid.uuid4())[1:6] + '@xyz.com',
password=str(uuid.uuid4())[4:8],
respdata='Specified user does not exist')),
# This test case validates the valid/correct credentials and allow user
# to login pgAdmin 4
('Valid_Creadentials', dict(
email=(config_data['pgAdmin4_login_credentials']
['test_login_username']),
password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
respdata='You are currently running version'))
]
def runTest(self):
"""This function checks login functionality."""
response = self.tester.post('/login', data=dict(
email=self.email, password=self.password),
follow_redirects=True)
self.assertIn(self.respdata, response.data)

View File

@ -0,0 +1,44 @@
# ##########################################################################
#
# #pgAdmin 4 - PostgreSQL Tools
#
# #Copyright (C) 2013 - 2016, The pgAdmin Development Team
# #This software is released under the PostgreSQL Licence
#
# ##########################################################################
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
class LogoutTest(LoginTestCase):
"""
This class verifies the logout functionality; provided the user is already
logged-in. Dictionary parameters define the scenario appended by test
name.
"""
priority = 3
scenarios = [
# This test case validate the logout page
('Logging Out', dict(respdata='Redirecting...'))
]
def runTest(self):
"""This function checks the logout functionality."""
response = self.tester.get('/logout')
self.assertIn(self.respdata, response.data)
def tearDown(self):
"""
Defining tear down class, which will run after each test method execute.
Re-logging in as further modules require login.
"""
self.tester.post('/login', data=dict(
email=(config_data['pgAdmin4_login_credentials']
['test_login_username']),
password=(config_data['pgAdmin4_login_credentials']
['test_login_password'])), follow_redirects=True)

View File

@ -0,0 +1,47 @@
# ##########################################################################
#
# #pgAdmin 4 - PostgreSQL Tools
#
# #Copyright (C) 2013 - 2016, The pgAdmin Development Team
# #This software is released under the PostgreSQL Licence
#
# ##########################################################################
import uuid
from pgadmin.utils.route import BaseTestGenerator
from regression.config import config_data
class ResetPasswordTestCase(BaseTestGenerator):
"""
This class validates the reset password functionality by defining
scenarios; Each dict parameter describe a scenario appended by
test name.
"""
priority = 1
scenarios = [
# This test case validates the empty email field
('TestCase for Validating Empty Email', dict(
email='', respdata='Email not provided')),
# This test case validates the invalid/incorrect email field
('TestCase for Validating Invalid_Email', dict(
email=str(uuid.uuid4())[1:6] + '@xyz.com',
respdata='Specified user does not exist')),
# This test case validates the valid email id
('TestCase for Validating Valid_Email', dict(
email=config_data['pgAdmin4_login_credentials']
['test_login_username'], respdata='pgAdmin 4'))
]
def runTest(self):
"""This function checks reset password functionality."""
response = self.tester.get('/reset')
self.assertIn('Recover pgAdmin 4 Password', response.data)
response = self.tester.post(
'/reset', data=dict(email=self.email),
follow_redirects=True)
self.assertIn(self.respdata, response.data)

View File

@ -0,0 +1,74 @@
#############################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##############################################################
from abc import ABCMeta, abstractmethod
import unittest
class TestsGeneratorRegistry(ABCMeta):
"""
class TestsGeneratorRegistry(object)
Every module will be registered automatically by its module name.
Class-level Methods:
----------- -------
* __init__(...)
- This is used to register test modules. You don't need to
call this function explicitly. This will be automatically executed,
whenever we create a class and inherit from BaseTestGenerator -
it will register it as an available module in TestsGeneratorRegistry.
By setting the __metaclass__ for BaseTestGenerator to TestsGeneratorRegistry
it will create new instance of this TestsGeneratorRegistry per class.
* load_generators():
- This function will load all the modules from __init__()
present in registry.
"""
registry = dict()
def __init__(cls, name, bases, d):
# Register this type of module, based on the module name
# Avoid registering the BaseDriver itself
if name != 'BaseTestGenerator':
TestsGeneratorRegistry.registry[d['__module__']] = cls
ABCMeta.__init__(cls, name, bases, d)
@classmethod
def load_generators(cls, pkg):
cls.registry = dict()
from importlib import import_module
from werkzeug.utils import find_modules
for module_name in find_modules(pkg, False, True):
module = import_module(module_name)
import six
@six.add_metaclass(TestsGeneratorRegistry)
class BaseTestGenerator(unittest.TestCase):
# Defining abstract method which will override by individual testcase.
@abstractmethod
def runTest(self):
pass
# Initializing app.
def setApp(self, app):
self.app = app
# Initializing test_client.
def setTestClient(self, test_client):
self.tester = test_client

96
web/regression/README Normal file
View File

@ -0,0 +1,96 @@
pgAdmin 4 Test Framework
========================
This regression framework is designed for executing the individual unit tests
available for the existing modules and to help catch regressions. In addition
to that this should be helpful for other new plugged-in module that can come
in later in time.
Assumptions
-----------
- pgAdmin must be configured to run in Server mode, with SMTP configured.
- There should be a single server group present in the browser.
- Currently each module will have testcases related to ONLY GET, POST, PUT,
and DELETE apis.
General Information
-------------------
1) The required test cases should be placed under the /tests directory of the
respective module.
- 'pgadmin/browser/tests' directory contains test-cases for following
modules:
1. Login Page
2. Reset Password Page
3. Change Password Page
4. Logout Page
- 'pgAdmin4/web/pgadmin/browser/server_groups/tests/' shows an example of
tree traversal of the pgAdmin modules and how the test folder is required
for each individual module.
- 'pgadmin/browser/server_groups/servers/tests/' directory will have separate
file for each test-case:
1. test_server_add.py
2. test_server_delete.py
3. test_server_get.py
4. test_server_update.py
2) The pgAdmin4 source tree includes a file template for the server configuration
named test_config.json.in' in the pgAdmin4/web/regression directory. After
completing the pgAdmin4 configuration, you must make a working copy of the
template called test_config.json before modifying the file contents.
2a) The following command copies the test_config.json.in file, creating a
configuration file named test_config.json
# cp pgadmin4/web/regression/test_config.json.in \
pgadmin4/web/regression/test_config.json
2b) After creating the server configuration file, add (or modify)
parameter values as per requirements. The configuration
files are owned by root/user. The pgAdmin4 regression framework expects
to find the files in the directory '/<installation dir>/web/regression/'.
If you move the file to another location, you must create a symbolic link
that specifies the new location.
2c) Specifying Server Configuration file:
The user can use the parameters in the configuration file to specify the
server details and connection properties as per their local setup. The
test_config file is in json format and property values are case-sensitive.
Test Data Details
-----------------
"pgAdmin4 Login Credentials":
test_login_username = login id
test_login_password = login password
test_new_password = new login password
"test_server_credentials":
test_name = Server/database Name
test_db_username = Database Username
test_host = IP Address of Server
test_db_password = Database Password
test_db_port = Database Port
test_maintenance_db = Maintenance Database
test_sslmode = SSL Mode
test_comment = Any Comments to add
Execution:
-----------
- The test framework is modular and pluggable and dynamically locates tests
for modules which are discovered at runtime. All test cases are found
and registered automatically by its module name in
'pgadmin4/web/pgadmin/utils/test.py' file.
- Execute test framework run 'regression/testsuite.py' file.

View File

16
web/regression/config.py Normal file
View File

@ -0,0 +1,16 @@
#############################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##############################################################
import json
import os
root = os.path.dirname(os.path.realpath(__file__))
with open(root + '/test_config.json') as data_file:
config_data = json.load(data_file)

View File

@ -0,0 +1,25 @@
{
"pgAdmin4_login_credentials": {
"test_new_password": "NEWPASSWORD",
"test_login_password": "PASSWORD",
"test_login_username": "USER@EXAMPLE.COM"
},
"test_server_group": 1,
"test_server_credentials": [
{
"test_name": "PostgreSQL 9.4",
"test_comment": "PostgreSQL 9.4 Server (EDB Installer)",
"test_db_username": "postgres",
"test_host": "localhost",
"test_db_password": "PASSWORD",
"test_db_port": 5432,
"test_maintenance_db": "postgres",
"test_sslmode": "prefer"
}
],
"test_server_update_data": [
{
"test_comment": "This is test update comment"
}
]
}

View File

@ -0,0 +1,72 @@
#############################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##############################################################
""" This file collect all modules/files present in tests directory and add
them to TestSuite. """
import os
import sys
import unittest
from testscenarios.scenarios import generate_scenarios
# We need to include the root directory in sys.path to ensure that we can
# find everything we need when running in the standalone runtime.
current_path = os.path.dirname(os.path.realpath(__file__))
root = os.path.dirname(current_path)
if sys.path[0] != root:
sys.path.insert(0, root)
from pgadmin import create_app
# Create the app!
app = create_app()
# Disabling Cross-site request forgery(CSRF token) for testing purpose.
# CSRF prevent session against malicious Web site, or end users who wants to
# execute unwanted actions.
app.config['WTF_CSRF_ENABLED'] = False
from pgadmin.utils.route import TestsGeneratorRegistry
# Registry will load all the testcases/modules from pgadmin path those are
# register as BaseTestGenerator.
TestsGeneratorRegistry.load_generators('pgadmin')
# Create test client
# werkzeug provides a test client which gives a simple interface to the
# application. We can trigger test request to the application.
test_client = app.test_client()
def suite():
""" Defining test suite which will execute all the testcases present in
tests directory according to set priority."""
pgadmin_suite = unittest.TestSuite()
modules = []
for key, klass in TestsGeneratorRegistry.registry.items():
gen = klass
modules.insert(gen.priority, gen)
for m in modules:
obj = m()
obj.setTestClient(test_client)
scenario = generate_scenarios(obj)
pgadmin_suite.addTests(scenario)
return pgadmin_suite
if __name__ == '__main__':
suite = suite()
tests = unittest.TextTestRunner(descriptions=True, verbosity=2).run(suite)