Ejemplo n.º 1
0
def query():
    request_object = r_E_uc.EventListRequestObject.from_dict({})

    repo = gr.GithubRepo()
    use_case = E_uc.EventListUseCase(repo)

    response = use_case.execute(request_object)

    return Response(json.dumps(response.value),
                    mimetype='application/json',
                    status=200)
    def test_event_list_without_parameters(self):
        repo = mock.Mock()
        repo.list.return_value = self.domain_events

        event_list_use_case = uc.EventListUseCase(repo)
        request_object = req.EventListRequestObject.from_dict({})

        respose_object = event_list_use_case.execute(request_object)

        self.assertTrue(bool(respose_object))
        repo.list.assert_called_with(filters=None)

        self.assertEqual(respose_object.value, self.domain_events)
    def test_event_list_handles_bad_request(self):
        repo = mock.Mock()

        event_list_use_case = uc.EventListUseCase(repo)
        request_object = req.EventListRequestObject.from_dict({'filters': 5})

        response_object = event_list_use_case.execute(request_object)

        self.assertFalse(bool(response_object))
        self.assertEqual(
            response_object.value, {
                'type': res.ResponseFailure.PARAMETERS_ERROR,
                'message': "filters: Is not iterable"
            })
    def test_event_list_with_filters(self):
        repo = mock.Mock()
        repo.list.return_value = self.domain_events

        event_list_use_case = uc.EventListUseCase(repo)
        qry_filters = {'a': 5}
        request_object = req.EventListRequestObject.from_dict(
            {'filters': qry_filters})

        response_object = event_list_use_case.execute(request_object)

        self.assertTrue(bool(response_object))
        repo.list.assert_called_with(filters=qry_filters)
        self.assertEqual(response_object.value, self.domain_events)
    def test_event_list_handles_generic_error(self):
        repo = mock.Mock()
        repo.list.side_effect = Exception('Just an error message')

        event_list_use_case = uc.EventListUseCase(repo)
        request_object = req.EventListRequestObject.from_dict({})

        response_object = event_list_use_case.execute(request_object)

        self.assertFalse(bool(response_object))
        self.assertEqual(
            response_object.value, {
                'type': res.ResponseFailure.SYSTEM_ERROR,
                'message': "Exception: Just an error message"
            })