# Path: yithlibraryserver/errors.py
# def password_not_found(msg='Password not found'):
#     return HTTPNotFound(body=json.dumps({'message': msg}),
#                         content_type='application/json')
# 
# def invalid_password_id(msg='Invalid password id'):
#     return HTTPBadRequest(body=json.dumps({'message': msg}),
#                           content_type='application/json')


import unittest
from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound
from yithlibraryserver.errors import password_not_found, invalid_password_id
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.






class ErrorsTests(unittest.TestCase):

    def test_password_not_found(self):
        result = password_not_found()
        self.assertTrue(isinstance(result, HTTPNotFound))
        self.assertTrue(result.content_type, 'application/json')
        self.assertTrue(result.body, '{"message": "Password not found"}')

        # try a different message
        result = password_not_found('test')
        self.assertTrue(result.body, '{"message": "test"}')


    def test_invalid_password_id(self):
        result = invalid_password_id()
        self.assertTrue(isinstance(result, HTTPBadRequest))
        self.assertTrue(result.content_type, 'application/json')
        self.assertTrue(result.body, '{"message": "Invalid password id"}')

        # try a different message

# Path: yithlibraryserver/errors.py
# def password_not_found(msg='Password not found'):
#     return HTTPNotFound(body=json.dumps({'message': msg}),
#                         content_type='application/json')
# 
# def invalid_password_id(msg='Invalid password id'):
#     return HTTPBadRequest(body=json.dumps({'message': msg}),
#                           content_type='application/json')


# Path: yithlibraryserver/tests/test_errors.py
import unittest
from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound
from yithlibraryserver.errors import password_not_found, invalid_password_id

# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.






class ErrorsTests(unittest.TestCase):

    def test_password_not_found(self):
        result = password_not_found()
        self.assertTrue(isinstance(result, HTTPNotFound))
        self.assertTrue(result.content_type, 'application/json')
        self.assertTrue(result.body, '{"message": "Password not found"}')

        # try a different message
        result = password_not_found('test')
        self.assertTrue(result.body, '{"message": "test"}')


    def test_invalid_password_id(self):
        result = invalid_password_id()
        self.assertTrue(isinstance(result, HTTPBadRequest))
        self.assertTrue(result.content_type, 'application/json')
        self.assertTrue(result.body, '{"message": "Invalid password id"}')

        # try a different message

        result = invalid_password_id('test')