public inbox for [email protected]
help / color / mirror / Atom feedFrom: Priyanka Shendge <[email protected]>
To: Dave Page <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Cc: Kanchan Mohitey <[email protected]>
Subject: Re: pgAdmin IV API test cases patch
Date: Wed, 29 Jun 2016 19:22:11 +0530
Message-ID: <CAKmZXFRfX+Us9Bg2ACFGvGLTjjW02XETLEj3h5cHnZZBAbZwEQ@mail.gmail.com> (raw)
In-Reply-To: <CAKmZXFT34JxCPw=UbZ27jU8uL0KzFa3Lfpmge2V14F7GynGLWw@mail.gmail.com>
References: <CAKmZXFQ2Hj1-OZpSGFEBB-vOypQ_=1b4Yr_VytZ-E1=CBw9Yhw@mail.gmail.com>
<CA+OCxow8Q83e7Tm+BC2bxq=oqwd-m4JS3y2KpzgFemc=wX=f=A@mail.gmail.com>
<CAKmZXFTX9D_qOXGrvPa9sfFjc1A6VPebcpBn7vyzPEOH4pWfEg@mail.gmail.com>
<CAKmZXFRj8yY91TTxwQQ01eOQE8Rc7FPWuxGcjxaVY+QcWpgWDg@mail.gmail.com>
<CA+OCxoyqfK8pUGGmeO=5pyC=MOizNMOnfshAfgQ5NjMRnkjgmA@mail.gmail.com>
<CAKmZXFSgdtd9NDE=TysR68_tcwqFB2Sv-h+qK4K4i1HjxOd5ng@mail.gmail.com>
<CAKmZXFRWXd7ZrUhpJt-rD_YOE1xcK5haE1CwAj8DMVyS9Fs6yA@mail.gmail.com>
<CA+OCxoyiNMAem5bYAZ1XM16vK4wJETCCPncRgKYbVdmH2m4Ocg@mail.gmail.com>
<CAKmZXFRvn8JDL52ooxZYtrf0Aw+bMz6=spXmyP9Q7fq8kWjuDA@mail.gmail.com>
<CA+OCxowzMWyATh1_eEQ7hnrseaxuq8T3_+FDsCETLm=WaoRNEw@mail.gmail.com>
<CAKmZXFT34JxCPw=UbZ27jU8uL0KzFa3Lfpmge2V14F7GynGLWw@mail.gmail.com>
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgadmin-hackers>
Hi Dave,
As per discussion over mail i have created separate config files for
credentials
and test data.
PFA patch for same. Kindly, review and let me know for modifications.
On 27 June 2016 at 15:10, Priyanka Shendge <
[email protected]> wrote:
>
>
> On 27 June 2016 at 13:24, Dave Page <[email protected]> wrote:
>
>> On Sun, Jun 26, 2016 at 12:05 PM, Priyanka Shendge
>> <[email protected]> wrote:
>> >
>> >
>> > On 24 June 2016 at 16:17, Dave Page <[email protected]> wrote:
>> >>
>> >> Hi
>> >>
>> >> On Thu, Jun 23, 2016 at 2:41 PM, Priyanka Shendge
>> >> <[email protected]> wrote:
>> >> >
>> >> >
>> >> > On 15 June 2016 at 15:05, Priyanka Shendge
>> >> > <[email protected]> wrote:
>> >> >>
>> >> >> Thanks a lot Dave.
>> >> >>
>> >> >> On 15 June 2016 at 14:09, Dave Page <[email protected]> wrote:
>> >> >>>
>> >> >>> Hi
>> >> >>>
>> >> >>> On Thu, Jun 9, 2016 at 1:37 PM, Priyanka Shendge
>> >> >>> <[email protected]> wrote:
>> >> >>> > Hi Dave,
>> >> >>> >
>> >> >>> > PFA updated patch. I have made changes suggested by you.
>> >> >>> >
>> >> >>> > Kindly, review and let me know for more changes.
>> >> >>>
>> >> >>> OK, I got a bit further this time, but not there yet.
>> >> >>>
>> >> >>> 1) The patch overwrote my test_config.json file. That should never
>> >> >>> happen (that file shouldn't be in the source tree).
>> >> >>> test_config.json.in should be the file that's included in the
>> patch.
>> >> >>
>> >> >>
>> >> >> OK.
>> >> >>>
>> >> >>>
>> >> >>> 2) The updated test_config.json file is huge.
>> >> >
>> >> >
>> >> > Current configuration file web/regression/test_config.json contains
>> test
>> >> > data(credentials) for each tree node;
>> >> > which is used while adding and updating the respective node.
>> >>
>> >> Why would we need that?
>> >
>> >
>> > Each node file (e.g. test_db_add.py and test_db_put.py) uses respective
>> > credentials test data from
>> > test_config.json while execution.
>>
>> That doesn't answer my question - why do we need separate credentials
>> for each node?
>>
>
> Sorry for typo, its test data not credentials.
>
>
>>
>> >> We should have just one set of credentials for
>> >> everything.
>> >
>> >
>> > Let me know if my understanding is clear:
>> >
>> > Should i keep basic credentials of each node (database, schema) into
>> > test_config.json
>> > instead taking care of each field?
>>
>> You should have one set of credentials that's used for the entire test
>> run.
>>
>
> Sure. I'll separate the credentials and test data into 2 different files.
> So, a normal user can run the tests into one go after some minor
> credentials changes.
> And an advanced user can have an option to change the test data if he
> wants.
>
>>
>> >> >>> I should only need to
>> >> >>> define one or more connections, then be able to run the tests. If
>> you
>> >> >>> need to keep configuration info for "advanced users", let's put it
>> in
>> >> >>> a different file to avoid confusing/scaring everyone else. Maybe
>> split
>> >> >>> it into config.json for the stuff the user needs to edit
>> >> >>> (config.json.in would go in git), and test_config.json for the
>> test
>> >> >>> configuration.
>> >> >
>> >> >
>> >> > Should i keep login and server credentials into
>> >> > web/regression/test_config.json file and
>> >> > put respective node details into config.json file of respective
>> node's
>> >> > tests
>> >> > directory?
>> >>
>> >> Not if you expect users to need to edit them - and if not, why are the
>> >> values not just hard-coded?
>> >>
>> >> > e.g. for database node:
>> >> > I'll create config.json file into .../databases/tests/ directory
>> >> > put database add and update credentials into config.json
>> >>
>> >> The key here is to make it simple for users.
>> >>
>> >> - To run the default tests, they should be able to copy/edit a simple
>> >> file, and just add database server details for the server to run
>> >> against.
>> >>
>> >> - If we have configurable tests (because making them configurable adds
>> >> genuine value), then we can use an "advanced" config file to allow the
>> >> user to adjust settings as they want.
>> >>
>> >> In the simple case, the user should be able to run the tests
>> >> successfully within a minute or two from starting.
>> >>
>> >> In designing the layout for files etc, remember the following:
>> >>
>> >> - Users should never edit a file that is in our source control. That's
>> >> why we have .in files that we expect them to copy.
>> >>
>> >> - Unless they're an advanced user, they shouldn't need to copy the
>> >> config file for advanced options. That means that the tests should
>> >> have defaults that match what is in the template advanced config file
>> >> (or, the tests could read advanced.json.in if advanced.json doesn't
>> >> exist, though that does seem a little icky). Of course, those are
>> >> example filenames, not necessarily what you may choose.
>> >>
>> >> --
>> >> Dave Page
>> >> Blog: http://pgsnake.blogspot.com
>> >> Twitter: @pgsnake
>> >>
>> >> EnterpriseDB UK: http://www.enterprisedb.com
>> >> The Enterprise PostgreSQL Company
>> >
>> >
>> >
>> >
>> > --
>> > Best,
>> > Priyanka
>> >
>> > EnterpriseDB Corporation
>> > The Enterprise PostgreSQL Company
>>
>>
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>>
>> --
>> Sent via pgadmin-hackers mailing list ([email protected])
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgadmin-hackers
>>
>
>
>
> --
> Best,
> Priyanka
>
> EnterpriseDB Corporation
> The Enterprise PostgreSQL Company
>
--
Best,
Priyanka
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[application/octet-stream] pgadmin4_config_revised.patch (40.0K, 3-pgadmin4_config_revised.patch)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/tests/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/tests/__init__.py
new file mode 100644
index 0000000..60ed4c7
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/tests/__init__.py
@@ -0,0 +1,16 @@
+# ##########################################################################
+#
+# #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 DatabaseGenerateTestCase(BaseTestGenerator):
+
+ def runTest(self):
+ return
diff --git a/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_add.py b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_add.py
new file mode 100644
index 0000000..4278383
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_add.py
@@ -0,0 +1,101 @@
+# #################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2016, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+# ##################################################################
+
+from regression.config import config_data, advance_config_data, pickle_path
+from pgadmin.browser.tests.test_login import LoginTestCase
+import json
+import pickle
+import uuid
+import os
+from regression.test_utils import get_ids
+
+
+class DatabaseAddTestCase(LoginTestCase):
+ """
+ This class will check server group node present on the object browser's
+ tree node by response code.
+ """
+ priority = 7
+
+ scenarios = [
+ # Fetching default URL for database node.
+ ('Check Databases Node URL', dict(url='/browser/database/obj/'))
+ ]
+
+ def runTest(self):
+ """ This function will add database under 1st server of tree node. """
+
+ srv_id = get_ids()
+
+ server_id = srv_id["sid"][0]
+ srv_grp = config_data['test_server_group']
+
+ response = self.tester.post('browser/server/connect/' + str(srv_grp) +
+ '/' + server_id,
+ data=dict(
+ password=config_data
+ ['test_server_credentials'][0]
+ ['test_db_password']),
+ follow_redirects=True)
+
+ self.assertEquals(response.status_code, 200)
+
+ srv_connect = json.loads(response.data.decode())
+
+ if srv_connect['data']['connected']:
+
+ data = {
+ "datacl": advance_config_data['test_add_database_data'][0]
+ ['test_privileges_acl'],
+ "datconnlimit": advance_config_data
+ ['test_add_database_data'][0]['test_conn_limit'],
+ "datowner": advance_config_data
+ ['test_add_database_data'][0]['test_owner'],
+ "deffuncacl": advance_config_data
+ ['test_add_database_data'][0]['test_fun_acl'],
+ "defseqacl": advance_config_data
+ ['test_add_database_data'][0]['test_seq_acl'],
+ "deftblacl": advance_config_data
+ ['test_add_database_data'][0]['test_tbl_acl'],
+ "deftypeacl": advance_config_data
+ ['test_add_database_data'][0]['test_type_acl'],
+ "encoding": advance_config_data
+ ['test_add_database_data'][0]['test_encoding'],
+ "name": str(uuid.uuid4())[1:8],
+ "privileges": advance_config_data
+ ['test_add_database_data'][0]['test_privileges'],
+ "securities": advance_config_data
+ ['test_add_database_data'][0]['test_securities'],
+ "variables": advance_config_data
+ ['test_add_database_data'][0]['test_variables']
+ }
+
+ db_response = self.tester.post(self.url + str(srv_grp) + "/" +
+ server_id + "/",
+ data=json.dumps(data),
+ content_type='html/json')
+
+ self.assertTrue(db_response.status_code, 200)
+
+ respdata = json.loads(db_response.data.decode())
+
+ db_id = respdata['node']['_id']
+
+ if os.path.isfile(pickle_path):
+
+ exst_server_id = open(pickle_path, 'rb')
+
+ tol_server_id = pickle.load(exst_server_id)
+ pickle_id_dict = tol_server_id
+
+ pickle_id_dict["did"].append(db_id)
+
+ db_output = open(pickle_path, 'wb')
+ pickle.dump(pickle_id_dict, db_output)
+ db_output.close()
diff --git a/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_delete.py b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_delete.py
new file mode 100644
index 0000000..ca8ed9b
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_delete.py
@@ -0,0 +1,45 @@
+# #################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2016, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+# ##################################################################
+
+from regression.config import config_data
+from pgadmin.browser.tests.test_login import LoginTestCase
+import json
+from regression.test_nodes import test_getnodes
+from regression.test_utils import get_ids
+
+
+class DatabaseDeleteTestCase(LoginTestCase):
+ """ This class will delete the database under last added server. """
+
+ priority = 98
+
+ scenarios = [
+ # Fetching default URL for database node.
+ ('Check Databases Node URL', dict(url='/browser/database/obj/'))
+ ]
+
+ def runTest(self):
+ """ This function will delete the database."""
+
+ all_id = get_ids()
+ server_id = all_id["sid"][0]
+ db_id = all_id["did"][0]
+ srv_grp = config_data['test_server_group']
+
+ db_con = test_getnodes(node=self)
+
+ if len(db_con) == 0:
+ raise Exception("No database(s) to delete.")
+
+ response = self.tester.delete(self.url + str(srv_grp) + '/' +
+ str(server_id) + '/' + str(db_id),
+ follow_redirects=True)
+
+ respdata = json.loads(response.data.decode())
+ self.assertTrue(respdata['success'], 1)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_get.py b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_get.py
new file mode 100644
index 0000000..e931985
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_get.py
@@ -0,0 +1,43 @@
+# #################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2016, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+# ##################################################################
+
+from regression.config import config_data
+from pgadmin.browser.tests.test_login import LoginTestCase
+from regression.test_nodes import test_getnodes
+from regression.test_utils import get_ids
+
+
+class DatabasesGetTestCase(LoginTestCase):
+ """
+ This class will fetch added database under server node.
+ """
+ priority = 8
+
+ scenarios = [
+ # Fetching default URL for database node.
+ ('Check Databases Node URL', dict(url='/browser/database/obj/'))
+ ]
+
+ def runTest(self):
+ """ This function will fetch added database. """
+
+ all_id = get_ids()
+ server_id = all_id["sid"][0]
+ db_id = all_id["did"][0]
+ srv_grp = config_data['test_server_group']
+
+ db_con = test_getnodes(node=self)
+
+ if db_con['data']["connected"]:
+
+ response = self.tester.get(self.url + str(srv_grp) + '/' +
+ str(server_id) + '/' + str(db_id),
+ follow_redirects=True)
+
+ self.assertEquals(response.status_code, 200)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_put.py b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_put.py
new file mode 100644
index 0000000..ad83603
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/tests/test_db_put.py
@@ -0,0 +1,51 @@
+# #################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2016, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+# ##################################################################
+
+from regression.config import config_data, advance_config_data
+from pgadmin.browser.tests.test_login import LoginTestCase
+import json
+from regression.test_utils import get_ids
+from regression.test_nodes import test_getnodes
+
+
+class DatabasesUpdateTestCase(LoginTestCase):
+ """
+ This class will update the database under last added server.
+ """
+ priority = 9
+
+ scenarios = [
+ # Fetching default URL for database node.
+ ('Check Databases Node', dict(url='/browser/database/obj/'))
+ ]
+
+ def runTest(self):
+ """ This function will update the comments field of database."""
+
+ all_id = get_ids()
+ server_id = all_id["sid"][0]
+ db_id = all_id["did"][0]
+ srv_grp = config_data['test_server_group']
+
+ db_con = test_getnodes(node=self)
+
+ if db_con['data']["connected"]:
+
+ data = {
+ "comments": advance_config_data["test_db_update_data"][0]
+ ["test_comment"],
+ "id": db_id
+ }
+
+ put_response = self.tester.put(self.url + str(srv_grp) + '/' +
+ str(server_id) + '/' + str(db_id),
+ data=json.dumps(data),
+ follow_redirects=True)
+
+ self.assertEquals(put_response.status_code, 200)
diff --git a/web/pgadmin/browser/server_groups/servers/tests/__init__.py b/web/pgadmin/browser/server_groups/servers/tests/__init__.py
index 28cdb94..4fd2066 100644
--- a/web/pgadmin/browser/server_groups/servers/tests/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/tests/__init__.py
@@ -12,4 +12,4 @@ from pgadmin.utils.route import BaseTestGenerator
class ServerGenerateTestCase(BaseTestGenerator):
def runTest(self):
- print ("In ServerGenerateTestCase...")
+ return
diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_server_add.py b/web/pgadmin/browser/server_groups/servers/tests/test_server_add.py
index 0af13d3..7499b85 100644
--- a/web/pgadmin/browser/server_groups/servers/tests/test_server_add.py
+++ b/web/pgadmin/browser/server_groups/servers/tests/test_server_add.py
@@ -8,16 +8,14 @@
# ##########################################################################
import json
-
+import pickle
+import os
from pgadmin.browser.tests.test_login import LoginTestCase
-from regression.config import config_data
+from regression.config import config_data, pickle_path
class ServersAddTestCase(LoginTestCase):
- """
- This class will add the servers under default server group and verify with
- server's name.
- """
+ """ This class will add the servers under default server group. """
priority = 4
@@ -27,14 +25,19 @@ class ServersAddTestCase(LoginTestCase):
]
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.
- """
+ """ This function will add the server under default server group."""
+
+ # Storing parent id's into pickle dict
+ pickle_id_dict = \
+ {
+ "sid": [], # server
+ "did": [] # database
+ }
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'],
@@ -44,10 +47,20 @@ class ServersAddTestCase(LoginTestCase):
"role": "",
"sslmode": srv['test_sslmode']}
- url = self.url + str(srv_grp) + "/"
-
- response = self.tester.post(url, data=json.dumps(data),
+ response = self.tester.post(self.url + str(srv_grp) + "/",
+ 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'])
+ respdata = json.loads(response.data.decode())
+
+ server_id = respdata['node']['_id']
+
+ if os.path.isfile(pickle_path):
+ exst_server_id = open(pickle_path, 'rb')
+ pickle_id_dict = pickle.load(exst_server_id)
+
+ pickle_id_dict["sid"].append(server_id)
+ output = open(pickle_path, 'wb')
+ pickle.dump(pickle_id_dict, output)
+ output.close()
diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_server_delete.py b/web/pgadmin/browser/server_groups/servers/tests/test_server_delete.py
index 329d74f..997308e 100644
--- a/web/pgadmin/browser/server_groups/servers/tests/test_server_delete.py
+++ b/web/pgadmin/browser/server_groups/servers/tests/test_server_delete.py
@@ -8,17 +8,14 @@
# ##################################################################
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
+class ServerDeleteTestCase(LoginTestCase):
+ """ This class will delete the last server present under tree node."""
+
+ priority = 99
scenarios = [
# Fetching the default url for server node
@@ -26,32 +23,22 @@ class ServersDeleteTestCase(LoginTestCase):
]
def runTest(self):
- """
- This function will get all available servers under object browser
- and delete the servers using server id.
- """
+ """ This function will get all available servers under object browser
+ and delete the last server 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) + "/"
- url = self.url + str(srv_grp) + "/"
+ response = self.tester.get(url)
+ respdata = json.loads(response.data.decode())
- response = self.tester.get(url, data=json.dumps(data),
- content_type='html/json')
- self.assertTrue(response.status_code, 200)
- respdata = json.loads(response.data)
+ if len(respdata) == 0:
+ raise Exception("No server(s) to delete.")
- 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)
+ # delete last server
+ server = respdata[-1]
+ response = self.tester.delete(url + str(server['id']))
+ self.assertTrue(response.status_code, 200)
+ respdata = json.loads(response.data.decode())
+ self.assertTrue(respdata['success'], 1)
diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_server_get.py b/web/pgadmin/browser/server_groups/servers/tests/test_server_get.py
index 050843e..163fef3 100644
--- a/web/pgadmin/browser/server_groups/servers/tests/test_server_get.py
+++ b/web/pgadmin/browser/server_groups/servers/tests/test_server_get.py
@@ -7,15 +7,14 @@
#
# ##########################################################################
-import json
-
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
+from regression.test_utils import get_ids
class ServersGetTestCase(LoginTestCase):
"""
- This class will check server node present on the object browser's tree node
+ This class will fetch added servers under default server group
by response code.
"""
@@ -27,23 +26,16 @@ class ServersGetTestCase(LoginTestCase):
]
def runTest(self):
- """
- This function will get all available servers present under
- object browser.
- """
+ """ This function will fetch the added servers to object browser. """
+ all_id = get_ids()
+ server_id = all_id["sid"]
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),
+ for srv in server_id:
+
+ response = self.tester.get(self.url + str(srv_grp) + '/' +
+ str(srv),
content_type='html/json')
- self.assertTrue(response.status_code, 200)
+
+ self.assertEquals(response.status_code, 200)
diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_server_put.py b/web/pgadmin/browser/server_groups/servers/tests/test_server_put.py
index 306bb03..f8cef24 100644
--- a/web/pgadmin/browser/server_groups/servers/tests/test_server_put.py
+++ b/web/pgadmin/browser/server_groups/servers/tests/test_server_put.py
@@ -8,16 +8,13 @@
# ##########################################################################
import json
-
from pgadmin.browser.tests.test_login import LoginTestCase
from regression.config import config_data
+from regression.test_utils import get_ids
-class ServersUpdateTestCase(LoginTestCase):
- """
- This class will check server node present on the object browser's tree node
- by response code.
- """
+class ServerUpdateTestCase(LoginTestCase):
+ """ This class will update server's comment field. """
priority = 6
@@ -27,39 +24,41 @@ class ServersUpdateTestCase(LoginTestCase):
]
def runTest(self):
- """
- This function will edit and update the server's comment field
- by the server id.
- """
+ """ This function will update the server's comment field. """
+ all_id = get_ids()
+ server_id = all_id["sid"][0]
srv_grp = config_data['test_server_group']
- for srv in config_data['test_server_credentials']:
+ response = self.tester.get(self.url + str(srv_grp) + '/' +
+ str(server_id),
+ follow_redirects=True)
- 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']}
+ con_response = self.tester.post('browser/server/connect/{0}/{1}'.format
+ (srv_grp, server_id),
+ data=dict(password=
+ config_data
+ ['test_server_credentials'][0]
+ ['test_db_password']),
+ follow_redirects=True)
- url = self.url + str(srv_grp) + "/"
+ srv_con = json.loads(con_response.data.decode())
- response = self.tester.get(url, data=json.dumps(data),
- content_type='html/json')
+ if len(srv_con) == 0:
+ raise Exception("No Server(s) connected to update.")
- self.assertTrue(response.status_code, 200)
- respdata = json.loads(response.data)
+ data = \
+ {
+ "comment": config_data
+ ['test_server_update_data']['test_comment'],
+ "id": server_id
+ }
- for server in respdata:
+ put_response = self.tester.put(self.url + str(srv_grp) + '/' +
+ str(server_id), data=json.dumps(data),
+ content_type='html/json')
- url = self.url + str(srv_grp) + "/" + json.dumps(server['id'])
+ self.assertEquals(put_response.status_code, 200)
- 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)
+ respdata = json.loads(put_response.data.decode())
+ self.assertTrue(respdata['success'], 1)
diff --git a/web/pgadmin/browser/server_groups/tests/test_sg_add.py b/web/pgadmin/browser/server_groups/tests/test_sg_add.py
deleted file mode 100644
index e70bb65..0000000
--- a/web/pgadmin/browser/server_groups/tests/test_sg_add.py
+++ /dev/null
@@ -1,36 +0,0 @@
-###########################################################################
-#
-# 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)
diff --git a/web/pgadmin/browser/server_groups/tests/test_sg_get.py b/web/pgadmin/browser/server_groups/tests/test_sg_get.py
new file mode 100644
index 0000000..c552d8e
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/tests/test_sg_get.py
@@ -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 SgGetTestCase(LoginTestCase):
+ """
+ This class will check available server groups in pgAdmin.
+ """
+
+ priority = 3
+
+ 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."""
+
+ srv_grp = config_data['test_server_group']
+
+ response = self.tester.get(self.url + str(srv_grp),
+ content_type='html/json')
+ self.assertEquals(response.status_code, 200)
+ respdata = json.loads(response.data.decode())
+ self.assertTrue(respdata['id'], srv_grp)
diff --git a/web/pgadmin/browser/tests/__init__.py b/web/pgadmin/browser/tests/__init__.py
index 2381efd..4470711 100644
--- a/web/pgadmin/browser/tests/__init__.py
+++ b/web/pgadmin/browser/tests/__init__.py
@@ -11,5 +11,6 @@ from pgadmin.utils.route import BaseTestGenerator
class BrowserGenerateTestCase(BaseTestGenerator):
+
def runTest(self):
- print ("In BrowserGenerateTestCase...")
+ return
diff --git a/web/pgadmin/browser/tests/test_change_password.py b/web/pgadmin/browser/tests/test_change_password.py
index dedb7d9..5c4930d 100644
--- a/web/pgadmin/browser/tests/test_change_password.py
+++ b/web/pgadmin/browser/tests/test_change_password.py
@@ -85,10 +85,10 @@ class ChangePasswordTestCase(LoginTestCase):
"""This function will check change password functionality."""
response = self.tester.get('/change', follow_redirects=True)
- self.assertIn('pgAdmin 4 Password Change', response.data)
+ self.assertIn('pgAdmin 4 Password Change', response.data.decode('utf8'))
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)
+ self.assertIn(self.respdata, response.data.decode('utf8'))
diff --git a/web/pgadmin/browser/tests/test_login.py b/web/pgadmin/browser/tests/test_login.py
index 7c2b796..d272a63 100644
--- a/web/pgadmin/browser/tests/test_login.py
+++ b/web/pgadmin/browser/tests/test_login.py
@@ -8,7 +8,6 @@
##########################################################################
import uuid
-
from pgadmin.utils.route import BaseTestGenerator
from regression.config import config_data
@@ -67,7 +66,9 @@ class LoginTestCase(BaseTestGenerator):
['test_login_username']),
password=(config_data['pgAdmin4_login_credentials']
['test_login_password']),
- respdata='You are currently running version'))
+ respdata='Gravatar image for %s' %
+ config_data['pgAdmin4_login_credentials']
+ ['test_login_username']))
]
def runTest(self):
@@ -76,4 +77,4 @@ class LoginTestCase(BaseTestGenerator):
response = self.tester.post('/login', data=dict(
email=self.email, password=self.password),
follow_redirects=True)
- self.assertIn(self.respdata, response.data)
+ self.assertIn(self.respdata, response.data.decode('utf8'))
diff --git a/web/pgadmin/browser/tests/test_logout.py b/web/pgadmin/browser/tests/test_logout.py
index 8971e72..d9611ae 100644
--- a/web/pgadmin/browser/tests/test_logout.py
+++ b/web/pgadmin/browser/tests/test_logout.py
@@ -14,14 +14,13 @@ 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.
+ logged-in.
"""
- priority = 3
+ priority = 100
scenarios = [
- # This test case validate the logout page
+ # This test case validate the logout page.
('Logging Out', dict(respdata='Redirecting...'))
]
@@ -29,7 +28,7 @@ class LogoutTest(LoginTestCase):
"""This function checks the logout functionality."""
response = self.tester.get('/logout')
- self.assertIn(self.respdata, response.data)
+ self.assertIn(self.respdata, response.data.decode('utf8'))
def tearDown(self):
"""
diff --git a/web/pgadmin/browser/tests/test_reset_password.py b/web/pgadmin/browser/tests/test_reset_password.py
index 030b182..31a3992 100644
--- a/web/pgadmin/browser/tests/test_reset_password.py
+++ b/web/pgadmin/browser/tests/test_reset_password.py
@@ -41,8 +41,9 @@ class ResetPasswordTestCase(BaseTestGenerator):
"""This function checks reset password functionality."""
response = self.tester.get('/reset')
- self.assertIn('Recover pgAdmin 4 Password', response.data)
+ self.assertIn('Recover pgAdmin 4 Password',
+ response.data.decode('utf8'))
response = self.tester.post(
'/reset', data=dict(email=self.email),
follow_redirects=True)
- self.assertIn(self.respdata, response.data)
+ self.assertIn(self.respdata, response.data.decode('utf8'))
diff --git a/web/pgadmin/utils/route.py b/web/pgadmin/utils/route.py
index fb9de69..e439965 100644
--- a/web/pgadmin/utils/route.py
+++ b/web/pgadmin/utils/route.py
@@ -52,7 +52,10 @@ class TestsGeneratorRegistry(ABCMeta):
from werkzeug.utils import find_modules
for module_name in find_modules(pkg, False, True):
- module = import_module(module_name)
+ try:
+ module = import_module(module_name)
+ except ImportError:
+ pass
import six
diff --git a/web/regression/README b/web/regression/README
index e0003e4..44eedfb 100644
--- a/web/regression/README
+++ b/web/regression/README
@@ -40,23 +40,27 @@ General Information
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.
+2) The pgAdmin4 source tree includes 2 different configuration file templates.
+ One file template for the server configuration
+ named ‘test_config.json.in' and another for test configuration named
+ 'test_advance_config.json.in' in the ‘pgAdmin4/web/regression’ directory.
+ After completing the pgAdmin4 configuration, you must make a working copy of
+ the templates called test_config.json and test_advance_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
+ configuration file named test_config.json (same way user can copy
+ test_advance_config.json.in file into test_advance_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)
+ 2b) After creating the server and test 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.
+ If you move the file to another location, you must create a symbolic
+ link that specifies the new location.
2c) Specifying Server Configuration file:
@@ -64,6 +68,13 @@ General Information
server details and connection properties as per their local setup. The
test_config file is in json format and property values are case-sensitive.
+ 2d) Specifying the Test Configuration file:
+
+ The user can add/change test data as per their need. The
+ test_advance_config file is in json format and property values are
+ case-sensitive.
+
+
Test Data Details
-----------------
diff --git a/web/regression/config.py b/web/regression/config.py
index bef65fb..f48eade 100644
--- a/web/regression/config.py
+++ b/web/regression/config.py
@@ -14,3 +14,8 @@ root = os.path.dirname(os.path.realpath(__file__))
with open(root + '/test_config.json') as data_file:
config_data = json.load(data_file)
+
+with open(root + '/test_advance_config.json') as data_file:
+ advance_config_data = json.load(data_file)
+
+pickle_path = os.path.join(root, 'parent_id.pkl')
diff --git a/web/regression/test_advance_config.json.in b/web/regression/test_advance_config.json.in
new file mode 100644
index 0000000..3729bcb
--- /dev/null
+++ b/web/regression/test_advance_config.json.in
@@ -0,0 +1,105 @@
+{
+ "test_add_database_data": [
+ {
+ "test_privileges_acl": [
+ {
+ "grantee": "postgres",
+ "grantor": "postgres",
+ "privileges": [
+ {
+ "privilege_type": "C",
+ "privilege": true,
+ "with_grant": true
+ },
+ {
+ "privilege_type": "T",
+ "privilege": true,
+ "with_grant": false
+ }
+ ]
+ }
+ ],
+ "test_conn_limit": -1,
+ "test_owner": "postgres",
+ "test_fun_acl": [
+ {
+ "grantee": "postgres",
+ "grantor": "postgres",
+ "privileges": [
+ {
+ "privilege_type": "X",
+ "privilege": true,
+ "with_grant": false
+ }
+ ]
+ }
+ ],
+ "test_seq_acl": [
+ {
+ "grantee": "postgres",
+ "grantor": "postgres",
+ "privileges": [
+ {
+ "privilege_type": "r",
+ "privilege": true,
+ "with_grant": false
+ },
+ {
+ "privilege_type": "w",
+ "privilege": true,
+ "with_grant": false
+ },
+ {
+ "privilege_type": "U",
+ "privilege": true,
+ "with_grant": false
+ }
+ ]
+ }
+ ],
+ "test_tbl_acl": [
+ {
+ "grantee": "postgres",
+ "grantor": "postgres",
+ "privileges": [
+ {
+ "privilege_type": "a",
+ "privilege": true,
+ "with_grant": true
+ },
+ {
+ "privilege_type": "r",
+ "privilege": true,
+ "with_grant": false
+ }
+ ]
+ }
+ ],
+ "test_type_acl": [
+ {
+ "grantee": "postgres",
+ "grantor": "postgres",
+ "privileges": [
+ {
+ "privilege_type": "U",
+ "privilege": true,
+ "with_grant": false
+ }
+ ]
+ }
+ ],
+ "test_encoding": "UTF8",
+ "test_name": "test_db_automation",
+ "test_privileges": [],
+ "test_securities": [],
+ "test_variables": []
+ }
+ ],
+
+ "test_db_update_data": [
+ {
+ "test_comment": "This is db update comment"
+ }
+ ]
+
+}
diff --git a/web/regression/test_nodes.py b/web/regression/test_nodes.py
new file mode 100644
index 0000000..b3fd5ef
--- /dev/null
+++ b/web/regression/test_nodes.py
@@ -0,0 +1,42 @@
+# #################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2016, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+# ##################################################################
+
+from regression.config import config_data
+import json
+from regression.test_utils import get_ids
+
+
+def test_getnodes(node=None):
+ # Connect to server and database.
+
+ if not node:
+ return None
+
+ all_id = get_ids()
+
+ server_id = all_id["sid"][0]
+ db_id = all_id["did"][0]
+ srv_grp = config_data['test_server_group']
+
+ # Connect to server
+ response = node.tester.post('browser/server/connect/{0}/{1}'.format
+ (srv_grp, server_id),
+ data=dict(password=config_data
+ ['test_server_credentials'][0]
+ ['test_db_password']), follow_redirects=True)
+
+ # Connect to database
+ con_response = node.tester.post('browser/database/connect/'
+ '{0}/{1}/{2}'.format
+ (srv_grp, server_id, db_id),
+ follow_redirects=True)
+
+ db_con = json.loads(con_response.data.decode())
+
+ return db_con
diff --git a/web/regression/test_utils.py b/web/regression/test_utils.py
new file mode 100644
index 0000000..c68744f
--- /dev/null
+++ b/web/regression/test_utils.py
@@ -0,0 +1,20 @@
+# #################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2016, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+# ##################################################################
+
+import pickle
+from regression.config import pickle_path
+
+
+def get_ids(url=pickle_path):
+ # This function will read parent nodes id's from pickle and return it.
+
+ output = open(url, 'rb')
+ ids = pickle.load(output)
+ output.close()
+ return ids
diff --git a/web/regression/testsuite.py b/web/regression/testsuite.py
index 6e6fb0c..45069b2 100644
--- a/web/regression/testsuite.py
+++ b/web/regression/testsuite.py
@@ -13,7 +13,8 @@ them to TestSuite. """
import os
import sys
import unittest
-
+import operator
+import logging
from testscenarios.scenarios import generate_scenarios
# We need to include the root directory in sys.path to ensure that we can
@@ -45,6 +46,22 @@ TestsGeneratorRegistry.load_generators('pgadmin')
# application. We can trigger test request to the application.
test_client = app.test_client()
+class StreamToLogger(object):
+ """
+ Fake file-like stream object that redirects writes to a logger instance.
+ """
+ def __init__(self, logger, log_level=logging.INFO):
+ self.logger = logger
+ self.log_level = log_level
+ self.linebuf = ''
+
+ def write(self, buf):
+ for line in buf.rstrip().splitlines():
+ self.logger.log(self.log_level, line.rstrip())
+
+ def flush(self):
+ pass
+
def suite():
""" Defining test suite which will execute all the testcases present in
@@ -59,6 +76,8 @@ def suite():
modules.insert(gen.priority, gen)
+ modules.sort(key=operator.attrgetter('priority'))
+
for m in modules:
obj = m()
obj.setTestClient(test_client)
@@ -69,5 +88,25 @@ def suite():
if __name__ == '__main__':
+
+ print("Please check output in file: logger.log placed at "
+ ".../pgadmin4/web/regression")
+
+ logging.basicConfig(level=logging.DEBUG,
+ format='%(asctime)s:%(levelname)s:%(name)s:%(message)s',
+ filename="logger.log",
+ filemode='w'
+ )
+
+ stdout_logger = logging.getLogger('STDOUT')
+ sl = StreamToLogger(stdout_logger, logging.INFO)
+ sys.stdout = sl
+
+ stderr_logger = logging.getLogger('STDERR')
+ sl = StreamToLogger(stderr_logger, logging.ERROR)
+ sys.stderr = sl
+
suite = suite()
- tests = unittest.TextTestRunner(descriptions=True, verbosity=2).run(suite)
+ tests = unittest.TextTestRunner(descriptions=True, verbosity=2,
+ stream=sys.stdout).run(suite)
+ os.remove("parent_id.pkl")
view thread (27+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: pgAdmin IV API test cases patch
In-Reply-To: <CAKmZXFRfX+Us9Bg2ACFGvGLTjjW02XETLEj3h5cHnZZBAbZwEQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox