MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / create_test_db

Function create_test_db

tests/mssqltestutils.py:93–128  ·  view source on GitHub ↗

Creates database for test, using various status checks and retry logic for reliability. - Calls helper method to check status of create db task, if possible - Exits on successful response or retry period exceeds time limit

()

Source from the content-addressed store, hash-verified

91 return os.path.abspath(tempPath)
92
93def create_test_db():
94 """
95 Creates database for test, using various status checks and retry logic for reliability.
96 - Calls helper method to check status of create db task, if possible
97 - Exits on successful response or retry period exceeds time limit
98 """
99 options = create_mssql_cli_options(database='master')
100 client = create_mssql_cli_client(options)
101
102 local_machine_name = socket.gethostname().replace(
103 '-', '_').replace('.', '_')
104
105 test_db_name = u'mssqlcli_testdb_{0}_{1}'.format(
106 local_machine_name, random_str())
107 query_db_create = u"CREATE DATABASE {0};".format(test_db_name)
108
109 try:
110 for _, _, status, _, is_create_error in client.execute_query(query_db_create):
111 if _is_client_db_on_cloud(client):
112 # retry logic is only supported for sql azure
113 create_db_status, create_db_error = _check_create_db_status(test_db_name, client)
114
115 if create_db_status == 'FAILED':
116 # break loop to assert db creation failure
117 raise AssertionError("Database creation failed. Retry logic for SQL " \
118 "Azure DB was unsuccessful with the following error: " \
119 "\n{}".format(create_db_error))
120
121 if is_create_error:
122 # break loop to assert db creation failure
123 raise AssertionError("Database creation failed: {}".format(status))
124
125 return test_db_name
126
127 finally:
128 shutdown(client)
129
130def _is_client_db_on_cloud(client):
131 """

Callers 3

client_with_dbMethod · 0.90
test_multiple_mergeMethod · 0.90
test_dbMethod · 0.90

Calls 8

random_strFunction · 0.90
create_mssql_cli_optionsFunction · 0.85
create_mssql_cli_clientFunction · 0.85
_is_client_db_on_cloudFunction · 0.85
_check_create_db_statusFunction · 0.85
shutdownFunction · 0.85
formatMethod · 0.45
execute_queryMethod · 0.45

Tested by

no test coverage detected