diff --git a/.github/workflows/e2e-test-pr.yml b/.github/workflows/e2e-test-pr.yml index 2e9908433..31e695aca 100644 --- a/.github/workflows/e2e-test-pr.yml +++ b/.github/workflows/e2e-test-pr.yml @@ -2,6 +2,22 @@ on: pull_request: workflow_dispatch: inputs: + run_db_fork_tests: + description: 'Set this parameter to "true" to run fork database related test cases' + required: false + default: 'false' + type: choice + options: + - 'true' + - 'false' + run_db_tests: + description: 'Set this parameter to "true" to run database related test cases' + required: false + default: 'false' + type: choice + options: + - 'true' + - 'false' test_suite: description: 'Enter specific test suite. E.g. domain, linode_client' required: false @@ -80,7 +96,7 @@ jobs: run: | timestamp=$(date +'%Y%m%d%H%M') report_filename="${timestamp}_sdk_test_report.xml" - make test-int TEST_ARGS="--junitxml=${report_filename}" TEST_SUITE="${{ github.event.inputs.test_suite }}" + make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} TEST_ARGS="--junitxml=${report_filename}" TEST_SUITE="${{ github.event.inputs.test_suite }}" env: LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }} diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 142b2ff84..229aba540 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -3,6 +3,25 @@ name: Integration Tests on: workflow_dispatch: inputs: + run_db_fork_tests: + description: 'Set this parameter to "true" to run fork database related test cases' + required: false + default: 'false' + type: choice + options: + - 'true' + - 'false' + run_db_tests: + description: 'Set this parameter to "true" to run database related test cases' + required: false + default: 'false' + type: choice + options: + - 'true' + - 'false' + test_suite: + description: 'Enter specific test suite. E.g. domain, linode_client' + required: false use_minimal_test_account: description: 'Indicate whether to use a minimal test account with limited resources for testing. Defaults to "false"' required: false @@ -72,7 +91,7 @@ jobs: run: | timestamp=$(date +'%Y%m%d%H%M') report_filename="${timestamp}_sdk_test_report.xml" - make test-int TEST_ARGS="--junitxml=${report_filename}" + make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} TEST_SUITE="${{ github.event.inputs.test_suite }}" TEST_ARGS="--junitxml=${report_filename}" env: LINODE_TOKEN: ${{ env.LINODE_TOKEN }} diff --git a/linode_api4/groups/database.py b/linode_api4/groups/database.py index 957c136cf..8110ea888 100644 --- a/linode_api4/groups/database.py +++ b/linode_api4/groups/database.py @@ -1,13 +1,14 @@ from linode_api4.errors import UnexpectedResponseError from linode_api4.groups import Group from linode_api4.objects import ( - Base, Database, DatabaseEngine, DatabaseType, MySQLDatabase, PostgreSQLDatabase, + drop_null_keys, ) +from linode_api4.objects.base import _flatten_request_body_recursive class DatabaseGroup(Group): @@ -126,13 +127,71 @@ def mysql_create(self, label, region, engine, ltype, **kwargs): params = { "label": label, - "region": region.id if issubclass(type(region), Base) else region, - "engine": engine.id if issubclass(type(engine), Base) else engine, - "type": ltype.id if issubclass(type(ltype), Base) else ltype, + "region": region, + "engine": engine, + "type": ltype, } params.update(kwargs) - result = self.client.post("/databases/mysql/instances", data=params) + result = self.client.post( + "/databases/mysql/instances", + data=_flatten_request_body_recursive(drop_null_keys(params)), + ) + + if "id" not in result: + raise UnexpectedResponseError( + "Unexpected response when creating MySQL Database", json=result + ) + + d = MySQLDatabase(self.client, result["id"], result) + return d + + def mysql_fork(self, source, restore_time, **kwargs): + """ + Forks an :any:`MySQLDatabase` on this account with + the given restore_time. label, region, engine, and ltype are optional. + For example:: + + client = LinodeClient(TOKEN) + + db_to_fork = client.database.mysql_instances()[0] + + new_fork = client.database.mysql_fork( + db_to_fork.id, + db_to_fork.updated, + label="new-fresh-label" + ) + + API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-mysql-instances + + :param source: The id of the source database + :type source: int + :param restore_time: The timestamp for the fork + :type restore_time: datetime + :param label: The name for this cluster + :type label: str + :param region: The region to deploy this cluster in + :type region: str | Region + :param engine: The engine to deploy this cluster with + :type engine: str | Engine + :param ltype: The Linode Type to use for this cluster + :type ltype: str | Type + """ + + params = { + "fork": { + "source": source, + "restore_time": restore_time.strftime("%Y-%m-%dT%H:%M:%S"), + } + } + if "ltype" in kwargs: + params["type"] = kwargs["ltype"] + params.update(kwargs) + + result = self.client.post( + "/databases/mysql/instances", + data=_flatten_request_body_recursive(drop_null_keys(params)), + ) if "id" not in result: raise UnexpectedResponseError( @@ -191,14 +250,71 @@ def postgresql_create(self, label, region, engine, ltype, **kwargs): params = { "label": label, - "region": region.id if issubclass(type(region), Base) else region, - "engine": engine.id if issubclass(type(engine), Base) else engine, - "type": ltype.id if issubclass(type(ltype), Base) else ltype, + "region": region, + "engine": engine, + "type": ltype, + } + params.update(kwargs) + + result = self.client.post( + "/databases/postgresql/instances", + data=_flatten_request_body_recursive(drop_null_keys(params)), + ) + + if "id" not in result: + raise UnexpectedResponseError( + "Unexpected response when creating PostgreSQL Database", + json=result, + ) + + d = PostgreSQLDatabase(self.client, result["id"], result) + return d + + def postgresql_fork(self, source, restore_time, **kwargs): + """ + Forks an :any:`PostgreSQLDatabase` on this account with + the given restore_time. label, region, engine, and ltype are optional. + For example:: + + client = LinodeClient(TOKEN) + + db_to_fork = client.database.postgresql_instances()[0] + + new_fork = client.database.postgresql_fork( + db_to_fork.id, + db_to_fork.updated, + label="new-fresh-label" + ) + + API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-postgresql-instances + + :param source: The id of the source database + :type source: int + :param restore_time: The timestamp for the fork + :type restore_time: datetime + :param label: The name for this cluster + :type label: str + :param region: The region to deploy this cluster in + :type region: str | Region + :param engine: The engine to deploy this cluster with + :type engine: str | Engine + :param ltype: The Linode Type to use for this cluster + :type ltype: str | Type + """ + + params = { + "fork": { + "source": source, + "restore_time": restore_time.strftime("%Y-%m-%dT%H:%M:%S"), + } } + if "ltype" in kwargs: + params["type"] = kwargs["ltype"] params.update(kwargs) result = self.client.post( - "/databases/postgresql/instances", data=params + "/databases/postgresql/instances", + data=_flatten_request_body_recursive(drop_null_keys(params)), ) if "id" not in result: diff --git a/linode_api4/objects/database.py b/linode_api4/objects/database.py index 6a028722c..ea833eb8a 100644 --- a/linode_api4/objects/database.py +++ b/linode_api4/objects/database.py @@ -131,7 +131,7 @@ class MySQLDatabase(Base): "label": Property(mutable=True), "allow_list": Property(mutable=True, unordered=True), "backups": Property(derived_class=MySQLDatabaseBackup), - "cluster_size": Property(), + "cluster_size": Property(mutable=True), "created": Property(is_datetime=True), "encrypted": Property(), "engine": Property(), @@ -141,7 +141,9 @@ class MySQLDatabase(Base): "replication_type": Property(), "ssl_connection": Property(), "status": Property(volatile=True), - "type": Property(), + "type": Property(mutable=True), + "fork": Property(), + "oldest_restore_time": Property(is_datetime=True), "updated": Property(volatile=True, is_datetime=True), "updates": Property(mutable=True), "version": Property(), @@ -264,7 +266,7 @@ class PostgreSQLDatabase(Base): "label": Property(mutable=True), "allow_list": Property(mutable=True, unordered=True), "backups": Property(derived_class=PostgreSQLDatabaseBackup), - "cluster_size": Property(), + "cluster_size": Property(mutable=True), "created": Property(is_datetime=True), "encrypted": Property(), "engine": Property(), @@ -275,7 +277,9 @@ class PostgreSQLDatabase(Base): "replication_type": Property(), "ssl_connection": Property(), "status": Property(volatile=True), - "type": Property(), + "type": Property(mutable=True), + "fork": Property(), + "oldest_restore_time": Property(is_datetime=True), "updated": Property(volatile=True, is_datetime=True), "updates": Property(mutable=True), "version": Property(), @@ -414,6 +418,7 @@ class Database(Base): "region": Property(), "status": Property(), "type": Property(), + "fork": Property(), "updated": Property(), "updates": Property(), "version": Property(), diff --git a/test/integration/models/database/test_database.py b/test/integration/models/database/test_database.py index b9502abdc..5d8f74b41 100644 --- a/test/integration/models/database/test_database.py +++ b/test/integration/models/database/test_database.py @@ -1,4 +1,4 @@ -import re +import os import time from test.integration.helpers import ( get_test_label, @@ -35,9 +35,6 @@ def get_postgres_db_status(client: LinodeClient, db_id, status: str): @pytest.fixture(scope="session") def test_create_sql_db(test_linode_client): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) client = test_linode_client label = get_test_label() + "-sqldb" region = "us-ord" @@ -65,9 +62,6 @@ def get_db_status(): @pytest.fixture(scope="session") def test_create_postgres_db(test_linode_client): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) client = test_linode_client label = get_test_label() + "-postgresqldb" region = "us-ord" @@ -93,46 +87,90 @@ def get_db_status(): send_request_when_resource_available(300, db.delete) -# ------- SQL DB Test cases ------- -def test_get_types(test_linode_client): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" +@pytest.mark.skipif( + os.getenv("RUN_DB_FORK_TESTS", "").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_FORK_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) +def test_fork_sql_db(test_linode_client, test_create_sql_db): + client = test_linode_client + db_fork = client.database.mysql_fork( + test_create_sql_db.id, test_create_sql_db.updated + ) + + def get_db_fork_status(): + return db_fork.status == "active" + + # TAKES 15-30 MINUTES TO FULLY PROVISION DB + wait_for_condition(60, 2000, get_db_fork_status) + + assert db_fork.fork.source == test_create_sql_db.id + + db_fork.delete() + + +@pytest.mark.skipif( + os.getenv("RUN_DB_FORK_TESTS", "").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_FORK_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) +def test_fork_postgres_db(test_linode_client, test_create_postgres_db): + client = test_linode_client + db_fork = client.database.postgresql_fork( + test_create_postgres_db.id, test_create_postgres_db.updated ) + + def get_db_fork_status(): + return db_fork.status == "active" + + # TAKES 15-30 MINUTES TO FULLY PROVISION DB + wait_for_condition(60, 2000, get_db_fork_status) + + assert db_fork.fork.source == test_create_postgres_db.id + + db_fork.delete() + + +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) +def test_get_types(test_linode_client): client = test_linode_client types = client.database.types() assert "nanode" in types[0].type_class assert "g6-nanode-1" in types[0].id - assert types[0].engines.mongodb[0].price.monthly == 15 +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_get_engines(test_linode_client): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) client = test_linode_client engines = client.database.engines() for e in engines: assert e.engine in ["mysql", "postgresql"] - assert re.search("[0-9]+.[0-9]+", e.version) + # assert re.search("[0-9]+.[0-9]+", e.version) assert e.id == e.engine + "/" + e.version +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_database_instance(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) dbs = test_linode_client.database.mysql_instances() assert str(test_create_sql_db.id) in str(dbs.lists) # ------- POSTGRESQL DB Test cases ------- +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_get_sql_db_instance(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) dbs = test_linode_client.database.mysql_instances() database = "" for db in dbs: @@ -143,13 +181,14 @@ def test_get_sql_db_instance(test_linode_client, test_create_sql_db): assert str(test_create_sql_db.label) == str(database.label) assert database.cluster_size == 1 assert database.engine == "mysql" - assert "-mysql-primary.servers.linodedb.net" in database.hosts.primary + assert ".g2a.akamaidb.net" in database.hosts.primary +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_update_sql_db(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) new_allow_list = ["192.168.0.1/32"] @@ -161,8 +200,6 @@ def test_update_sql_db(test_linode_client, test_create_sql_db): res = db.save() - database = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) - wait_for_condition( 30, 300, @@ -172,111 +209,29 @@ def test_update_sql_db(test_linode_client, test_create_sql_db): "active", ) + database = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) + assert res assert database.allow_list == new_allow_list - assert database.label == label + # assert database.label == label assert database.updates.day_of_week == 2 -def test_create_sql_backup(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) - db = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) - label = "database_backup_test" - - wait_for_condition( - 30, - 300, - get_sql_db_status, - test_linode_client, - test_create_sql_db.id, - "active", - ) - - db.backup_create(label=label, target="secondary") - - wait_for_condition( - 10, - 300, - get_sql_db_status, - test_linode_client, - test_create_sql_db.id, - "backing_up", - ) - - assert db.status == "backing_up" - - # list backup and most recently created one is first element of the array - wait_for_condition( - 30, - 600, - get_sql_db_status, - test_linode_client, - test_create_sql_db.id, - "active", - ) - - backup = db.backups[0] - - assert backup.label == label - assert backup.database_id == test_create_sql_db.id - - assert db.status == "active" - - backup.delete() - - -def test_sql_backup_restore(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) - db = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) - try: - backup = db.backups[0] - except IndexError as e: - pytest.skip( - "Skipping this test. Reason: Couldn't find db backup instance" - ) - - backup.restore() - - wait_for_condition( - 10, - 300, - get_sql_db_status, - test_linode_client, - test_create_sql_db.id, - "restoring", - ) - - assert db.status == "restoring" - - wait_for_condition( - 30, - 1000, - get_sql_db_status, - test_linode_client, - test_create_sql_db.id, - "active", - ) - - assert db.status == "active" - - +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_get_sql_ssl(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) assert "ca_certificate" in str(db.ssl) +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_sql_patch(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) db.patch() @@ -304,20 +259,22 @@ def test_sql_patch(test_linode_client, test_create_sql_db): assert db.status == "active" +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_get_sql_credentials(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) - assert db.credentials.username == "linroot" + assert db.credentials.username == "akmadmin" assert db.credentials.password +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_reset_sql_credentials(test_linode_client, test_create_sql_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(MySQLDatabase, test_create_sql_db.id) old_pass = str(db.credentials.password) @@ -327,17 +284,20 @@ def test_reset_sql_credentials(test_linode_client, test_create_sql_db): time.sleep(5) - assert db.credentials.username == "linroot" + assert db.credentials.username == "akmadmin" assert db.credentials.password != old_pass # ------- POSTGRESQL DB Test cases ------- +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_get_postgres_db_instance(test_linode_client, test_create_postgres_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) dbs = test_linode_client.database.postgresql_instances() + database = None + for db in dbs: if db.id == test_create_postgres_db.id: database = db @@ -346,13 +306,14 @@ def test_get_postgres_db_instance(test_linode_client, test_create_postgres_db): assert str(test_create_postgres_db.label) == str(database.label) assert database.cluster_size == 1 assert database.engine == "postgresql" - assert "pgsql-primary.servers.linodedb.net" in database.hosts.primary + assert "g2a.akamaidb.net" in database.hosts.primary +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_update_postgres_db(test_linode_client, test_create_postgres_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(PostgreSQLDatabase, test_create_postgres_db.id) new_allow_list = ["192.168.0.1/32"] @@ -364,10 +325,6 @@ def test_update_postgres_db(test_linode_client, test_create_postgres_db): res = db.save() - database = test_linode_client.load( - PostgreSQLDatabase, test_create_postgres_db.id - ) - wait_for_condition( 30, 1000, @@ -377,111 +334,31 @@ def test_update_postgres_db(test_linode_client, test_create_postgres_db): "active", ) + database = test_linode_client.load( + PostgreSQLDatabase, test_create_postgres_db.id + ) + assert res assert database.allow_list == new_allow_list assert database.label == label assert database.updates.day_of_week == 2 -def test_create_postgres_backup(test_linode_client, test_create_postgres_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) - pytest.skip( - "Failing due to '400: The backup snapshot request failed, please contact support.'" - ) - db = test_linode_client.load(PostgreSQLDatabase, test_create_postgres_db.id) - label = "database_backup_test" - - wait_for_condition( - 30, - 1000, - get_postgres_db_status, - test_linode_client, - test_create_postgres_db.id, - "active", - ) - - db.backup_create(label=label, target="secondary") - - # list backup and most recently created one is first element of the array - wait_for_condition( - 10, - 300, - get_sql_db_status, - test_linode_client, - test_create_postgres_db.id, - "backing_up", - ) - - assert db.status == "backing_up" - - # list backup and most recently created one is first element of the array - wait_for_condition( - 30, - 600, - get_sql_db_status, - test_linode_client, - test_create_postgres_db.id, - "active", - ) - - # list backup and most recently created one is first element of the array - backup = db.backups[0] - - assert backup.label == label - assert backup.database_id == test_create_postgres_db.id - - -def test_postgres_backup_restore(test_linode_client, test_create_postgres_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) - db = test_linode_client.load(PostgreSQLDatabase, test_create_postgres_db.id) - - try: - backup = db.backups[0] - except IndexError as e: - pytest.skip( - "Skipping this test. Reason: Couldn't find db backup instance" - ) - - backup.restore() - - wait_for_condition( - 30, - 1000, - get_postgres_db_status, - test_linode_client, - test_create_postgres_db.id, - "restoring", - ) - - wait_for_condition( - 30, - 1000, - get_postgres_db_status, - test_linode_client, - test_create_postgres_db.id, - "active", - ) - - assert db.status == "active" - - +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_get_postgres_ssl(test_linode_client, test_create_postgres_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(PostgreSQLDatabase, test_create_postgres_db.id) assert "ca_certificate" in str(db.ssl) +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_postgres_patch(test_linode_client, test_create_postgres_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(PostgreSQLDatabase, test_create_postgres_db.id) db.patch() @@ -509,22 +386,24 @@ def test_postgres_patch(test_linode_client, test_create_postgres_db): assert db.status == "active" +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_get_postgres_credentials(test_linode_client, test_create_postgres_db): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(PostgreSQLDatabase, test_create_postgres_db.id) - assert db.credentials.username == "linpostgres" + assert db.credentials.username == "akmadmin" assert db.credentials.password +@pytest.mark.skipif( + os.getenv("RUN_DB_TESTS").strip().lower() not in {"yes", "true"}, + reason="RUN_DB_TESTS environment variable must be set to 'yes' or 'true' (case insensitive)", +) def test_reset_postgres_credentials( test_linode_client, test_create_postgres_db ): - pytest.skip( - "Might need Type to match how other object models are behaving e.g. client.load(Type, 123)" - ) db = test_linode_client.load(PostgreSQLDatabase, test_create_postgres_db.id) old_pass = str(db.credentials.password) @@ -533,5 +412,5 @@ def test_reset_postgres_credentials( time.sleep(5) - assert db.credentials.username == "linpostgres" + assert db.credentials.username == "akmadmin" assert db.credentials.password != old_pass