-
Notifications
You must be signed in to change notification settings - Fork 0
#21: Created integration test for operation "create DB" #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
cdd3256
Addded changes file
ckunki 824952c
#21: Added integration tests
ckunki 4ddfc1b
Updated version to 0.3.0
ckunki 5698fad
Described environment variables for integration tests in developer guide
ckunki d369d58
re-activated coverage
ckunki bb2bb05
Use org secrets
ckunki 0e19e95
Moved secrets section to job-level of GitHub workflow file
ckunki ed92b83
changed secrets syntax to env
ckunki 2a12ca4
Adde output for SAAS_HOST
ckunki 0d2ee95
Added quotes around secrets
ckunki 1c4a872
experiment for environment variables
ckunki 2452a97
experiment for environment variables
ckunki a21a2b8
experiment for environment variables
ckunki c3baea5
experiment for environment variables
ckunki 497d6ff
experiment for environment variables
ckunki 9f993db
experiment for environment variables
ckunki a934d59
experiment for environment variables
ckunki eaba3c7
experiment for environment variables
ckunki 3e287cf
experiment for environment variables
ckunki db6d835
inherit secrets to child job
ckunki 338fcf4
Added raise_on_unexpected_status=True
ckunki f2ec4f4
Fixed tests
ckunki 5990868
Refactored tests
ckunki fdbee75
Fixed tests
ckunki 467fee9
Implemtented integration tests for allowed ip addresses
ckunki c9fd039
Fixed review findings
ckunki 44480eb
Removed code related to ip whitelists
ckunki 527c819
Fixed additional review findings
ckunki 4caf15a
Set scope of fixtures to "session"
ckunki 4e9a469
Fixed import
ckunki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Saas API Python 0.3.0, released tbd | ||
|
|
||
| ## Summary | ||
|
|
||
| This release adds integration tests for the most important calls to SaaS API. | ||
|
|
||
| ## Refactorings | ||
|
|
||
| * #21: Added integration test for operation "create database" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [tool.poetry] | ||
| name = "saas-api" | ||
| version = "0.2.0" | ||
| version = "0.3.0" | ||
| description = "API enabling Python applications connecting to Exasol database SaaS instances and using their SaaS services" | ||
| packages = [ {include = "exasol"}, ] | ||
| authors = [ "Christoph Kuhnke <[email protected]>" ] | ||
|
|
@@ -77,6 +77,7 @@ ignore = [ | |
| ] | ||
| ignore-paths = [ | ||
| ".*/exasol/saas/client/openapi/.*", | ||
| ".*/test/.*", | ||
| ] | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| from typing import Iterable | ||
| from contextlib import contextmanager | ||
| from datetime import datetime | ||
|
|
||
| from exasol.saas.client import openapi | ||
| from exasol.saas.client.openapi.api.databases import ( | ||
| create_database, | ||
| delete_database, | ||
| list_databases, | ||
| ) | ||
| from exasol.saas.client.openapi.api.security import ( | ||
| list_allowed_i_ps, | ||
| add_allowed_ip, | ||
| delete_allowed_ip, | ||
| ) | ||
|
|
||
|
|
||
| def timestamp() -> str: | ||
| return f'{datetime.now().timestamp():.0f}' | ||
|
|
||
|
|
||
| def create_saas_client( | ||
| host: str, | ||
| pat: str, | ||
| raise_on_unexpected_status: bool = True, | ||
| ) -> openapi.AuthenticatedClient: | ||
| return openapi.AuthenticatedClient( | ||
| base_url=host, | ||
| token=pat, | ||
| raise_on_unexpected_status = raise_on_unexpected_status, | ||
| ) | ||
|
|
||
|
|
||
| class _OpenApiAccess: | ||
| """ | ||
| This class is meant to be used only in the context of the API | ||
| generator repository while integration tests in other repositories are | ||
| planned to only use fixture ``saas_database_id()``. | ||
| """ | ||
|
|
||
| def __init__(self, client: openapi.Client, account_id: str): | ||
| self._client = client | ||
| self._account_id = account_id | ||
|
|
||
| def create_database(self, cluster_size: str = "XS") -> openapi.models.database.Database: | ||
| cluster_spec = openapi.models.CreateCluster( | ||
| name="my-cluster", | ||
| size=cluster_size, | ||
| ) | ||
| return create_database.sync( | ||
| self._account_id, | ||
| client=self._client, | ||
| body=openapi.models.CreateDatabase( | ||
| name=f"pytest-{timestamp()}", | ||
| initial_cluster=cluster_spec, | ||
| provider="aws", | ||
| region='us-east-1', | ||
| ) | ||
| ) | ||
|
|
||
| @contextmanager | ||
| def _ignore_failures(self, ignore: bool = False): | ||
| before = self._client.raise_on_unexpected_status | ||
| self._client.raise_on_unexpected_status = not ignore | ||
| yield self._client | ||
| self._client.raise_on_unexpected_status = before | ||
|
|
||
| def delete_database(self, database_id: str, ignore_failures=False): | ||
| with self._ignore_failures(ignore_failures) as client: | ||
| return delete_database.sync_detailed( | ||
| self._account_id, database_id, client=client) | ||
|
|
||
| def list_database_ids(self) -> Iterable[str]: | ||
| dbs = list_databases.sync(self._account_id, client=self._client) | ||
| return (db.id for db in dbs) | ||
|
|
||
| @contextmanager | ||
| def database( | ||
| self, | ||
| keep: bool = False, | ||
| ignore_delete_failure: bool = False, | ||
| ): | ||
| db = None | ||
| try: | ||
| db = self.create_database() | ||
| yield db | ||
| finally: | ||
| if not keep and db: | ||
| self.delete_database(db.id, ignore_delete_failure) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import pytest | ||
| import os | ||
|
|
||
| from exasol.saas.client import openapi | ||
| from api_access import create_saas_client, _OpenApiAccess | ||
|
|
||
| @pytest.fixture(scope="session") | ||
| def saas_host() -> str: | ||
| return os.environ["SAAS_HOST"] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def saas_pat() -> str: | ||
| return os.environ["SAAS_PAT"] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def saas_account_id() -> str: | ||
| return os.environ["SAAS_ACCOUNT_ID"] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def api_access(saas_host, saas_pat, saas_account_id) -> _OpenApiAccess: | ||
| with create_saas_client(saas_host, saas_pat) as client: | ||
| yield _OpenApiAccess(client, saas_account_id) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def saas_database(api_access) -> openapi.models.database.Database: | ||
| """ | ||
| Note: The SaaS instance database returned by this fixture initially | ||
| will not be operational. The startup takes about 20 minutes. | ||
| """ | ||
| with api_access.database() as db: | ||
| yield db | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from exasol.saas.client import openapi | ||
|
|
||
|
|
||
| def test_lifecycle(api_access): | ||
| """ | ||
| This integration test uses the database created and provided by pytest | ||
| context ``_OpenApiAccess.database()`` to verify | ||
|
|
||
| - initial status and number of clusters of the created database | ||
| - list_databases includes the new database | ||
| - delete_database deletes the database | ||
| - list_databases does not include the deleted database anymore | ||
| """ | ||
|
|
||
| testee = api_access | ||
| with testee.database(ignore_delete_failure=True) as db: | ||
| # verify state and clusters of created database | ||
| assert db.status == openapi.models.Status.TOCREATE and \ | ||
| db.clusters.total == 1 | ||
|
|
||
| # verify database is listed | ||
| assert db.id in testee.list_database_ids() | ||
|
|
||
| # delete database and verify database is not listed anymore | ||
| testee.delete_database(db.id) | ||
| assert db.id not in testee.list_database_ids() |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.