File: test_exceptions.py

package info (click to toggle)
flask-api 0.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 316 kB
  • ctags: 329
  • sloc: python: 1,284; sh: 21; makefile: 10
file content (26 lines) | stat: -rw-r--r-- 830 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# coding: utf8
from __future__ import unicode_literals
from flask_api import exceptions
from flask_api import status
import unittest


class Conflict(exceptions.APIException):
    status_code = status.HTTP_409_CONFLICT
    detail = 'Could not update the resource'


class TestExceptions(unittest.TestCase):
    def test_custom_exception(self):
        try:
            raise Conflict()
        except Conflict as exc:
            self.assertEqual(str(exc), 'Could not update the resource')
            self.assertEqual(exc.status_code, 409)

    def test_override_exception_detail(self):
        try:
            raise Conflict('A widget with this id already exists')
        except Conflict as exc:
            self.assertEqual(str(exc), 'A widget with this id already exists')
            self.assertEqual(exc.status_code, 409)