def test_do_POST_process(self) -> None:
"""Test POST /process and its effect on the database."""
self.assertEqual(0, len(Process.all(self.db_conn)))
- form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.1}
- self.check_post(form_data, '/process?id=', 302, '/process?id=1')
+ form_data = self.post_process()
self.assertEqual(1, len(Process.all(self.db_conn)))
self.check_post(form_data, '/process?id=FOO', 400)
form_data['effort'] = 'foo'
self.assertEqual(1, len(Process.all(self.db_conn)))
form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.0,
'condition': []}
- self.check_post(form_data, '/process?id=', 302, '/process?id=2')
+ self.post_process(2, form_data)
form_data['condition'] = [1]
self.check_post(form_data, '/process?id=', 404)
form_data_cond = {'title': 'foo', 'description': 'foo'}
self.check_post(form_data_cond, '/condition', 302, '/condition?id=1')
- self.check_post(form_data, '/process?id=', 302, '/process?id=3')
+ self.post_process(3, form_data)
form_data['disables'] = [1]
- self.check_post(form_data, '/process?id=', 302, '/process?id=4')
+ self.post_process(4, form_data)
form_data['enables'] = [1]
- self.check_post(form_data, '/process?id=', 302, '/process?id=5')
+ self.post_process(5, form_data)
form_data['delete'] = ''
self.check_post(form_data, '/process?id=', 404)
self.check_post(form_data, '/process?id=6', 404)
def test_do_GET(self) -> None:
"""Test /process and /processes response codes."""
- form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.1}
- self.check_post(form_data, '/process?id=', 302, '/process?id=1')
+ self.post_process()
self.check_get_defaults('/process')
self.check_get('/processes', 200)
def test_do_POST_day(self) -> None:
"""Test Todo posting of POST /day."""
- form_data = {'title': '', 'description': '', 'effort': 1}
- self.check_post(form_data, '/process?id=', 302, '/process?id=1')
- self.check_post(form_data, '/process?id=', 302, '/process?id=2')
+ self.post_process()
+ self.post_process(2)
proc = Process.by_id(self.db_conn, 1)
proc2 = Process.by_id(self.db_conn, 2)
form_data = {'comment': ''}
self.check_post(form_data, '/todo?id=1', status, redir_url)
return Todo.by_date(self.db_conn, '2024-01-01')[0]
# test minimum
- form_data = {'title': '', 'description': '', 'effort': 1}
- self.check_post(form_data, '/process', 302, '/process?id=1')
+ self.post_process()
form_data = {'comment': '', 'new_todo': 1}
self.check_post(form_data, '/day?date=2024-01-01', 302)
# test posting to bad URLs
def test_do_POST_day_todo_adoption(self) -> None:
"""Test Todos posted to Day view may adopt existing Todos."""
- form_data = {'title': '', 'description': '', 'effort': 1}
- self.check_post(form_data, '/process', 302, '/process?id=1')
+ form_data = self.post_process()
form_data['new_top_step'] = 1
- self.check_post(form_data, '/process', 302, '/process?id=2')
+ form_data = self.post_process(2, form_data)
form_data = {'comment': '', 'new_todo': 1}
self.check_post(form_data, '/day?date=2024-01-01', 302)
form_data = {'comment': '', 'new_todo': 2}
def test_do_GET_todo(self) -> None:
"""Test GET /todo response codes."""
- form_data = {'title': '', 'description': '', 'effort': 1}
- self.check_post(form_data, '/process?id=', 302, '/process?id=1')
+ self.post_process()
form_data = {'comment': '', 'new_todo': 1}
self.check_post(form_data, '/day?date=2024-01-01', 302)
self.check_get('/todo', 400)
from urllib.parse import urlencode
from datetime import datetime
from os import remove as remove_file
-from typing import Mapping
+from typing import Mapping, Any
from plomtask.db import DatabaseFile, DatabaseConnection
from plomtask.http import TaskHandler, TaskServer
from plomtask.processes import Process, ProcessStep
self.check_get(f'{path}?id=foo', 400)
self.check_get(f'/{path}?id=0', 500)
self.check_get(f'{path}?id=1', 200)
+
+ def post_process(self, id_: int = 1,
+ form_data: dict[str, Any] | None = None
+ ) -> dict[str, Any]:
+ """POST basic Process."""
+ if not form_data:
+ form_data = {'title': 'foo', 'description': 'foo', 'effort': 1.1}
+ self.check_post(form_data, '/process?id=', 302, f'/process?id={id_}')
+ return form_data