Skip to content

Commit

Permalink
[db-up] Test db up (#543)
Browse files Browse the repository at this point in the history
* initial tests

* added testing and edited show connection string commands

* static check
  • Loading branch information
williexu authored Feb 28, 2019
1 parent 5a82cfc commit 8697980
Show file tree
Hide file tree
Showing 6 changed files with 2,429 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/db-up/azext_db_up/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def mysql_up(cmd, client, resource_group_name=None, server_name=None, location=N
_create_database(db_context, cmd, resource_group_name, server_name, database_name)

# check ip address(es) of the user and configure firewall rules
mysql_errors = (mysql_connector.errors.DatabaseError)
mysql_errors = (mysql_connector.errors.DatabaseError, mysql_connector.errors.InterfaceError)
host, user = _configure_firewall_rules(
db_context, mysql_errors, cmd, server_result, resource_group_name, server_name, administrator_login,
administrator_login_password, database_name)
Expand Down Expand Up @@ -127,13 +127,11 @@ def postgres_up(cmd, client, resource_group_name=None, server_name=None, locatio
if administrator_login_password is not None:
_run_postgresql_commands(host, user, administrator_login_password, database_name)

return {
'connectionStrings': _create_postgresql_connection_string(
host, user, administrator_login_password, database_name),
'host': host,
'username': user,
'password': administrator_login_password if administrator_login_password is not None else '*****'
}
return _form_response(
_create_postgresql_connection_string(host, user, administrator_login_password, database_name),
host, user,
administrator_login_password if administrator_login_password is not None else '*****'
)


def server_down(cmd, client, resource_group_name=None, server_name=None, delete_group=None):
Expand All @@ -154,15 +152,30 @@ def create_mysql_connection_string(
administrator_login_password='{password}'):
user = '{}@{}'.format(administrator_login, server_name)
host = '{}.mysql.database.azure.com'.format(server_name)
return _create_mysql_connection_string(host, user, administrator_login_password, database_name)
return _form_response(
_create_mysql_connection_string(host, user, administrator_login_password, database_name),
host, user, administrator_login_password
)


def create_postgresql_connection_string(
server_name='{server}', database_name='{database}', administrator_login='{login}',
administrator_login_password='{password}'):
user = '{}@{}'.format(administrator_login, server_name)
host = '{}.postgres.database.azure.com'.format(server_name)
return _create_postgresql_connection_string(host, user, administrator_login_password, database_name)
return _form_response(
_create_postgresql_connection_string(host, user, administrator_login_password, database_name),
host, user, administrator_login_password
)


def _form_response(connection_strings, host, username, password):
return {
'connectionStrings': connection_strings,
'host': host,
'username': username,
'password': password
}


def _create_mysql_connection_string(host, user, password, database):
Expand Down
4 changes: 4 additions & 0 deletions src/db-up/azext_db_up/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
4 changes: 4 additions & 0 deletions src/db-up/azext_db_up/tests/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
Loading

0 comments on commit 8697980

Please sign in to comment.