-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Is765/extends products plugin (⚠️ devops) (#3540)
- Loading branch information
Showing
19 changed files
with
749 additions
and
245 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
...abase/src/simcore_postgres_database/migration/versions/2ca532b0831f_new_products_table.py
This file contains 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,105 @@ | ||
"""new products table | ||
Revision ID: 2ca532b0831f | ||
Revises: 90c92dae8fc9 | ||
Create Date: 2022-11-11 10:54:13.921120+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "2ca532b0831f" | ||
down_revision = "90c92dae8fc9" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"products", | ||
sa.Column("vendor", postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
) | ||
op.add_column( | ||
"products", | ||
sa.Column("issues", postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
) | ||
op.add_column( | ||
"products", | ||
sa.Column("manuals", postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
) | ||
op.add_column( | ||
"products", | ||
sa.Column("support", postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
) | ||
op.drop_column("products", "feedback_form_url") | ||
op.drop_column("products", "manual_extra_url") | ||
op.drop_column("products", "issues_new_url") | ||
op.drop_column("products", "manual_url") | ||
op.drop_column("products", "issues_login_url") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"products", | ||
sa.Column( | ||
"issues_login_url", | ||
sa.VARCHAR(), | ||
server_default=sa.text( | ||
"'https://github.com/ITISFoundation/osparc-simcore/issues'::character varying" | ||
), | ||
autoincrement=False, | ||
nullable=True, | ||
), | ||
) | ||
op.add_column( | ||
"products", | ||
sa.Column( | ||
"manual_url", | ||
sa.VARCHAR(), | ||
server_default=sa.text( | ||
"'https://itisfoundation.github.io/osparc-manual/'::character varying" | ||
), | ||
autoincrement=False, | ||
nullable=False, | ||
), | ||
) | ||
op.add_column( | ||
"products", | ||
sa.Column( | ||
"issues_new_url", | ||
sa.VARCHAR(), | ||
server_default=sa.text( | ||
"'https://github.com/ITISFoundation/osparc-simcore/issues/new'::character varying" | ||
), | ||
autoincrement=False, | ||
nullable=True, | ||
), | ||
) | ||
op.add_column( | ||
"products", | ||
sa.Column( | ||
"manual_extra_url", | ||
sa.VARCHAR(), | ||
server_default=sa.text( | ||
"'https://itisfoundation.github.io/osparc-manual-z43/'::character varying" | ||
), | ||
autoincrement=False, | ||
nullable=True, | ||
), | ||
) | ||
op.add_column( | ||
"products", | ||
sa.Column( | ||
"feedback_form_url", sa.VARCHAR(), autoincrement=False, nullable=True | ||
), | ||
) | ||
op.drop_column("products", "support") | ||
op.drop_column("products", "manuals") | ||
op.drop_column("products", "issues") | ||
op.drop_column("products", "vendor") | ||
# ### end Alembic commands ### |
This file contains 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 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 |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
# pylint: disable=unused-argument | ||
|
||
|
||
import json | ||
from pathlib import Path | ||
from pprint import pprint | ||
from typing import Callable | ||
|
||
import pytest | ||
|
@@ -13,11 +15,19 @@ | |
from aiopg.sa.exc import ResourceClosedError | ||
from aiopg.sa.result import ResultProxy, RowProxy | ||
from simcore_postgres_database.models.jinja2_templates import jinja2_templates | ||
from simcore_postgres_database.models.products import ( | ||
EmailFeedback, | ||
Forum, | ||
IssueTracker, | ||
Manual, | ||
Vendor, | ||
WebFeedback, | ||
) | ||
from simcore_postgres_database.webserver_models import products | ||
|
||
|
||
@pytest.fixture | ||
def product_sample() -> dict: | ||
def products_regex() -> dict: | ||
return { | ||
"osparc": r"^osparc.", | ||
"s4l": r"(^s4l[\.-])|(^sim4life\.)", | ||
|
@@ -27,10 +37,10 @@ def product_sample() -> dict: | |
|
||
@pytest.fixture | ||
def make_products_table( | ||
product_sample: dict, | ||
products_regex: dict, | ||
) -> Callable: | ||
async def _make(conn) -> None: | ||
for name, regex in product_sample.items(): | ||
for name, regex in products_regex.items(): | ||
result = await conn.execute( | ||
products.insert().values(name=name, host_regex=regex) | ||
) | ||
|
@@ -44,7 +54,7 @@ async def _make(conn) -> None: | |
|
||
|
||
async def test_load_products( | ||
pg_engine: Engine, make_products_table: Callable, product_sample: dict | ||
pg_engine: Engine, make_products_table: Callable, products_regex: dict | ||
): | ||
exclude = { | ||
products.c.created, | ||
|
@@ -63,7 +73,7 @@ async def test_load_products( | |
|
||
assert { | ||
row[products.c.name]: row[products.c.host_regex] for row in rows | ||
} == product_sample | ||
} == products_regex | ||
|
||
|
||
async def test_jinja2_templates_table( | ||
|
@@ -123,8 +133,8 @@ async def test_jinja2_templates_table( | |
result: ResultProxy = await conn.execute(stmt) | ||
assert result.rowcount == 2 | ||
assert await result.fetchall() == [ | ||
("s4l", "registration_email.jinja2", "s4l web"), | ||
("osparc", "registration_email.jinja2", "osparc"), | ||
("s4l", "registration_email.jinja2", "s4l web"), | ||
] | ||
|
||
assert ( | ||
|
@@ -144,3 +154,66 @@ async def test_jinja2_templates_table( | |
) | ||
is None | ||
) | ||
|
||
|
||
async def test_insert_select_product( | ||
pg_engine: Engine, | ||
): | ||
osparc_product = { | ||
"name": "osparc", | ||
"display_name": "o²S²PARC", | ||
"short_name": "osparc", | ||
"host_regex": r"([\.-]{0,1}osparc[\.-])", | ||
"support_email": "[email protected]", | ||
"twilio_messaging_sid": None, | ||
"vendor": Vendor( | ||
name="ACME", | ||
copyright="© ACME correcaminos", | ||
url="https://acme.com", | ||
), | ||
"issues": [ | ||
IssueTracker( | ||
label="github", | ||
login_url="https://github.com/ITISFoundation/osparc-simcore", | ||
new_url="https://github.com/ITISFoundation/osparc-simcore/issues/new/choose", | ||
), | ||
IssueTracker( | ||
label="fogbugz", | ||
login_url="https://fogbugz.com/login", | ||
new_url="https://fogbugz.com/new?project=123", | ||
), | ||
], | ||
"manuals": [ | ||
Manual(label="main", url="doc.acme.com"), | ||
Manual(label="z43", url="yet-another-manual.acme.com"), | ||
], | ||
"support": [ | ||
Forum(label="forum", kind="forum", url="forum.acme.com"), | ||
EmailFeedback(label="email", kind="email", email="[email protected]"), | ||
WebFeedback(label="web-form", kind="web", url="support.acme.com"), | ||
], | ||
} | ||
|
||
print(json.dumps(osparc_product)) | ||
|
||
async with pg_engine.acquire() as conn: | ||
# writes | ||
stmt = products.insert().values(**osparc_product).returning(products.c.name) | ||
name = await conn.scalar(stmt) | ||
|
||
# reads | ||
stmt = sa.select(products).where(products.c.name == name) | ||
row = await (await conn.execute(stmt)).fetchone() | ||
print(row) | ||
assert row | ||
|
||
pprint(dict(**row)) | ||
|
||
assert row.manuals | ||
assert row.manuals == osparc_product["manuals"] | ||
|
||
assert row.vendor == { | ||
"url": "https://acme.com", | ||
"name": "ACME", | ||
"copyright": "© ACME correcaminos", | ||
} |
File renamed without changes.
This file contains 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
Oops, something went wrong.