Skip to content

Commit

Permalink
Adding more signal tests (#3175)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss authored Mar 28, 2023
1 parent 7e1fcb9 commit 24d6b05
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/dispatch/signal/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ def signal_instance_create_flow(
if signal_instance.signal.conversation_target:
conversation_target = signal_instance.signal.conversation_target

return case_flows.case_new_create_flow(
case_flows.case_new_create_flow(
db_session=db_session,
organization_slug=None,
service_id=service_id,
conversation_target=conversation_target,
case_id=case.id,
)

return signal_instance


def create_signal_instance(
db_session: SessionLocal,
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ def plugin_instance(session):
return PluginInstanceFactory()


@pytest.fixture
def conversation_plugin_instance(session, conversation_plugin):
return PluginInstanceFactory(plugin=PluginFactory(slug=conversation_plugin.slug))


@pytest.fixture
def workflow_plugin_instance(session, workflow_plugin):
return PluginInstanceFactory(plugin=PluginFactory(slug=workflow_plugin.slug))
Expand Down
2 changes: 1 addition & 1 deletion tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ class Meta:
class PluginInstanceFactory(BaseFactory):
"""PluginInstance Factory."""

enabled = Faker().pybool()
enabled = True
project = SubFactory(ProjectFactory)
plugin = SubFactory(PluginFactory)

Expand Down
42 changes: 42 additions & 0 deletions tests/signal/test_signal_flow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest


def test_create_signal_instance(session, signal, case_severity, case_priority, user):
from dispatch.signal.flows import create_signal_instance

Expand All @@ -15,3 +18,42 @@ def test_create_signal_instance(session, signal, case_severity, case_priority, u
signal_instance_data=instance_data,
current_user=user,
)


def test_create_signal_instance_no_variant(session, signal, case_severity, case_priority, user):
from dispatch.signal.flows import create_signal_instance

case_priority.default = True
case_priority.project_id = signal.project_id

case_severity.default = True
case_severity.project_id = signal.project_id

instance_data = {"variant": "unknown"}
with pytest.raises(Exception):
create_signal_instance(
db_session=session,
project=signal.project,
signal_instance_data=instance_data,
current_user=user,
)


def test_create_signal_instance_not_enabled(session, signal, case_severity, case_priority, user):
from dispatch.signal.flows import create_signal_instance

case_priority.default = True
case_priority.project_id = signal.project_id

case_severity.default = True
case_severity.project_id = signal.project_id

signal.enabled = False
instance_data = {"variant": signal.variant}
with pytest.raises(Exception):
create_signal_instance(
db_session=session,
project=signal.project,
signal_instance_data=instance_data,
current_user=user,
)

0 comments on commit 24d6b05

Please sign in to comment.