Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d8b56a2
feat: ass samples for create and drop table
HemangChothani Apr 19, 2021
a36749b
feat: add sample for insert and fetch rows
HemangChothani Apr 20, 2021
4bfac00
feat: add row related samples
HemangChothani Apr 21, 2021
8005a89
feat: add delete and orderby test
HemangChothani Apr 22, 2021
02eb091
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Apr 29, 2021
a65b226
feat: remove CLI from samples
HemangChothani Apr 29, 2021
7ab99c2
feat: remove ununsed import and add filter like sample
HemangChothani May 1, 2021
d269c0e
feat: add more samples of startswith and endswith
HemangChothani May 3, 2021
550571d
feat: add samples for get table column primary key
HemangChothani May 11, 2021
b77539f
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 11, 2021
9388d91
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 12, 2021
585ea3a
feat: ass foreign key sample
HemangChothani May 12, 2021
0cf649b
feat: add get index sample
HemangChothani May 18, 2021
e14891d
feat: add create unique index sample
HemangChothani May 19, 2021
26632db
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 19, 2021
f69d070
feat: add limit and offset samples
HemangChothani May 19, 2021
dc21c74
feat: move all tests and added in nox
HemangChothani May 20, 2021
0a493f8
feat: nits
HemangChothani May 21, 2021
1a2643d
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 21, 2021
3c292f9
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 25, 2021
a4e3775
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 25, 2021
0fb8081
feat: open db connection explicitly
HemangChothani May 25, 2021
19e12b9
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 31, 2021
06c353e
feat: resolve conflict
HemangChothani Jun 8, 2021
67c16e8
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Jun 17, 2021
21a3e00
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Jun 17, 2021
8857441
Merge branch 'main' into demo_samples
AVaksman Jun 17, 2021
fbe3e79
WIP: update the SQLAlchemy samples
Sep 7, 2021
6bc37ee
Merge branch 'main' into demo_samples
skuruppu Sep 8, 2021
c8879fb
update samples
Sep 9, 2021
938320a
Merge branch 'demo_samples' of https://github.com/cloudspannerecosyst…
Sep 9, 2021
3143b0c
Merge branch 'main' into demo_samples
Sep 9, 2021
49f2ac8
del excess with statements
Sep 9, 2021
9de08a8
Merge branch 'demo_samples' of https://github.com/cloudspannerecosyst…
Sep 9, 2021
d52e2c8
change tags prefixes
Sep 9, 2021
b9b47ec
update contributing.md
Sep 10, 2021
228c261
Apply suggestions from code review
larkee Sep 16, 2021
fa96c05
Merge branch 'main' into demo_samples
Sep 16, 2021
87ec881
Merge branch 'demo_samples' of https://github.com/cloudspannerecosyst…
Sep 16, 2021
701f7a8
erase excess whitespaces
Sep 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,29 @@ information on using pull requests.

This project follows [Google's Open Source Community
Guidelines](https://opensource.google/conduct/).

## Running tests

SQLAlchemy Spanner dialect includes a test suite, which can be executed both on a live service and Spanner emulator.

**Using pytest**
To execute the test suite with standard `pytest` package you only need to checkout to the package folder and run:
```
pytest -v
```

**Using nox**
The package includes a configuration file for `nox` package, which allows to execute the dialect test suite in an isolated virtual environment. To execute all the `nox` sessions checkout to the dialect folder and then run command:
```
nox
```
To execute only the dialect compliance test suite execute command:
```
nox -s compliance_test
```

**Live service**
To run the test suite on a live service use [setup.cfg](https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy/blob/main/setup.cfg) `db.default` attribute to set URI of the project, instance and database, where the tests should be executed.

**Emulator**
As the dialect is built on top of the Spanner DB API, it also supports running on Spanner emulator. To make it happen you need to set an environment variable, pointing to the emulator service, for example `SPANNER_EMULATOR_HOST=localhost:9010`
25 changes: 24 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class = StreamHandler


BLACK_VERSION = "black==19.10b0"
BLACK_PATHS = ["google", "test", "noxfile.py", "setup.py"]
BLACK_PATHS = ["google", "test", "noxfile.py", "setup.py", "samples"]
DEFAULT_PYTHON_VERSION = "3.8"


Expand Down Expand Up @@ -178,3 +178,26 @@ def migration_test(session):
session.run("python", "migration_test_cleanup.py")
if os.path.exists("test.cfg"):
os.remove("test.cfg")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def snippets(session):
"""Run the documentation example snippets."""
# Sanity check: Only run snippets system tests if the environment variable
# is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable.")

session.install("pytest")
session.install("sqlalchemy")
session.install(
"git+https://github.com/googleapis/python-spanner.git#egg=google-cloud-spanner"
)
session.install("-e", ".")
session.run("python", "create_test_database.py")
session.run(
"py.test",
"--quiet",
os.path.join("samples", "snippets_test.py"),
*session.posargs,
)
Empty file added samples/__init__.py
Empty file.
92 changes: 92 additions & 0 deletions samples/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
import uuid

import pytest

from sqlalchemy import (
Column,
Integer,
MetaData,
String,
Table,
create_engine,
ForeignKey,
)


@pytest.fixture
def db_url():
return (
"spanner:///projects/appdev-soda-spanner-staging/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)


@pytest.fixture
def table_id():
now = datetime.datetime.now()
table_id = "example_table_{}_{}".format(
now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex[:8]
)
return table_id


@pytest.fixture
def table(db_url, table_id):
engine = create_engine(db_url)
metadata = MetaData(bind=engine)

table = Table(
table_id,
metadata,
Column("user_id", Integer, primary_key=True),
Column("user_name", String(16), nullable=False),
)
table.create()
yield table
table.drop()


@pytest.fixture
def table_w_foreign_key(db_url, table):
engine = create_engine(db_url)
metadata = MetaData(bind=engine)

table_fk = Table(
"table_fk",
metadata,
Column("id", Integer, primary_key=True),
Column("name", String(16), nullable=False),
Column(
table.name + "_user_id",
Integer,
ForeignKey(table.c.user_id, name=table.name + "user_id"),
),
)
table_fk.create()
yield table_fk
table_fk.drop()


@pytest.fixture
def connection(db_url):
engine = create_engine(db_url)
return engine.connect()


def insert_data(conn, table, data):
conn.execute(table.insert(), data)
Loading