home · contact · privacy
Use different exceptions throwing different HTTP codes for different cases.
[plomtask] / tests / processes.py
index 17af14edfe5a6c5c773084ffe1c3a9df7f32b52e..399eb9dfc354e73db88858a16dc10178f2825297 100644 (file)
@@ -3,7 +3,7 @@ from unittest import TestCase
 from urllib.parse import urlencode
 from tests.utils import TestCaseWithDB, TestCaseWithServer
 from plomtask.processes import Process
-from plomtask.misc import HandledException
+from plomtask.exceptions import NotFoundException
 
 
 class TestsSansDB(TestCase):
@@ -42,11 +42,11 @@ class TestsWithDB(TestCaseWithDB):
 
     def test_Process_by_id(self) -> None:
         """Test Process.by_id()."""
-        with self.assertRaises(HandledException):
+        with self.assertRaises(NotFoundException):
             Process.by_id(self.db_conn, None, create=False)
-        with self.assertRaises(HandledException):
+        with self.assertRaises(NotFoundException):
             Process.by_id(self.db_conn, 0, create=False)
-        with self.assertRaises(HandledException):
+        with self.assertRaises(NotFoundException):
             Process.by_id(self.db_conn, 1, create=False)
         self.assertNotEqual(Process(1).id_,
                             Process.by_id(self.db_conn, None, create=True).id_)
@@ -81,11 +81,11 @@ class TestsWithServer(TestCaseWithServer):
                               body=encoded_form_data, headers=headers)
             self.assertEqual(self.conn.getresponse().status, expect)
         form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0}
-        post_data_to_expect(form_data, '/process?id=FOO', 400)
+        post_data_to_expect(form_data, '/process?id=FOO', 401)
         form_data['effort'] = 'foo'
-        post_data_to_expect(form_data, '/process?id=', 400)
+        post_data_to_expect(form_data, '/process?id=', 401)
         form_data['effort'] = None
-        post_data_to_expect(form_data, '/process?id=', 400)
+        post_data_to_expect(form_data, '/process?id=', 401)
         form_data = {'title': None, 'description': 1, 'effort': 1.0}
         post_data_to_expect(form_data, '/process?id=', 302)
         retrieved = Process.by_id(self.db_conn, 1)
@@ -102,6 +102,6 @@ class TestsWithServer(TestCaseWithServer):
         self.conn.request('GET', '/process?id=0')
         self.assertEqual(self.conn.getresponse().status, 200)
         self.conn.request('GET', '/process?id=FOO')
-        self.assertEqual(self.conn.getresponse().status, 400)
+        self.assertEqual(self.conn.getresponse().status, 401)
         self.conn.request('GET', '/processes')
         self.assertEqual(self.conn.getresponse().status, 200)