Skip to content

Commit

Permalink
test(service_feedback): adding tests for oncall service feedback (#5386)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Oct 26, 2024
1 parent f2a1493 commit 183eee4
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
ReportFactory,
SearchFilterFactory,
ServiceFactory,
ServiceFeedbackFactory,
SignalFactory,
SignalFilterFactory,
SignalInstanceFactory,
Expand Down Expand Up @@ -669,3 +670,8 @@ def cost_model(session):
@pytest.fixture
def cost_model_activity(session):
return CostModelActivityFactory()


@pytest.fixture
def service_feedback(session):
return ServiceFeedbackFactory()
33 changes: 33 additions & 0 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
from dispatch.route.models import Recommendation, RecommendationMatch
from dispatch.search_filter.models import SearchFilter
from dispatch.service.models import Service
from dispatch.feedback.service.models import ServiceFeedback
from dispatch.feedback.service.enums import ServiceFeedbackRating
from dispatch.signal.models import Signal, SignalFilter, SignalInstance
from dispatch.storage.models import Storage
from dispatch.tag.models import Tag
Expand Down Expand Up @@ -1450,3 +1452,34 @@ def creator(self, create, extracted, **kwargs):

if extracted:
self.creator_id = extracted.id


class ServiceFeedbackFactory(BaseFactory):
"""Service Feedback Factory."""

rating = FuzzyChoice(
[
ServiceFeedbackRating.no_effort,
ServiceFeedbackRating.little_effort,
ServiceFeedbackRating.moderate_effort,
ServiceFeedbackRating.lots_of_effort,
ServiceFeedbackRating.very_high_effort,
ServiceFeedbackRating.extreme_effort,
]
)
feedback = FuzzyText()
hours = FuzzyInteger(low=0, high=100)
project = SubFactory(ProjectFactory)

class Meta:
"""Factory Configuration."""

model = ServiceFeedback

@post_generation
def individual(self, create, extracted, **kwargs):
if not create:
return

if extracted:
self.individual_id = extracted.id
47 changes: 47 additions & 0 deletions tests/feedback/test_feedback_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
def test_create(session, case, case_type, case_priority):
from dispatch.feedback.incident.service import create
from dispatch.feedback.incident.models import FeedbackCreate

case.incident_type = case_type
case.incident_priority = case_priority
rating = "Neither satisfied nor dissatisfied"
feedback = "The incident commander did an excellent job"

feedback_in = FeedbackCreate(rating=rating, feedback=feedback, case=case)
feedback = create(db_session=session, feedback_in=feedback_in)
assert feedback


def test_get(session, feedback):
from dispatch.feedback.incident.service import get

t_feedback = get(db_session=session, feedback_id=feedback.id)
assert t_feedback.id == feedback.id


def test_get_all(session, feedbacks):
from dispatch.feedback.incident.service import get_all

t_feedbacks = get_all(db_session=session).all()
assert t_feedbacks


def test_update(session, feedback):
from dispatch.feedback.incident.service import update
from dispatch.feedback.incident.models import FeedbackUpdate

rating = "Very satisfied"
feedback_text = "The incident commander did an excellent job"

feedback_in = FeedbackUpdate(rating=rating, feedback=feedback_text)
feedback = update(db_session=session, feedback=feedback, feedback_in=feedback_in)

assert feedback.rating == rating
assert feedback.feedback == feedback_text


def test_delete(session, feedback):
from dispatch.feedback.incident.service import delete, get

delete(db_session=session, feedback_id=feedback.id)
assert not get(db_session=session, feedback_id=feedback.id)
55 changes: 55 additions & 0 deletions tests/feedback/test_feedback_oncall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
""" Tests oncall service feedback """


def test_create(session, participant, project):
from dispatch.feedback.service.service import create
from dispatch.feedback.service.models import ServiceFeedbackCreate

feedback = "Not a difficult shift"
hours = 5
rating = "No effort"

feedback_in = ServiceFeedbackCreate(
individual=participant.individual,
rating=rating,
feedback=feedback,
hours=hours,
project=project,
)
feedback = create(db_session=session, service_feedback_in=feedback_in)
assert feedback


def test_get(session, service_feedback):
from dispatch.feedback.service.service import get

t_feedback = get(db_session=session, service_feedback_id=service_feedback.id)
assert t_feedback.id == service_feedback.id


def test_get_all(session):
from dispatch.feedback.service.service import get_all

t_feedbacks = get_all(db_session=session).all()
assert t_feedbacks


def test_update(session, service_feedback):
from dispatch.feedback.service.service import update
from dispatch.feedback.service.models import ServiceFeedbackUpdate

feedback_text = "Changed my mind. The shift was difficult"

feedback_in = ServiceFeedbackUpdate(id=service_feedback.id, feedback=feedback_text)
feedback = update(
db_session=session, service_feedback=service_feedback, service_feedback_in=feedback_in
)

assert feedback.feedback == feedback_text


def test_delete(session, service_feedback):
from dispatch.feedback.service.service import delete, get

delete(db_session=session, service_feedback_id=service_feedback.id)
assert not get(db_session=session, service_feedback_id=service_feedback.id)

0 comments on commit 183eee4

Please sign in to comment.