Skip to content

Commit f9dffb1

Browse files
committed
changed behaviour of add_test_package_product to work with new fucntionality of add_product
1 parent 3b34e82 commit f9dffb1

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

web/server/codechecker_server/server.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -915,35 +915,41 @@ def add_product(self, orm_product, init_db=False):
915915

916916
self.__products[prod.endpoint] = prod
917917

918-
def get_if_database_in_use(self, product_connection_string):
918+
def get_if_database_in_use(self, product):
919919
"""
920920
Returns the product endpoint if the given database is in use
921921
"""
922922
# get the database name from the product connection string
923-
to_add = product_connection_string.database
923+
is_sqlite = False
924+
if product.database.endswith('.sqlite'):
925+
to_add = product.database.replace('////', '/')
926+
is_sqlite = True
927+
else:
928+
to_add = f"@{product.host}:{product.port}/{product.database}"
929+
924930
LOG.info("The database string that will be added: %s", to_add)
925931

926-
# if str(product_connection_string.engine) == "sqlite":
927-
# to_add = str(to_add).rsplit('/', maxsplit=1)[-1]
928-
# if to_add.endswith('.sqlite'):
929-
# to_add = to_add[:-7]
930932
LOG.info("to add: %s", to_add)
931933

932934
# get the current state of connected databases from products
933935
dynamic_list = [
934-
a.connection
936+
a.connection.replace('////', '/')
935937
for a in self.cfg_sess_private.query(ORMProduct).all()
936938
]
937939

938-
# log dynamic list
939-
# LOG.info("dynamic list: %s", dynamic_list)
940-
# dynamic_list = [
941-
# d[:-7] if d.endswith('.sqlite') else d
942-
# for d in dynamic_list
943-
# ]
944-
LOG.info("dynamic list: %s", dynamic_list)
940+
dynamic_list = [
941+
d[16:] if d.endswith('.sqlite') else d
942+
for d in dynamic_list
943+
]
945944

946-
return to_add in dynamic_list # True if found, False otherwise
945+
# True if found, False otherwise
946+
LOG.info("dynamic list: %s", dynamic_list)
947+
for d in dynamic_list:
948+
if d == to_add and is_sqlite:
949+
return True
950+
elif to_add in d and not is_sqlite:
951+
return True
952+
return False
947953

948954
@property
949955
def num_products(self):

web/tests/functional/products/test_config_db_share.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import unittest
2222

2323
from codechecker_api_shared.ttypes import Permission
24-
# from codechecker_api_shared.ttypes import RequestFailed
24+
from codechecker_api_shared.ttypes import RequestFailed
2525

2626
from codechecker_api.ProductManagement_v6.ttypes import ProductConfiguration
2727
from codechecker_api.ProductManagement_v6.ttypes import DatabaseConnection
@@ -160,7 +160,7 @@ def create_test_product(product_name, product_endpoint):
160160
username_b64='',
161161
password_b64='',
162162
database=os.path.join(self.test_workspace_secondary,
163-
'data.sqlite')))
163+
'data_test.sqlite')))
164164

165165
product_cfg = create_test_product('producttest_second',
166166
'producttest_second')
@@ -171,8 +171,15 @@ def create_test_product(product_name, product_endpoint):
171171
product_cfg = create_test_product('producttest_second 2',
172172
'producttest_second_2')
173173

174-
self.assertTrue(self._pr_client_2.addProduct(product_cfg),
175-
"Cannot create product on secondary server.")
174+
# self.assertTrue(self._pr_client_2.addProduct(product_cfg),
175+
# "Cannot create product on secondary server.")
176+
177+
# expect request to fail
178+
with self.assertRaises(RequestFailed):
179+
self._pr_client_2.addProduct(product_cfg)
180+
181+
# self.assertTrue(self._pr_client_2.addProduct(product_cfg),
182+
# "Cannot create product on secondary server.")
176183

177184
# Product name full string match.
178185
products = self._pr_client_2.getProducts('producttest_second', None)
@@ -184,10 +191,10 @@ def create_test_product(product_name, product_endpoint):
184191

185192
# Product name substring match.
186193
products = self._pr_client_2.getProducts('producttest_second*', None)
187-
self.assertEqual(len(products), 2)
194+
self.assertEqual(len(products), 1)
188195

189196
products = self._pr_client_2.getProducts(None, 'producttest_second*')
190-
self.assertEqual(len(products), 2)
197+
self.assertEqual(len(products), 1)
191198

192199
# Use the same CodeChecker config that was used on the main server,
193200
# but store into the secondary one.

web/tests/functional/store/test_store.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ def setup_class(self):
7272

7373
server_access['viewer_product'] = 'store_limited_product'
7474
codechecker.add_test_package_product(server_access, TEST_WORKSPACE,
75-
report_limit=2)
75+
report_limit=2,
76+
database_name='store_limited_product')
7677

7778
server_access['viewer_product'] = 'store_test'
78-
codechecker.add_test_package_product(server_access, TEST_WORKSPACE)
79+
codechecker.add_test_package_product(server_access, TEST_WORKSPACE,
80+
database_name='store_test')
7981

8082
# Extend the checker configuration with the server access.
8183
codechecker_cfg.update(server_access)

web/tests/libtest/codechecker.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ def start_server_proc(event, server_cmd, checking_env):
733733

734734
def add_test_package_product(server_data, test_folder, check_env=None,
735735
protocol='http', report_limit=None,
736-
user_permissions=None):
736+
user_permissions=None,
737+
database_name="data.sqlite"):
737738
"""
738739
Add a product for a test suite to the server provided by server_data.
739740
Server must be running before called.
@@ -781,7 +782,7 @@ def add_test_package_product(server_data, test_folder, check_env=None,
781782
else:
782783
# SQLite databases are put under the workspace of the appropriate test.
783784
add_command += ['--sqlite',
784-
os.path.join(test_folder, 'data.sqlite')]
785+
os.path.join(test_folder, database_name)]
785786

786787
print(' '.join(add_command))
787788

0 commit comments

Comments
 (0)