Ejemplo n.º 1
0
    def test_add_user_db_exception(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.json_body = {"id": "1", "first_name": "Ben",
                             "last_name": "Franklin", "email": "*****@*****.**"}
        user_service = UserServiceRest(None, request, dao=MagicMock)
        user_service._dao.add = MagicMock(side_effect=sqlite3.DatabaseError())

        with self.assertRaisesRegex(HTTPInternalServerError, r'Could not add'):
            user_service.add_user()
        user_service._dao.add.assert_called_with(ANY, ANY)
Ejemplo n.º 2
0
    def test_add_user_db_exception(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.json_body = {"id": "1", "first_name": "Ben",
                             "last_name": "Franklin", "email": "*****@*****.**"}
        user_service = UserServiceRest(None, request, dao=MagicMock)
        user_service._dao.add = MagicMock(side_effect=sqlite3.DatabaseError())

        with self.assertRaisesRegex(HTTPInternalServerError, r'Could not add'):
            user_service.add_user()
        user_service._dao.add.assert_called_with(ANY, ANY)
Ejemplo n.º 3
0
    def test_add_user_success(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.json_body = {"id": "1", "first_name": "Ben", "last_name": "Franklin", "email": "*****@*****.**"}
        user_service = UserServiceRest(None, request, dao=Mock)

        response = user_service.add_user()

        self.assertEqual(201, response.status_int)
Ejemplo n.º 4
0
    def test_add_user_db_exception(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.json_body = {"id": "1", "first_name": "Ben", "last_name": "Franklin", "email": "*****@*****.**"}
        user_service = UserServiceRest(None, request, dao=Mock)

        # TODO: note the mock DAO's add() method will raise a DatabaseError.
        # (no code change required)
        user_service._dao.add = Mock(side_effect=sqlite3.DatabaseError())

        # TODO: assert that an HTTPInternalServerError is raised when you call
        # the user_service's add_user() method, and that the exception's
        # message includes the string 'Could not add'
        with self.assertRaisesRegex(HTTPInternalServerError, r"Could not add"):
            user_service.add_user()

        # Assert that the mock DAO's add() method was called once, with
        # any two arguments.
        user_service._dao.add.assert_called_once(ANY, ANY)
Ejemplo n.º 5
0
    def test_add_user_success(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.json_body = {"id": "1", "first_name": "Ben",
                             "last_name": "Franklin", "email": "*****@*****.**"}
        user_service = UserServiceRest(None, request, dao=Mock)

        response = user_service.add_user()

        self.assertEqual(201, response.status_int)
Ejemplo n.º 6
0
    def test_add_user_db_exception(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.json_body = {
            "id": "1",
            "first_name": "Ben",
            "last_name": "Franklin",
            "email": "*****@*****.**"
        }
        user_service = UserServiceRest(None, request, dao=Mock)

        # TODO: note the mock DAO's add() method will raise a DatabaseError.
        # (no code change required)
        user_service._dao.add = Mock(side_effect=sqlite3.DatabaseError())

        # TODO: assert that an HTTPInternalServerError is raised when you call
        # the user_service's add_user() method, and that the exception's
        # message includes the string 'Could not add'
        with self.assertRaisesRegex(HTTPInternalServerError, r'Could not add'):
            user_service.add_user()

        # Assert that the mock DAO's add() method was called once, with
        # any two arguments.
        user_service._dao.add.assert_called_once(ANY, ANY)