mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-30 12:33:52 -06:00
5c3c543d2e
- Test framework support API testing with multiple server for this we need to modify test_config.json(for user it’s test_config.json.in) and test_advanced_config.json(for user it’s test_advanced_config.json.in). Server details of PG and PPAS are included in both .in files. - Removed the logic of logging in the test client on each test scenario(As per Khushboo's comment in previous email). We need this logic in test cases under ‘browser/tests/’ as for test scenarios like change password and invalid login test cases as test client should be logged out first. So, as per this the code is slightly modified in ‘browser/tests/’.
89 lines
2.7 KiB
Python
89 lines
2.7 KiB
Python
#############################################################
|
|
#
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
#
|
|
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
|
|
# This software is released under the PostgreSQL Licence
|
|
#
|
|
##############################################################
|
|
|
|
import unittest
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
|
|
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
|
|
import config
|
|
|
|
# Check for SERVER mode
|
|
if config.SERVER_MODE:
|
|
for module_name in find_modules(pkg, False, True):
|
|
try:
|
|
module = import_module(module_name)
|
|
except ImportError:
|
|
pass
|
|
else:
|
|
for module_name in find_modules(pkg, False, True):
|
|
try:
|
|
# Exclude the test cases in browser node if SERVER_MODE
|
|
# is False
|
|
if "pgadmin.browser.tests" not in module_name:
|
|
module = import_module(module_name)
|
|
except ImportError:
|
|
pass
|
|
|
|
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
|