from sqlite3 import Row
from datetime import datetime
from plomtask.db import DatabaseConnection
-from plomtask.exceptions import NotFoundException
+from plomtask.exceptions import NotFoundException, BadFormatException
class Process:
"""Template for, and metadata for, Todos, and their arrangements."""
def __init__(self, id_: int | None) -> None:
- self.id_ = id_ if id_ != 0 else None # to avoid DB-confusing rowid=0
+ if (id_ is not None) and id_ < 1:
+ raise BadFormatException(f'illegal Process ID, must be >=1: {id_}')
+ self.id_ = id_
self.title = VersionedAttribute(self, 'title', 'UNNAMED')
self.description = VersionedAttribute(self, 'description', '')
self.effort = VersionedAttribute(self, 'effort', 1.0)
from urllib.parse import urlencode
from tests.utils import TestCaseWithDB, TestCaseWithServer
from plomtask.processes import Process
-from plomtask.exceptions import NotFoundException
+from plomtask.exceptions import NotFoundException, BadFormatException
class TestsSansDB(TestCase):
p_saved.save(self.db_conn)
self.assertEqual(p_saved.id_,
Process.by_id(self.db_conn, 1, create=False).id_)
- p_saved = Process(0)
- p_saved.save(self.db_conn)
- self.assertEqual(p_saved.id_,
- Process.by_id(self.db_conn, 2, create=False).id_)
+ with self.assertRaises(BadFormatException):
+ p_saved = Process(0)
p_saved = Process(5)
p_saved.save(self.db_conn)
self.assertEqual(p_saved.id_,
Process.by_id(self.db_conn, 1, create=False)
self.assertNotEqual(Process(1).id_,
Process.by_id(self.db_conn, None, create=True).id_)
- self.assertNotEqual(Process(1).id_,
- Process.by_id(self.db_conn, 0, create=True).id_)
self.assertEqual(Process(1).id_,
Process.by_id(self.db_conn, 1, create=True).id_)
self.assertEqual(Process(2).id_,
self.conn.request('GET', '/process?id=')
self.assertEqual(self.conn.getresponse().status, 200)
self.conn.request('GET', '/process?id=0')
- self.assertEqual(self.conn.getresponse().status, 200)
+ self.assertEqual(self.conn.getresponse().status, 400)
self.conn.request('GET', '/process?id=FOO')
self.assertEqual(self.conn.getresponse().status, 400)
self.conn.request('GET', '/processes')