diff --git a/tests/conftest.py b/tests/conftest.py index 947bdaf79b1a..9f36dc7b37fa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -62,6 +62,7 @@ ReportFactory, SearchFilterFactory, ServiceFactory, + ServiceFeedbackFactory, SignalFactory, SignalFilterFactory, SignalInstanceFactory, @@ -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() diff --git a/tests/factories.py b/tests/factories.py index 7ffbfc9815b3..eb225343be60 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -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 @@ -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 diff --git a/tests/feedback/test_feedback_oncall.py b/tests/feedback/test_feedback_oncall.py new file mode 100644 index 000000000000..fd0cc9ae3efd --- /dev/null +++ b/tests/feedback/test_feedback_oncall.py @@ -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)