ucampostgresvro 0.1.1__py3-none-any.whl → 0.2.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 +348 -139
- ucampostgresvro/__init__.py +1 -1
- ucampostgresvro/__main__.py +49 -67
- ucampostgresvro/tests/dbconnect.py +5 -5
- ucampostgresvro/tests/test_DB.py +129 -21
- ucampostgresvro/utils.py +44 -0
- {ucampostgresvro-0.1.1.dist-info → ucampostgresvro-0.2.0.dist-info}/METADATA +99 -39
- ucampostgresvro-0.2.0.dist-info/RECORD +16 -0
- ucampostgresvro-0.1.1.dist-info/RECORD +0 -16
- {ucampostgresvro-0.1.1.dist-info → ucampostgresvro-0.2.0.dist-info}/LICENSE +0 -0
- {ucampostgresvro-0.1.1.dist-info → ucampostgresvro-0.2.0.dist-info}/WHEEL +0 -0
ucampostgresvro/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION = "0.
|
1
|
+
VERSION = "0.2.0"
|
ucampostgresvro/__main__.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
import logging
|
2
2
|
import sys
|
3
|
-
from typing import Dict
|
4
3
|
|
4
|
+
# from datetime import datetime
|
5
5
|
from ucampostgresvro import VERSION, utils
|
6
6
|
from ucampostgresvro.DBA import DB
|
7
7
|
from ucampostgresvro.exceptions import DbException
|
8
8
|
from ucampostgresvro.secrets import password
|
9
|
-
from ucampostgresvro.tools import DEFAULT_TABLES
|
10
9
|
|
11
10
|
|
12
11
|
def setloggerdetail():
|
@@ -21,52 +20,6 @@ def setloggerdetail():
|
|
21
20
|
return LOG
|
22
21
|
|
23
22
|
|
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
23
|
def main():
|
71
24
|
LOG = setloggerdetail()
|
72
25
|
LOG.info(f"VERSION : {VERSION}")
|
@@ -81,50 +34,79 @@ def main():
|
|
81
34
|
}
|
82
35
|
db = DB(db_params)
|
83
36
|
|
84
|
-
if not pre_setupconfig(db_params):
|
37
|
+
if not utils.pre_setupconfig(db_params):
|
85
38
|
raise DbException("ERROR: Tables are not created successfully")
|
86
39
|
|
87
40
|
# db.insert_vrauser("ll220", "len")
|
88
41
|
# print(db.get_vrauser("ll220"))
|
42
|
+
# print(db.get_vrauser_primary_key("ll220"))
|
89
43
|
# db.update_vrauser("ll220", "bda20", 'Ben Argyle')
|
90
44
|
# print(db.get_vrauser())
|
91
45
|
# db.remove_vrauser('bda20')
|
46
|
+
# print(db.get_vrauser_by_id(2))
|
92
47
|
# print(db.get_vrauser())
|
93
48
|
|
94
49
|
# db.insert_deployment_id("1231ee112ad11212")
|
50
|
+
# print(db.get_deployment_id("1231ee112ad11212"))
|
51
|
+
# print(db.get_deployment_id_primary_key("1231ee112ad11212"))
|
95
52
|
# db.update_deployment_id("1231ee112ad11212", "1231a")
|
96
53
|
# print(db.get_deployment_id("1231a"))
|
97
54
|
# db.remove_deployment_id('1231a')
|
55
|
+
# print(db.get_deployment_id())
|
98
56
|
# db.insert_deployment_id("123")
|
99
57
|
# print(db.get_deployment_id())
|
58
|
+
# print(db.get_deployment_id_by_id(2))
|
59
|
+
# print(db.get_deployment_id_primary_key("123"))
|
100
60
|
|
101
|
-
# print(db.get_project())
|
102
|
-
# db.insert_project("0001",1,100.0)
|
103
61
|
# db.insert_project("0101",2,100.0)
|
104
|
-
# db.
|
105
|
-
# db.
|
106
|
-
# db.
|
107
|
-
# db.
|
108
|
-
#
|
62
|
+
# db.insert_project("0001",2,100.0)
|
63
|
+
# print(db.get_project())
|
64
|
+
# db.update_project(2, "0002", 2, 200)
|
65
|
+
# print(db.get_project())
|
66
|
+
# db.remove_project(1)
|
67
|
+
# print(db.get_project())
|
68
|
+
# db.insert_project("2001",2,100.0)
|
69
|
+
# db.insert_project("2003",2,200.0)
|
70
|
+
# db.insert_project("2001",2,100.0)
|
71
|
+
# print(db.get_project("2001"))
|
72
|
+
# print(db.get_project_by_id(6))
|
73
|
+
# print(db.get_project_primary_key("2001"))
|
74
|
+
# print(db.get_project_primary_key("2001", datetime(2025, 1, 22, 15, 55, 25, 95698)))
|
75
|
+
# print(db.get_project())
|
109
76
|
|
110
77
|
# print(db.get_grant())
|
111
|
-
# db.insert_grant("0001",
|
112
|
-
# db.
|
78
|
+
# db.insert_grant("0001",2,100.0)
|
79
|
+
# print(db.get_grant())
|
80
|
+
# db.update_grant(2, "0002", 2, 200)
|
113
81
|
# print(db.get_grant())
|
114
|
-
# db.
|
82
|
+
# db.insert_grant("2001",2,100.0)
|
83
|
+
# db.insert_grant("2003",2,200.0)
|
84
|
+
# db.insert_grant("2001",2,100.0)
|
115
85
|
# print(db.get_grant())
|
116
|
-
# db.
|
117
|
-
# db.
|
118
|
-
# print(db.
|
86
|
+
# print(db.get_grant())
|
87
|
+
# print(db.get_grant("2001"))
|
88
|
+
# print(db.get_grant_primary_key("2001"))
|
89
|
+
# print(db.get_grant_by_id(5))
|
90
|
+
# print(db.get_grant_primary_key("2001",
|
91
|
+
# datetime(2025, 1, 22, 18, 17, 25, 95698)
|
92
|
+
# )
|
93
|
+
# )
|
94
|
+
# print(db.get_project())
|
95
|
+
# db.remove_grant(1)
|
119
96
|
|
97
|
+
# db.insert_costing(2, "Initial Resource", project_id=2, grant_id=None)
|
98
|
+
# db.insert_costing(2, "Initial Resource", project_id=None, grant_id=2)
|
120
99
|
# 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
100
|
# print(db.get_costing())
|
101
|
+
# print(db.get_costing(2, "Initial Resource", 2)) # project
|
102
|
+
# print(db.get_costing(2, "Initial Resource", None, 2)) # Grant
|
103
|
+
# print(db.get_costing(3, "Duration Expansion", None, 2)) # Grant
|
104
|
+
# # print(db.get_costing_primary_key(2, "Initial Resource", 2)) # project
|
105
|
+
# print(db.get_costing_primary_key(2, "Initial Resource", None, 2)) #Grant
|
106
|
+
# db.update_costing(3, 2, "Duration Expansion", new_grant_id=None, new_project_id=2)
|
126
107
|
# print(db.get_costing())
|
127
|
-
# db.
|
108
|
+
# print(db.get_costing_by_id(3))
|
109
|
+
# db.remove_costing(4)
|
128
110
|
# print(db.get_costing())
|
129
111
|
|
130
112
|
db.closedb()
|
@@ -2,9 +2,9 @@ import os
|
|
2
2
|
|
3
3
|
|
4
4
|
db_params = {
|
5
|
-
"dbname": os.environ[
|
6
|
-
"user": os.environ[
|
7
|
-
"password": os.environ[
|
8
|
-
"host": os.environ[
|
9
|
-
"port": os.environ[
|
5
|
+
"dbname": os.environ["POSTGRES_DB"],
|
6
|
+
"user": os.environ["POSTGRES_USER"],
|
7
|
+
"password": os.environ["POSTGRES_PASSWORD"],
|
8
|
+
"host": os.environ["POSTGRES_HOST"],
|
9
|
+
"port": os.environ["POSTGRES_PORT"],
|
10
10
|
}
|
ucampostgresvro/tests/test_DB.py
CHANGED
@@ -38,6 +38,14 @@ def test_user_fetchall(user_db_fixture):
|
|
38
38
|
assert info[1][1] == "im532"
|
39
39
|
|
40
40
|
|
41
|
+
def test_user_fetch_by_id(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_by_id(2, tables.get("user"))
|
46
|
+
assert info[1] == "im532"
|
47
|
+
|
48
|
+
|
41
49
|
def test_user_fetch_one(user_db_fixture):
|
42
50
|
db = user_db_fixture
|
43
51
|
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
@@ -47,6 +55,14 @@ def test_user_fetch_one(user_db_fixture):
|
|
47
55
|
assert info[0][1] == "im530"
|
48
56
|
|
49
57
|
|
58
|
+
def test_user_fetch_primary_key_crsid(user_db_fixture):
|
59
|
+
db = user_db_fixture
|
60
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
61
|
+
db.insert_vrauser("im532", "Ishan", tables.get("user"))
|
62
|
+
info = db.get_vrauser_primary_key("im532", tables.get("user"))
|
63
|
+
assert info == 2
|
64
|
+
|
65
|
+
|
50
66
|
def test_deployment_insertion(deploymentid_db_fixture):
|
51
67
|
db = deploymentid_db_fixture
|
52
68
|
result = db.insert_deployment_id("121212", tables.get("deploymentid"))
|
@@ -84,6 +100,14 @@ def test_deployment_fetchall(deploymentid_db_fixture):
|
|
84
100
|
assert info[1][1] == "1256"
|
85
101
|
|
86
102
|
|
103
|
+
def test_deployment_fetch_by_id(deploymentid_db_fixture):
|
104
|
+
db = deploymentid_db_fixture
|
105
|
+
db.insert_deployment_id("1212", tables.get("deploymentid"))
|
106
|
+
db.insert_deployment_id("1256", tables.get("deploymentid"))
|
107
|
+
info = db.get_deployment_id_by_id(2, tables.get("deploymentid"))
|
108
|
+
assert info[1] == "1256"
|
109
|
+
|
110
|
+
|
87
111
|
def test_deployment_fetch_one(deploymentid_db_fixture):
|
88
112
|
db = deploymentid_db_fixture
|
89
113
|
db.insert_deployment_id("1212", tables.get("deploymentid"))
|
@@ -93,6 +117,14 @@ def test_deployment_fetch_one(deploymentid_db_fixture):
|
|
93
117
|
assert info[0][1] == "1256"
|
94
118
|
|
95
119
|
|
120
|
+
def test_deployment_fetch_primary_key_deployment(deploymentid_db_fixture):
|
121
|
+
db = deploymentid_db_fixture
|
122
|
+
db.insert_deployment_id("1212", tables.get("deploymentid"))
|
123
|
+
db.insert_deployment_id("1256", tables.get("deploymentid"))
|
124
|
+
info = db.get_deployment_id_primary_key("1256", tables.get("deploymentid"))
|
125
|
+
assert info == 2
|
126
|
+
|
127
|
+
|
96
128
|
def test_proj_insertion(project_db_fixture):
|
97
129
|
db = project_db_fixture
|
98
130
|
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
@@ -109,13 +141,13 @@ def test_proj_update(project_db_fixture):
|
|
109
141
|
users = db.get_vrauser(None, None, tables.get("user"))
|
110
142
|
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
111
143
|
result = db.update_project(
|
112
|
-
|
144
|
+
1, "9876xyz", users[0][0], 220.0, tables.get("proj")
|
113
145
|
)
|
114
146
|
info = db.get_project(None, tables.get("proj"))
|
115
147
|
assert len(info) == 1
|
116
148
|
assert result
|
117
|
-
assert info[0][
|
118
|
-
assert info[0][
|
149
|
+
assert info[0][2] == "9876xyz"
|
150
|
+
assert info[0][4] == 220.0
|
119
151
|
|
120
152
|
|
121
153
|
def test_proj_remove(project_db_fixture):
|
@@ -123,8 +155,8 @@ def test_proj_remove(project_db_fixture):
|
|
123
155
|
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
124
156
|
users = db.get_vrauser(None, None, tables.get("user"))
|
125
157
|
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
126
|
-
|
127
|
-
result = db.remove_project(
|
158
|
+
prj = db.get_project(None, tables.get("proj"))
|
159
|
+
result = db.remove_project(prj[0][0], tables.get("proj"))
|
128
160
|
info = db.get_project(None, tables.get("proj"))
|
129
161
|
assert result
|
130
162
|
assert len(info) == 0
|
@@ -138,8 +170,8 @@ def test_proj_fetchall(project_db_fixture):
|
|
138
170
|
db.insert_project("123xyz", users[0][0], 200.0, tables.get("proj"))
|
139
171
|
info = db.get_project(None, tables.get("proj"))
|
140
172
|
assert len(info) == 2
|
141
|
-
assert info[0][
|
142
|
-
assert info[1][
|
173
|
+
assert info[0][2] == "123abc"
|
174
|
+
assert info[1][2] == "123xyz"
|
143
175
|
|
144
176
|
|
145
177
|
def test_proj_fetch_one(project_db_fixture):
|
@@ -150,7 +182,27 @@ def test_proj_fetch_one(project_db_fixture):
|
|
150
182
|
db.insert_project("123xyz", users[0][0], 200.0, tables.get("proj"))
|
151
183
|
info = db.get_project("123xyz", tables.get("proj"))
|
152
184
|
assert len(info) == 1
|
153
|
-
assert info[0][
|
185
|
+
assert info[0][2] == "123xyz"
|
186
|
+
|
187
|
+
|
188
|
+
def test_proj_fetch_by_id(project_db_fixture):
|
189
|
+
db = project_db_fixture
|
190
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
191
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
192
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
193
|
+
db.insert_project("123xyz", users[0][0], 200.0, tables.get("proj"))
|
194
|
+
info = db.get_project_by_id(2, tables.get("proj"))
|
195
|
+
assert info[2] == "123xyz"
|
196
|
+
|
197
|
+
|
198
|
+
def test_proj_fetch_primary_key(project_db_fixture):
|
199
|
+
db = project_db_fixture
|
200
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
201
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
202
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
203
|
+
db.insert_project("123xyz", users[0][0], 200.0, tables.get("proj"))
|
204
|
+
info = db.get_project_primary_key("123xyz", None, tables.get("proj"))
|
205
|
+
assert info == 2
|
154
206
|
|
155
207
|
|
156
208
|
def test_grant_insertion(grant_db_fixture):
|
@@ -169,13 +221,13 @@ def test_grant_update(grant_db_fixture):
|
|
169
221
|
users = db.get_vrauser(None, None, tables.get("user"))
|
170
222
|
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
171
223
|
result = db.update_grant(
|
172
|
-
|
224
|
+
1, "9876xyz", users[0][0], 220.0, tables.get("grant")
|
173
225
|
)
|
174
226
|
info = db.get_grant(None, tables.get("grant"))
|
175
227
|
assert len(info) == 1
|
176
228
|
assert result
|
177
|
-
assert info[0][
|
178
|
-
assert info[0][
|
229
|
+
assert info[0][2] == "9876xyz"
|
230
|
+
assert info[0][4] == 220.0
|
179
231
|
|
180
232
|
|
181
233
|
def test_grant_remove(grant_db_fixture):
|
@@ -183,7 +235,7 @@ def test_grant_remove(grant_db_fixture):
|
|
183
235
|
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
184
236
|
users = db.get_vrauser(None, None, tables.get("user"))
|
185
237
|
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
186
|
-
result = db.remove_grant(
|
238
|
+
result = db.remove_grant(1, tables.get("grant"))
|
187
239
|
info = db.get_grant(None, tables.get("grant"))
|
188
240
|
assert len(info) == 0
|
189
241
|
assert result
|
@@ -197,8 +249,8 @@ def test_grant_fetchall(grant_db_fixture):
|
|
197
249
|
db.insert_grant("123xyz", users[0][0], 200.0, tables.get("grant"))
|
198
250
|
info = db.get_grant(None, tables.get("grant"))
|
199
251
|
assert len(info) == 2
|
200
|
-
assert info[0][
|
201
|
-
assert info[1][
|
252
|
+
assert info[0][2] == "123abc"
|
253
|
+
assert info[1][2] == "123xyz"
|
202
254
|
|
203
255
|
|
204
256
|
def test_grant_fetch_one(grant_db_fixture):
|
@@ -209,7 +261,27 @@ def test_grant_fetch_one(grant_db_fixture):
|
|
209
261
|
db.insert_grant("123xyz", users[0][0], 200.0, tables.get("grant"))
|
210
262
|
info = db.get_grant("123xyz", tables.get("grant"))
|
211
263
|
assert len(info) == 1
|
212
|
-
assert info[0][
|
264
|
+
assert info[0][2] == "123xyz"
|
265
|
+
|
266
|
+
|
267
|
+
def test_grant_fetch_by_id(grant_db_fixture):
|
268
|
+
db = grant_db_fixture
|
269
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
270
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
271
|
+
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
272
|
+
db.insert_grant("123xyz", users[0][0], 200.0, tables.get("grant"))
|
273
|
+
info = db.get_grant_by_id(2, tables.get("grant"))
|
274
|
+
assert info[2] == "123xyz"
|
275
|
+
|
276
|
+
|
277
|
+
def test_grant_primary_key(grant_db_fixture):
|
278
|
+
db = grant_db_fixture
|
279
|
+
db.insert_vrauser("im530", "Ishan", tables.get("user"))
|
280
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
281
|
+
db.insert_grant("123abc", users[0][0], 100.0, tables.get("grant"))
|
282
|
+
db.insert_grant("123xyz", users[0][0], 200.0, tables.get("grant"))
|
283
|
+
info = db.get_grant_primary_key("123xyz", None, tables.get("grant"))
|
284
|
+
assert info == 2
|
213
285
|
|
214
286
|
|
215
287
|
def test_costing_insertion(costing_db_fixture):
|
@@ -249,12 +321,10 @@ def test_costing_update(costing_db_fixture):
|
|
249
321
|
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
250
322
|
)
|
251
323
|
|
252
|
-
info = db.get_costing(None, None, None, None, tables.get("costing"))
|
253
324
|
result = db.update_costing(
|
325
|
+
1,
|
254
326
|
deploy[0][0],
|
255
327
|
"Resource Expansion",
|
256
|
-
None,
|
257
|
-
proj[0][0],
|
258
328
|
grant[0][0],
|
259
329
|
None,
|
260
330
|
tables.get("costing"),
|
@@ -281,9 +351,7 @@ def test_costing_remove(costing_db_fixture):
|
|
281
351
|
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
282
352
|
)
|
283
353
|
|
284
|
-
result = db.remove_costing(
|
285
|
-
deploy[0][0], "Resource Expansion", proj[0][0], None, tables.get("costing")
|
286
|
-
)
|
354
|
+
result = db.remove_costing(1, tables.get("costing"))
|
287
355
|
|
288
356
|
info = db.get_costing(None, None, None, None, tables.get("costing"))
|
289
357
|
assert len(info) == 0
|
@@ -337,3 +405,43 @@ def test_costing_fetch_one(costing_db_fixture):
|
|
337
405
|
)
|
338
406
|
assert len(info) == 1
|
339
407
|
assert info[0][2] == "Duration Expansion"
|
408
|
+
|
409
|
+
|
410
|
+
def test_costing_fetch_by_id(costing_db_fixture):
|
411
|
+
db = costing_db_fixture
|
412
|
+
db.insert_vrauser("im530", "Ishan", "test_user")
|
413
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
414
|
+
|
415
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
416
|
+
deploy = db.get_deployment_id(None, tables.get("deploymentid"))
|
417
|
+
|
418
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
419
|
+
proj = db.get_project(None, tables.get("proj"))
|
420
|
+
|
421
|
+
db.insert_costing(
|
422
|
+
deploy[0][0], "Duration Expansion", proj[0][0], None, tables.get("costing")
|
423
|
+
)
|
424
|
+
|
425
|
+
info = db.get_costing_by_id(1, tables.get("costing"))
|
426
|
+
assert info[1] == deploy[0][0]
|
427
|
+
assert info[2] == "Duration Expansion"
|
428
|
+
assert info[3] == proj[0][0]
|
429
|
+
|
430
|
+
|
431
|
+
def test_costing_fetch_primary_key(costing_db_fixture):
|
432
|
+
db = costing_db_fixture
|
433
|
+
db.insert_vrauser("im530", "Ishan", "test_user")
|
434
|
+
users = db.get_vrauser(None, None, tables.get("user"))
|
435
|
+
|
436
|
+
db.insert_deployment_id("121212", tables.get("deploymentid"))
|
437
|
+
deploy = db.get_deployment_id(None, tables.get("deploymentid"))
|
438
|
+
|
439
|
+
db.insert_project("123abc", users[0][0], 100.0, tables.get("proj"))
|
440
|
+
proj = db.get_project(None, tables.get("proj"))
|
441
|
+
|
442
|
+
db.insert_costing(
|
443
|
+
deploy[0][0], "Duration Expansion", proj[0][0], None, tables.get("costing")
|
444
|
+
)
|
445
|
+
|
446
|
+
info = db.get_costing_primary_key(deploy[0][0], "Duration Expansion", proj[0][0], None, tables.get("costing"))
|
447
|
+
assert info == 1
|
ucampostgresvro/utils.py
CHANGED
@@ -3,10 +3,52 @@ from typing import Callable, Dict
|
|
3
3
|
|
4
4
|
from ucampostgresvro.DBA import DB
|
5
5
|
from ucampostgresvro.exceptions import DbException
|
6
|
+
from ucampostgresvro.tools import DEFAULT_TABLES
|
6
7
|
|
7
8
|
LOG = logging.getLogger(__name__)
|
8
9
|
|
9
10
|
|
11
|
+
def pre_setupconfig(db_params: Dict[str, str]) -> bool:
|
12
|
+
"""Create the Database
|
13
|
+
|
14
|
+
Args:
|
15
|
+
db_params (Dict[str, str]): provide parameters for DB connection.
|
16
|
+
|
17
|
+
Returns:
|
18
|
+
bool: True if creation of database is suceess else False
|
19
|
+
"""
|
20
|
+
result = []
|
21
|
+
if not check_table_exists(DEFAULT_TABLES.get("user"), db_params):
|
22
|
+
result.append(create_user_table(DEFAULT_TABLES.get("user"), db_params))
|
23
|
+
if not check_table_exists(DEFAULT_TABLES.get("deploymentid"), db_params):
|
24
|
+
result.append(
|
25
|
+
create_deployment_table(DEFAULT_TABLES.get("deploymentid"), db_params)
|
26
|
+
)
|
27
|
+
if not check_table_exists(DEFAULT_TABLES.get("proj"), db_params):
|
28
|
+
result.append(
|
29
|
+
create_project_table(
|
30
|
+
DEFAULT_TABLES.get("proj"), DEFAULT_TABLES.get("user"), db_params
|
31
|
+
)
|
32
|
+
)
|
33
|
+
if not check_table_exists(DEFAULT_TABLES.get("grant"), db_params):
|
34
|
+
result.append(
|
35
|
+
create_grant_table(
|
36
|
+
DEFAULT_TABLES.get("grant"), DEFAULT_TABLES.get("user"), db_params
|
37
|
+
)
|
38
|
+
)
|
39
|
+
if not check_table_exists(DEFAULT_TABLES.get("costing"), db_params):
|
40
|
+
result.append(
|
41
|
+
create_costing_table(
|
42
|
+
DEFAULT_TABLES.get("costing"),
|
43
|
+
DEFAULT_TABLES.get("deploymentid"),
|
44
|
+
DEFAULT_TABLES.get("proj"),
|
45
|
+
DEFAULT_TABLES.get("grant"),
|
46
|
+
db_params,
|
47
|
+
)
|
48
|
+
)
|
49
|
+
return False not in result
|
50
|
+
|
51
|
+
|
10
52
|
def create_table(tablename: str, db_params: Dict[str, str], design: str) -> bool:
|
11
53
|
"""Creation of table with provided design
|
12
54
|
|
@@ -109,6 +151,7 @@ def create_project_table(
|
|
109
151
|
"""
|
110
152
|
design = f"CREATE TABLE {proj_tablename} (\
|
111
153
|
id SERIAL PRIMARY KEY, \
|
154
|
+
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, \
|
112
155
|
project_number VARCHAR(255), \
|
113
156
|
paid_by INTEGER REFERENCES {user_tablename}(id), \
|
114
157
|
amount FLOAT NOT NULL \
|
@@ -131,6 +174,7 @@ def create_grant_table(
|
|
131
174
|
"""
|
132
175
|
design = f"CREATE TABLE {grant_tablename} (\
|
133
176
|
id SERIAL PRIMARY KEY,\
|
177
|
+
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, \
|
134
178
|
grant_number VARCHAR(255),\
|
135
179
|
paid_by INTEGER REFERENCES {user_tablename}(id),\
|
136
180
|
amount FLOAT NOT NULL\
|