Skip to content

Commit

Permalink
Clone use cases from the use case store as draft (jsocol#149)
Browse files Browse the repository at this point in the history
* Clone use cases from the use case store as draft

* Upgrade requirements and precommits
  • Loading branch information
maxime-fender authored May 31, 2022
1 parent a467841 commit c00c11d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ repos:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.950
rev: v0.960
hooks:
- id: mypy
args: [--ignore-missing-imports]
Expand Down
4 changes: 2 additions & 2 deletions requirements-base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# File generated automatically. Do not update it manually.
# Update files in the requirements folder instead.
pip==22.0.4
setuptools==62.2.0
pip==22.1.1
setuptools==62.3.2
wheel==0.37.1
38 changes: 19 additions & 19 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# File generated automatically. Do not update it manually.
# Update files in the requirements folder instead.
alembic==1.7.7
anyio==3.5.0
apispec==5.2.1
anyio==3.6.1
apispec==5.2.2
apispec-webframeworks==0.5.2
asgiref==3.5.1
asgiref==3.5.2
astroid==2.11.5
attrs==21.4.0
black==22.3.0
boto3==1.22.11
botocore==1.25.11
boto3==1.23.10
botocore==1.26.10
callee==0.3.1
certifi==2021.10.8
certifi==2022.5.18.1
cffi==1.15.0
cfgv==3.3.1
charset-normalizer==2.0.12
Expand All @@ -20,19 +20,19 @@ content-size-limit-asgi==0.1.5
cryptography==37.0.2
decopatch==1.4.10
dependency-injector==4.39.1
dill==0.3.4
dill==0.3.5.1
distlib==0.3.4
factory-boy==3.2.1
Faker==13.11.0
fastapi==0.77.1
filelock==3.6.0
Faker==13.12.0
fastapi==0.78.0
filelock==3.7.0
Flask==2.1.2
freezegun==1.2.1
funcy==1.17
greenlet==1.1.2
gunicorn==20.1.0
h11==0.13.0
identify==2.5.0
identify==2.5.1
idna==3.3
iniconfig==1.1.1
isort==5.10.1
Expand All @@ -43,13 +43,13 @@ lazy-object-proxy==1.7.1
makefun==1.13.1
Mako==1.2.0
MarkupSafe==2.1.1
marshmallow==3.15.0
marshmallow==3.16.0
marshmallow-dataclass==8.5.3
marshmallow-enum==1.5.1
mccabe==0.7.0
more-itertools==8.13.0
moto==3.1.8
mypy==0.950
moto==3.1.11
mypy==0.960
mypy-extensions==0.4.3
nodeenv==1.6.0
packaging==21.3
Expand All @@ -61,23 +61,23 @@ pre-commit==2.19.0
psycopg2-binary==2.9.3
py==1.11.0
pycparser==2.21
pydantic==1.9.0
pylint==2.13.8
pydantic==1.9.1
pylint==2.13.9
pyparsing==3.0.9
pytest==7.1.2
pytest-cases==3.6.11
pytest-cases==3.6.13
pytest-freezegun==0.4.2
pytest-mock==3.7.0
pytest-pycharm==0.7.0
pytest-responses==0.5.0
python-dateutil==2.8.2
python-dotenv==0.20.0
python-magic==0.4.25
python-magic==0.4.26
python-multipart==0.0.5
pytz==2022.1
PyYAML==6.0
requests==2.27.1
responses==0.20.0
responses==0.21.0
s3transfer==0.5.2
sentry-sdk==1.5.12
six==1.16.0
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# File generated automatically. Do not update it manually.
# Update files in the requirements folder instead.
alembic==1.7.7
anyio==3.5.0
asgiref==3.5.1
boto3==1.22.11
botocore==1.25.11
certifi==2021.10.8
anyio==3.6.1
asgiref==3.5.2
boto3==1.23.10
botocore==1.26.10
certifi==2022.5.18.1
charset-normalizer==2.0.12
click==8.1.3
content-size-limit-asgi==0.1.5
dependency-injector==4.39.1
fastapi==0.77.1
fastapi==0.78.0
funcy==1.17
greenlet==1.1.2
gunicorn==20.1.0
Expand All @@ -19,19 +19,19 @@ idna==3.3
jmespath==1.0.0
Mako==1.2.0
MarkupSafe==2.1.1
marshmallow==3.15.0
marshmallow==3.16.0
marshmallow-dataclass==8.5.3
marshmallow-enum==1.5.1
more-itertools==8.13.0
mypy-extensions==0.4.3
packaging==21.3
pika==1.2.1
psycopg2-binary==2.9.3
pydantic==1.9.0
pydantic==1.9.1
pyparsing==3.0.9
python-dateutil==2.8.2
python-dotenv==0.20.0
python-magic==0.4.25
python-magic==0.4.26
python-multipart==0.0.5
requests==2.27.1
s3transfer==0.5.2
Expand Down
12 changes: 7 additions & 5 deletions tests/api/namespace/use_case/test_clone_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tests.factories.use_case_factory import UseCaseFactory
from tests.factories.use_case_version_factory import UseCaseVersionFactory
from tests.factories.variable_factory import VariableFactory
from use_case_executor.adapters.database_repository.models import UseCaseVersion
from use_case_executor.adapters.database_repository.models.use_case import UseCase
from use_case_executor.adapters.database_repository.models.variable import Variable
from use_case_executor.domain.flow.edge_data.quick_reply_data import QuickReplyData
Expand Down Expand Up @@ -260,14 +261,13 @@ def test_clone_use_case_on_a_use_case_with_production_only_setting(
assert new_use_case.service_record_id == payload["service_record_id"]
assert new_use_case.intent_record_id == payload["intent_record_id"]

assert new_use_case.production_version_id is None
if has_production_flow:
assert len(new_use_case.versions) == 1
version = new_use_case.versions[0]
assert new_use_case.production_version_id == version.id
assert version.flow == prod_version.flow
else:
assert len(new_use_case.versions) == 0
assert new_use_case.production_version_id is None

assert response.json() == {
"instance_id": payload["instance_id"],
Expand Down Expand Up @@ -538,10 +538,12 @@ def test_creates_new_variables_if_cloning_to_other_instance( # pylint: disable=
assert new_variable.name == variable.name
assert new_variable.type == variable.type

new_use_case = session.query(UseCase).filter(UseCase.uuid != use_case.uuid).one()
new_flow = common.dict_flow_to_domain_flow(
flow=new_use_case.production_version.flow
new_use_case_version = (
session.query(UseCaseVersion)
.filter(UseCaseVersion.use_case_uuid != use_case.uuid)
.one()
)
new_flow = common.dict_flow_to_domain_flow(flow=new_use_case_version.flow)

new_answer_node_data = new_flow.get_node(uuid=answer_node_uuid).data
assert isinstance(new_answer_node_data, AnswerData)
Expand Down
6 changes: 0 additions & 6 deletions use_case_executor/api/namespaces/use_cases/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ def clone_use_case(
service_record_id=clone_use_case_model_in.service_record_id,
intent_record_id=clone_use_case_model_in.intent_record_id,
flow=flow_to_clone,
set_new_version_as_production=(
clone_behavior == CloneBehavior.PRODUCTION_FLOW_ONLY
),
clone_variables=(clone_use_case_model_in.instance_id != use_case.instance_id),
)
session.commit()
Expand Down Expand Up @@ -90,9 +87,6 @@ def clone_use_case_as_main_menu(
service_record_id=clone_use_case_as_main_menu_model_in.service_record_id,
intent_record_id=clone_use_case_as_main_menu_model_in.intent_record_id,
flow=flow_to_clone,
set_new_version_as_production=(
clone_behavior == CloneBehavior.PRODUCTION_FLOW_ONLY
),
clone_variables=False,
)
session.commit()
Expand Down
4 changes: 0 additions & 4 deletions use_case_executor/api/namespaces/use_cases/clone_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def create_new_use_case_and_version(
intent_record_id: int,
service_record_id: int,
flow: Optional[dict],
set_new_version_as_production: bool,
clone_variables: bool,
) -> UseCase:
new_use_case = UseCase(
Expand All @@ -75,9 +74,6 @@ def create_new_use_case_and_version(
)
new_use_case.versions.append(new_version)

if set_new_version_as_production:
new_use_case.production_version = new_version

with helpers.handle_use_case_unique_violations():
session.flush()

Expand Down

0 comments on commit c00c11d

Please sign in to comment.