ucampostgresvro 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ucampostgresvro/DBA.py +792 -0
- ucampostgresvro/__init__.py +1 -0
- ucampostgresvro/__main__.py +134 -0
- ucampostgresvro/ca.crt +19 -0
- ucampostgresvro/exceptions.py +2 -0
- ucampostgresvro/tests/__init__.py +0 -0
- ucampostgresvro/tests/conftest.py +63 -0
- ucampostgresvro/tests/dbconnect.py +10 -0
- ucampostgresvro/tests/test_DB.py +339 -0
- ucampostgresvro/tests/utils.py +116 -0
- ucampostgresvro/tools.py +7 -0
- ucampostgresvro/utils.py +197 -0
- ucampostgresvro-0.1.0.dist-info/LICENSE +21 -0
- ucampostgresvro-0.1.0.dist-info/METADATA +232 -0
- ucampostgresvro-0.1.0.dist-info/RECORD +16 -0
- ucampostgresvro-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1 @@
|
|
1
|
+
VERSION = "0.1.0"
|
@@ -0,0 +1,134 @@
|
|
1
|
+
import logging
|
2
|
+
import sys
|
3
|
+
from typing import Dict
|
4
|
+
|
5
|
+
from ucampostgresvro import VERSION, utils
|
6
|
+
from ucampostgresvro.DBA import DB
|
7
|
+
from ucampostgresvro.exceptions import DbException
|
8
|
+
from ucampostgresvro.secrets import password
|
9
|
+
from ucampostgresvro.tools import DEFAULT_TABLES
|
10
|
+
|
11
|
+
|
12
|
+
def setloggerdetail():
|
13
|
+
LOG = logging.getLogger(__name__)
|
14
|
+
stdout_handler = logging.StreamHandler(sys.stdout)
|
15
|
+
logging.basicConfig(
|
16
|
+
level=logging.INFO,
|
17
|
+
format="%(asctime)s [%(levelname)s] %(message)s",
|
18
|
+
datefmt="%m/%d/%Y %H:%M:%S",
|
19
|
+
handlers=[stdout_handler],
|
20
|
+
)
|
21
|
+
return LOG
|
22
|
+
|
23
|
+
|
24
|
+
def pre_setupconfig(db_params: Dict[str, str]) -> bool:
|
25
|
+
"""Create the Database
|
26
|
+
|
27
|
+
Args:
|
28
|
+
db_params (Dict[str, str]): provide parameters for DB connection.
|
29
|
+
|
30
|
+
Returns:
|
31
|
+
bool: True if creation of database is suceess else False
|
32
|
+
"""
|
33
|
+
result = []
|
34
|
+
if not utils.check_table_exists(DEFAULT_TABLES.get("user"), db_params):
|
35
|
+
result.append(utils.create_user_table(DEFAULT_TABLES.get("user"), db_params))
|
36
|
+
|
37
|
+
if not utils.check_table_exists(DEFAULT_TABLES.get("deploymentid"), db_params):
|
38
|
+
result.append(
|
39
|
+
utils.create_deployment_table(DEFAULT_TABLES.get("deploymentid"), db_params)
|
40
|
+
)
|
41
|
+
|
42
|
+
if not utils.check_table_exists(DEFAULT_TABLES.get("proj"), db_params):
|
43
|
+
result.append(
|
44
|
+
utils.create_project_table(
|
45
|
+
DEFAULT_TABLES.get("proj"), DEFAULT_TABLES.get("user"), db_params
|
46
|
+
)
|
47
|
+
)
|
48
|
+
|
49
|
+
if not utils.check_table_exists(DEFAULT_TABLES.get("grant"), db_params):
|
50
|
+
result.append(
|
51
|
+
utils.create_grant_table(
|
52
|
+
DEFAULT_TABLES.get("grant"), DEFAULT_TABLES.get("user"), db_params
|
53
|
+
)
|
54
|
+
)
|
55
|
+
|
56
|
+
if not utils.check_table_exists(DEFAULT_TABLES.get("costing"), db_params):
|
57
|
+
result.append(
|
58
|
+
utils.create_costing_table(
|
59
|
+
DEFAULT_TABLES.get("costing"),
|
60
|
+
DEFAULT_TABLES.get("deploymentid"),
|
61
|
+
DEFAULT_TABLES.get("proj"),
|
62
|
+
DEFAULT_TABLES.get("grant"),
|
63
|
+
db_params,
|
64
|
+
)
|
65
|
+
)
|
66
|
+
|
67
|
+
return False not in result
|
68
|
+
|
69
|
+
|
70
|
+
def main():
|
71
|
+
LOG = setloggerdetail()
|
72
|
+
LOG.info(f"VERSION : {VERSION}")
|
73
|
+
db_params = {
|
74
|
+
"dbname": "vrapricing",
|
75
|
+
"user": "postgres",
|
76
|
+
"password": password,
|
77
|
+
"host": "infra-db.srv.uis.cam.ac.uk", # or your database host
|
78
|
+
"port": "5432", # default PostgreSQL port
|
79
|
+
"sslmode": "require", # or 'verify-ca' or 'verify-full' based on your needs
|
80
|
+
"sslrootcert": "./ca.crt", # path to your client certificate
|
81
|
+
}
|
82
|
+
db = DB(db_params)
|
83
|
+
|
84
|
+
if not pre_setupconfig(db_params):
|
85
|
+
raise DbException("ERROR: Tables are not created successfully")
|
86
|
+
|
87
|
+
# db.insert_vrauser("ll220", "len")
|
88
|
+
# print(db.get_vrauser("ll220"))
|
89
|
+
# db.update_vrauser("ll220", "bda20", 'Ben Argyle')
|
90
|
+
# print(db.get_vrauser())
|
91
|
+
# db.remove_vrauser('bda20')
|
92
|
+
# print(db.get_vrauser())
|
93
|
+
|
94
|
+
# db.insert_deployment_id("1231ee112ad11212")
|
95
|
+
# db.update_deployment_id("1231ee112ad11212", "1231a")
|
96
|
+
# print(db.get_deployment_id("1231a"))
|
97
|
+
# db.remove_deployment_id('1231a')
|
98
|
+
# db.insert_deployment_id("123")
|
99
|
+
# print(db.get_deployment_id())
|
100
|
+
|
101
|
+
# print(db.get_project())
|
102
|
+
# db.insert_project("0001",1,100.0)
|
103
|
+
# db.insert_project("0101",2,100.0)
|
104
|
+
# db.update_project("0001", "0002", 1, 200)
|
105
|
+
# db.remove_project("0002")
|
106
|
+
# db.insert_project("0001",1,100.0)
|
107
|
+
# db.insert_project("0002",1,200.0)
|
108
|
+
# print(db.get_project("0002",1,200))
|
109
|
+
|
110
|
+
# print(db.get_grant())
|
111
|
+
# db.insert_grant("0001",1,100.0)
|
112
|
+
# db.update_grant("0001", "0002", 1, 200)
|
113
|
+
# print(db.get_grant())
|
114
|
+
# db.remove_grant("0002")
|
115
|
+
# print(db.get_grant())
|
116
|
+
# db.insert_grant("0001",1,100.0)
|
117
|
+
# db.insert_grant("0002",1,200.0)
|
118
|
+
# print(db.get_grant("0002",1,200))
|
119
|
+
|
120
|
+
# print(db.get_costing())
|
121
|
+
# db.insert_costing(1, "Initial Resource", project_id=2, grant_id=None)
|
122
|
+
# db.insert_costing(1, "Initial Resource", project_id=None, grant_id=1)
|
123
|
+
# db.update_costing(1, "Duration Expansion", old_grant_id=None,
|
124
|
+
# old_project_id=2, grant_id=None, project_id=2)
|
125
|
+
# print(db.get_costing())
|
126
|
+
# print(db.get_costing())
|
127
|
+
# db.remove_costing(1, "Duration Expansion", 4, None)
|
128
|
+
# print(db.get_costing())
|
129
|
+
|
130
|
+
db.closedb()
|
131
|
+
|
132
|
+
|
133
|
+
if __name__ == "__main__":
|
134
|
+
main()
|
ucampostgresvro/ca.crt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDGTCCAgGgAwIBAgIUGSvY0cDL0E2opwi3ovKt0Ctuf0swDQYJKoZIhvcNAQEL
|
3
|
+
BQAwGzEZMBcGA1UEAwwQaW5mcmEtZGIgcm9vdCBDQTAgFw0yMTA3MTUxMTMwNTBa
|
4
|
+
GA8yMTIxMDYyMTExMzA1MFowGzEZMBcGA1UEAwwQaW5mcmEtZGIgcm9vdCBDQTCC
|
5
|
+
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL8Z6OlwQ1b4W2QO+0bhMjxQ
|
6
|
+
xnTZeiWg+jOwrbWdOgxcjOt0KB0lCMuIVcBiMkVdh32Ov0q+FpinJ97/ZnZBhiYf
|
7
|
+
QqrNYjsfBUsWy/q9x/b0RcSHtkGrtHsU3YloeyzzdB6jIg8SC35p0Ht6BQuYrP07
|
8
|
+
NHjvMzZKbS/+PZIDs5fhyQVl6isEy1xvqJ/nDlRg2HItYOd7lzXC46E7AIj2lqIv
|
9
|
+
GCUKAszFnf6OsZEwr0XoKeZqgPbrsCY6RqcT3uWUM86C3F8b6wee/9AvapElvWg5
|
10
|
+
eMoIgW3oCvpBSgVuCKWj5YEycz5kQ14LIxacocSSoghyhN3ce72gjtOw16ZkKyEC
|
11
|
+
AwEAAaNTMFEwHQYDVR0OBBYEFDtnsz4XBSEfkTCuTgAeiGmubTrXMB8GA1UdIwQY
|
12
|
+
MBaAFDtnsz4XBSEfkTCuTgAeiGmubTrXMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZI
|
13
|
+
hvcNAQELBQADggEBALiBdm+Ka7R6AQePfMjVNoqPqjueorIhxazcoSNrJkl5+lzc
|
14
|
+
lpB8NznWG6XxTJxvXQ2Am2/Gv3SOPZaceTJFD2G54AuQlrH2ic5KUvZJaJQ5uYCt
|
15
|
+
DaH5U96O9mJ2GtVMsgPocbTH2lSkCCkfMmiP80lj6Ms/gSa3oWfhacCl8OhcjI+D
|
16
|
+
Etz5dGtVbqavp4DK4b8nt29Ok3v4mWZ6UAnCr3ci8JGFMcmPS6Nh+Tqy6nB7yj4Z
|
17
|
+
TgjzT3vqtTROfhE25xSAIZFsA0YM4+pTGJ85W9hZewT52HG8K0bV54/EIIOXHFyu
|
18
|
+
SnMIaMvdpveWbgzocgJY54H0i9k+dsjC0dal40w=
|
19
|
+
-----END CERTIFICATE-----
|
File without changes
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import pytest
|
2
|
+
|
3
|
+
from ucampostgresvro.tests import utils as tools
|
4
|
+
from ucampostgresvro.exceptions import DbException
|
5
|
+
|
6
|
+
|
7
|
+
data_params = tools.db_params
|
8
|
+
|
9
|
+
|
10
|
+
@pytest.fixture
|
11
|
+
def user_db_fixture():
|
12
|
+
# Setup
|
13
|
+
if tools.check_db_connection(data_params):
|
14
|
+
db = tools.setup_user_table_func(data_params)
|
15
|
+
yield db
|
16
|
+
# tear_down
|
17
|
+
tools.teardown_user_table_func(data_params)
|
18
|
+
else:
|
19
|
+
raise DbException("Could not connect to the database after several retries.")
|
20
|
+
|
21
|
+
|
22
|
+
@pytest.fixture
|
23
|
+
def deploymentid_db_fixture():
|
24
|
+
# Setup
|
25
|
+
if tools.check_db_connection(data_params):
|
26
|
+
db = tools.setup_deployment_table_func(data_params)
|
27
|
+
yield db
|
28
|
+
tools.teardown_deployment_table_func(data_params)
|
29
|
+
else:
|
30
|
+
raise DbException("Could not connect to the database after several retries.")
|
31
|
+
|
32
|
+
|
33
|
+
@pytest.fixture
|
34
|
+
def project_db_fixture():
|
35
|
+
# Setup
|
36
|
+
if tools.check_db_connection(data_params):
|
37
|
+
db = tools.setup_project_table_func(data_params)
|
38
|
+
yield db
|
39
|
+
tools.teardown_project_table_func(data_params)
|
40
|
+
else:
|
41
|
+
raise DbException("Could not connect to the database after several retries.")
|
42
|
+
|
43
|
+
|
44
|
+
@pytest.fixture
|
45
|
+
def grant_db_fixture():
|
46
|
+
# Setup
|
47
|
+
if tools.check_db_connection(data_params):
|
48
|
+
db = tools.setup_grant_table_func(data_params)
|
49
|
+
yield db
|
50
|
+
tools.teardown_grant_table_func(data_params)
|
51
|
+
else:
|
52
|
+
raise DbException("Could not connect to the database after several retries.")
|
53
|
+
|
54
|
+
|
55
|
+
@pytest.fixture
|
56
|
+
def costing_db_fixture():
|
57
|
+
# Setup
|
58
|
+
if tools.check_db_connection(data_params):
|
59
|
+
db = tools.setup_costing_table_func(data_params)
|
60
|
+
yield db
|
61
|
+
tools.teardown_costing_table_func(data_params)
|
62
|
+
else:
|
63
|
+
raise DbException("Could not connect to the database after several retries.")
|
@@ -0,0 +1,339 @@
|
|
1
|
+
from ucampostgresvro.tests.utils import tables
|
2
|
+
|
3
|
+
|
4
|
+
def test_user_insertion(user_db_fixture):
|
5
|
+
db = user_db_fixture
|
6
|
+
result = db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
7
|
+
info = db.get_vrauser(None, None, tables.get("user"))
|
8
|
+
assert len(info) == 1
|
9
|
+
assert result
|
10
|
+
|
11
|
+
|
12
|
+
def test_user_update(user_db_fixture):
|
13
|
+
db = user_db_fixture
|
14
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
15
|
+
result = db.update_vrauser("im530", "ll220", "Len", tables.get("user"))
|
16
|
+
info = db.get_vrauser(None, None, tables.get("user"))
|
17
|
+
assert len(info) == 1
|
18
|
+
assert result
|
19
|
+
assert info[0][1] == "ll220"
|
20
|
+
|
21
|
+
|
22
|
+
def test_user_remove(user_db_fixture):
|
23
|
+
db = user_db_fixture
|
24
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
25
|
+
result = db.remove_vrauser("im530", tables.get("user"))
|
26
|
+
info = db.get_vrauser(None, None, tables.get("user"))
|
27
|
+
assert len(info) == 0
|
28
|
+
assert result
|
29
|
+
|
30
|
+
|
31
|
+
def test_user_fetchall(user_db_fixture):
|
32
|
+
db = user_db_fixture
|
33
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
34
|
+
db.insert_vrauser("im532", "Ishan", tables.get("user"))
|
35
|
+
info = db.get_vrauser(None, None, tables.get("user"))
|
36
|
+
assert len(info) == 2
|
37
|
+
assert info[0][1] == "im530"
|
38
|
+
assert info[1][1] == "im532"
|
39
|
+
|
40
|
+
|
41
|
+
def test_user_fetch_one(user_db_fixture):
|
42
|
+
db = user_db_fixture
|
43
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
44
|
+
db.insert_vrauser("im532", "Ishan", tables.get("user"))
|
45
|
+
info = db.get_vrauser("im530", None, tables.get("user"))
|
46
|
+
assert len(info) == 1
|
47
|
+
assert info[0][1] == "im530"
|
48
|
+
|
49
|
+
|
50
|
+
def test_deployment_insertion(deploymentid_db_fixture):
|
51
|
+
db = deploymentid_db_fixture
|
52
|
+
result = db.insert_deployment_id("121212", tables.get("deploymentid"))
|
53
|
+
info = db.get_deployment_id(None, tables.get("deploymentid"))
|
54
|
+
assert len(info) == 1
|
55
|
+
assert result
|
56
|
+
|
57
|
+
|
58
|
+
def test_deployment_update(deploymentid_db_fixture):
|
59
|
+
db = deploymentid_db_fixture
|
60
|
+
db.insert_deployment_id("12345", tables.get("deploymentid"))
|
61
|
+
result = db.update_deployment_id("12345", "9876", tables.get("deploymentid"))
|
62
|
+
info = db.get_deployment_id(None, tables.get("deploymentid"))
|
63
|
+
assert len(info) == 1
|
64
|
+
assert result
|
65
|
+
assert info[0][1] == "9876"
|
66
|
+
|
67
|
+
|
68
|
+
def test_deployment_remove(deploymentid_db_fixture):
|
69
|
+
db = deploymentid_db_fixture
|
70
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
71
|
+
result = db.remove_deployment_id("121212", tables.get("deploymentid"))
|
72
|
+
info = db.get_deployment_id(None, tables.get("deploymentid"))
|
73
|
+
assert len(info) == 0
|
74
|
+
assert result
|
75
|
+
|
76
|
+
|
77
|
+
def test_deployment_fetchall(deploymentid_db_fixture):
|
78
|
+
db = deploymentid_db_fixture
|
79
|
+
db.insert_deployment_id("1212", tables.get("deploymentid"))
|
80
|
+
db.insert_deployment_id("1256", tables.get("deploymentid"))
|
81
|
+
info = db.get_deployment_id(None, tables.get("deploymentid"))
|
82
|
+
assert len(info) == 2
|
83
|
+
assert info[0][1] == "1212"
|
84
|
+
assert info[1][1] == "1256"
|
85
|
+
|
86
|
+
|
87
|
+
def test_deployment_fetch_one(deploymentid_db_fixture):
|
88
|
+
db = deploymentid_db_fixture
|
89
|
+
db.insert_deployment_id("1212", tables.get("deploymentid"))
|
90
|
+
db.insert_deployment_id("1256", tables.get("deploymentid"))
|
91
|
+
info = db.get_deployment_id("1256", tables.get("deploymentid"))
|
92
|
+
assert len(info) == 1
|
93
|
+
assert info[0][1] == "1256"
|
94
|
+
|
95
|
+
|
96
|
+
def test_proj_insertion(project_db_fixture):
|
97
|
+
db = project_db_fixture
|
98
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
99
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
100
|
+
result = db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
101
|
+
info = db.get_project(None, tables.get("proj"))
|
102
|
+
assert len(info) == 1
|
103
|
+
assert result
|
104
|
+
|
105
|
+
|
106
|
+
def test_proj_update(project_db_fixture):
|
107
|
+
db = project_db_fixture
|
108
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
109
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
110
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
111
|
+
result = db.update_project(
|
112
|
+
"123abc", "9876xyz", users[0][0], 220.0, tables.get("proj")
|
113
|
+
)
|
114
|
+
info = db.get_project(None, tables.get("proj"))
|
115
|
+
assert len(info) == 1
|
116
|
+
assert result
|
117
|
+
assert info[0][1] == "9876xyz"
|
118
|
+
assert info[0][3] == 220.0
|
119
|
+
|
120
|
+
|
121
|
+
def test_proj_remove(project_db_fixture):
|
122
|
+
db = project_db_fixture
|
123
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
124
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
125
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
126
|
+
info = db.get_project(None, tables.get("proj"))
|
127
|
+
result = db.remove_project("123abc", tables.get("proj"))
|
128
|
+
info = db.get_project(None, tables.get("proj"))
|
129
|
+
assert result
|
130
|
+
assert len(info) == 0
|
131
|
+
|
132
|
+
|
133
|
+
def test_proj_fetchall(project_db_fixture):
|
134
|
+
db = project_db_fixture
|
135
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
136
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
137
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
138
|
+
db.insert_project("123xyz", users[0][0], 200.0, tables.get("proj"))
|
139
|
+
info = db.get_project(None, tables.get("proj"))
|
140
|
+
assert len(info) == 2
|
141
|
+
assert info[0][1] == "123abc"
|
142
|
+
assert info[1][1] == "123xyz"
|
143
|
+
|
144
|
+
|
145
|
+
def test_proj_fetch_one(project_db_fixture):
|
146
|
+
db = project_db_fixture
|
147
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
148
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
149
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
150
|
+
db.insert_project("123xyz", users[0][0], 200.0, tables.get("proj"))
|
151
|
+
info = db.get_project("123xyz", tables.get("proj"))
|
152
|
+
assert len(info) == 1
|
153
|
+
assert info[0][1] == "123xyz"
|
154
|
+
|
155
|
+
|
156
|
+
def test_grant_insertion(grant_db_fixture):
|
157
|
+
db = grant_db_fixture
|
158
|
+
result = db.insert_vrauser("im530", "Ishan", "test_user")
|
159
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
160
|
+
result = db.insert_grant("123zyx", users[0][0], 200.0, tables.get("grant"))
|
161
|
+
info = db.get_grant(None, tables.get("grant"))
|
162
|
+
assert len(info) == 1
|
163
|
+
assert result
|
164
|
+
|
165
|
+
|
166
|
+
def test_grant_update(grant_db_fixture):
|
167
|
+
db = grant_db_fixture
|
168
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
169
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
170
|
+
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
171
|
+
result = db.update_grant(
|
172
|
+
"123abc", "9876xyz", users[0][0], 220.0, tables.get("grant")
|
173
|
+
)
|
174
|
+
info = db.get_grant(None, tables.get("grant"))
|
175
|
+
assert len(info) == 1
|
176
|
+
assert result
|
177
|
+
assert info[0][1] == "9876xyz"
|
178
|
+
assert info[0][3] == 220.0
|
179
|
+
|
180
|
+
|
181
|
+
def test_grant_remove(grant_db_fixture):
|
182
|
+
db = grant_db_fixture
|
183
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
184
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
185
|
+
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
186
|
+
result = db.remove_grant("123abc", tables.get("grant"))
|
187
|
+
info = db.get_grant(None, tables.get("grant"))
|
188
|
+
assert len(info) == 0
|
189
|
+
assert result
|
190
|
+
|
191
|
+
|
192
|
+
def test_grant_fetchall(grant_db_fixture):
|
193
|
+
db = grant_db_fixture
|
194
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
195
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
196
|
+
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
197
|
+
db.insert_grant("123xyz", users[0][0], 200.0, tables.get("grant"))
|
198
|
+
info = db.get_grant(None, tables.get("grant"))
|
199
|
+
assert len(info) == 2
|
200
|
+
assert info[0][1] == "123abc"
|
201
|
+
assert info[1][1] == "123xyz"
|
202
|
+
|
203
|
+
|
204
|
+
def test_grant_fetch_one(grant_db_fixture):
|
205
|
+
db = grant_db_fixture
|
206
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
207
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
208
|
+
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
209
|
+
db.insert_grant("123xyz", users[0][0], 200.0, tables.get("grant"))
|
210
|
+
info = db.get_grant("123xyz", tables.get("grant"))
|
211
|
+
assert len(info) == 1
|
212
|
+
assert info[0][1] == "123xyz"
|
213
|
+
|
214
|
+
|
215
|
+
def test_costing_insertion(costing_db_fixture):
|
216
|
+
db = costing_db_fixture
|
217
|
+
db.insert_vrauser("im530", "Ishan", "test_user")
|
218
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
219
|
+
|
220
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
221
|
+
deploy = db.get_deployment_id(None, tables.get("deploymentid"))
|
222
|
+
|
223
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
224
|
+
proj = db.get_project(None, tables.get("proj"))
|
225
|
+
|
226
|
+
result = db.insert_costing(
|
227
|
+
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
228
|
+
)
|
229
|
+
info = db.get_costing(None, None, None, None, tables.get("costing"))
|
230
|
+
assert len(info) == 1
|
231
|
+
assert result
|
232
|
+
|
233
|
+
|
234
|
+
def test_costing_update(costing_db_fixture):
|
235
|
+
db = costing_db_fixture
|
236
|
+
db.insert_vrauser("im530", "Ishan", "test_user")
|
237
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
238
|
+
|
239
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
240
|
+
deploy = db.get_deployment_id(None, tables.get("deploymentid"))
|
241
|
+
|
242
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
243
|
+
proj = db.get_project(None, tables.get("proj"))
|
244
|
+
|
245
|
+
db.insert_grant("998zxc", users[0][0], 100.0, tables.get("grant"))
|
246
|
+
grant = db.get_grant(None, tables.get("grant"))
|
247
|
+
|
248
|
+
db.insert_costing(
|
249
|
+
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
250
|
+
)
|
251
|
+
|
252
|
+
info = db.get_costing(None, None, None, None, tables.get("costing"))
|
253
|
+
result = db.update_costing(
|
254
|
+
deploy[0][0],
|
255
|
+
"Resource Expansion",
|
256
|
+
None,
|
257
|
+
proj[0][0],
|
258
|
+
grant[0][0],
|
259
|
+
None,
|
260
|
+
tables.get("costing"),
|
261
|
+
)
|
262
|
+
|
263
|
+
info = db.get_costing(None, None, None, None, tables.get("costing"))
|
264
|
+
assert len(info) == 1
|
265
|
+
assert result
|
266
|
+
assert info[0][4] == 1
|
267
|
+
|
268
|
+
|
269
|
+
def test_costing_remove(costing_db_fixture):
|
270
|
+
db = costing_db_fixture
|
271
|
+
db.insert_vrauser("im530", "Ishan", "test_user")
|
272
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
273
|
+
|
274
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
275
|
+
deploy = db.get_deployment_id(None, tables.get("deploymentid"))
|
276
|
+
|
277
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
278
|
+
proj = db.get_project(None, tables.get("proj"))
|
279
|
+
|
280
|
+
db.insert_costing(
|
281
|
+
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
282
|
+
)
|
283
|
+
|
284
|
+
result = db.remove_costing(
|
285
|
+
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
286
|
+
)
|
287
|
+
|
288
|
+
info = db.get_costing(None, None, None, None, tables.get("costing"))
|
289
|
+
assert len(info) == 0
|
290
|
+
assert result
|
291
|
+
|
292
|
+
|
293
|
+
def test_costing_fetchall(costing_db_fixture):
|
294
|
+
db = costing_db_fixture
|
295
|
+
db.insert_vrauser("im530", "Ishan", "test_user")
|
296
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
297
|
+
|
298
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
299
|
+
deploy = db.get_deployment_id(None, tables.get("deploymentid"))
|
300
|
+
|
301
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
302
|
+
proj = db.get_project(None, tables.get("proj"))
|
303
|
+
|
304
|
+
db.insert_costing(
|
305
|
+
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
306
|
+
)
|
307
|
+
db.insert_costing(
|
308
|
+
deploy[0][0], "Duration Expansion", proj[0][0], None, tables.get("costing")
|
309
|
+
)
|
310
|
+
|
311
|
+
info = db.get_costing(None, None, None, None, tables.get("costing"))
|
312
|
+
assert len(info) == 2
|
313
|
+
assert info[0][2] == "Resource Expansion"
|
314
|
+
assert info[1][2] == "Duration Expansion"
|
315
|
+
|
316
|
+
|
317
|
+
def test_costing_fetch_one(costing_db_fixture):
|
318
|
+
db = costing_db_fixture
|
319
|
+
db.insert_vrauser("im530", "Ishan", "test_user")
|
320
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
321
|
+
|
322
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
323
|
+
deploy = db.get_deployment_id(None, tables.get("deploymentid"))
|
324
|
+
|
325
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
326
|
+
proj = db.get_project(None, tables.get("proj"))
|
327
|
+
|
328
|
+
db.insert_costing(
|
329
|
+
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
330
|
+
)
|
331
|
+
db.insert_costing(
|
332
|
+
deploy[0][0], "Duration Expansion", proj[0][0], None, tables.get("costing")
|
333
|
+
)
|
334
|
+
|
335
|
+
info = db.get_costing(
|
336
|
+
deploy[0][0], "Duration Expansion", proj[0][0], None, tables.get("costing")
|
337
|
+
)
|
338
|
+
assert len(info) == 1
|
339
|
+
assert info[0][2] == "Duration Expansion"
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import psycopg2
|
2
|
+
import time
|
3
|
+
|
4
|
+
from ucampostgresvro import utils
|
5
|
+
from ucampostgresvro.DBA import DB
|
6
|
+
from ucampostgresvro.exceptions import DbException
|
7
|
+
from ucampostgresvro.tests.dbconnect import db_params
|
8
|
+
|
9
|
+
db_params = db_params
|
10
|
+
|
11
|
+
tables = {
|
12
|
+
"user": "test_user",
|
13
|
+
"deploymentid": "test_deployment",
|
14
|
+
"grant": "test_grants",
|
15
|
+
"proj": "test_projects",
|
16
|
+
"costing": "test_costing",
|
17
|
+
}
|
18
|
+
|
19
|
+
|
20
|
+
def check_db_connection(data_params):
|
21
|
+
retries = 3
|
22
|
+
state = False
|
23
|
+
while retries > 0:
|
24
|
+
try:
|
25
|
+
conn = psycopg2.connect(**db_params)
|
26
|
+
state = True
|
27
|
+
break
|
28
|
+
except psycopg2.OperationalError:
|
29
|
+
time.sleep(2) # Wait for 2 seconds before retrying
|
30
|
+
retries -= 1
|
31
|
+
if state:
|
32
|
+
conn.close()
|
33
|
+
return state
|
34
|
+
|
35
|
+
|
36
|
+
def setup_user_table_func(data_params):
|
37
|
+
utils.create_user_table(tables.get("user"), data_params)
|
38
|
+
db = DB(db_params)
|
39
|
+
return db
|
40
|
+
|
41
|
+
|
42
|
+
def teardown_user_table_func(data_params):
|
43
|
+
return utils.drop_table(tables.get("user"), data_params)
|
44
|
+
|
45
|
+
|
46
|
+
def setup_deployment_table_func(data_params):
|
47
|
+
utils.create_deployment_table(tables.get("deploymentid"), data_params)
|
48
|
+
db = DB(db_params)
|
49
|
+
return db
|
50
|
+
|
51
|
+
|
52
|
+
def teardown_deployment_table_func(data_params):
|
53
|
+
return utils.drop_table(tables.get("deploymentid"), data_params)
|
54
|
+
|
55
|
+
|
56
|
+
def setup_grant_table_func(data_params):
|
57
|
+
db = DB(db_params)
|
58
|
+
if utils.create_user_table(tables.get("user"), data_params):
|
59
|
+
if utils.create_grant_table(
|
60
|
+
tables.get("grant"), tables.get("user"), data_params
|
61
|
+
):
|
62
|
+
return db
|
63
|
+
raise DbException("Creation of the grant DB failed.")
|
64
|
+
|
65
|
+
|
66
|
+
def teardown_grant_table_func(data_params):
|
67
|
+
result = []
|
68
|
+
result.append(utils.drop_table(tables.get("grant"), data_params))
|
69
|
+
result.append(utils.drop_table(tables.get("user"), data_params))
|
70
|
+
return False not in result
|
71
|
+
|
72
|
+
|
73
|
+
def setup_project_table_func(data_params):
|
74
|
+
db = DB(db_params)
|
75
|
+
if utils.create_user_table(tables.get("user"), data_params):
|
76
|
+
utils.create_project_table(tables.get("proj"), tables.get("user"), data_params)
|
77
|
+
return db
|
78
|
+
raise DbException("Creation of the purchase order DB failed.")
|
79
|
+
|
80
|
+
|
81
|
+
def teardown_project_table_func(data_params):
|
82
|
+
result = []
|
83
|
+
result.append(utils.drop_table(tables.get("proj"), data_params))
|
84
|
+
result.append(utils.drop_table(tables.get("user"), data_params))
|
85
|
+
return False not in result
|
86
|
+
|
87
|
+
|
88
|
+
def setup_costing_table_func(data_params):
|
89
|
+
db = DB(db_params)
|
90
|
+
if utils.create_user_table(tables.get("user"), data_params):
|
91
|
+
if utils.create_deployment_table(tables.get("deploymentid"), data_params):
|
92
|
+
if utils.create_project_table(
|
93
|
+
tables.get("proj"), tables.get("user"), data_params
|
94
|
+
):
|
95
|
+
if utils.create_grant_table(
|
96
|
+
tables.get("grant"), tables.get("user"), data_params
|
97
|
+
):
|
98
|
+
if utils.create_costing_table(
|
99
|
+
tables.get("costing"),
|
100
|
+
tables.get("deploymentid"),
|
101
|
+
tables.get("proj"),
|
102
|
+
tables.get("grant"),
|
103
|
+
data_params,
|
104
|
+
):
|
105
|
+
return db
|
106
|
+
raise DbException("Creation of the costing DB failed.")
|
107
|
+
|
108
|
+
|
109
|
+
def teardown_costing_table_func(data_params):
|
110
|
+
result = []
|
111
|
+
result.append(utils.drop_table(tables.get("costing"), data_params))
|
112
|
+
result.append(utils.drop_table(tables.get("proj"), data_params))
|
113
|
+
result.append(utils.drop_table(tables.get("grant"), data_params))
|
114
|
+
result.append(utils.drop_table(tables.get("user"), data_params))
|
115
|
+
result.append(utils.drop_table(tables.get("deploymentid"), data_params))
|
116
|
+
return False not in result
|