|
43 | 43 | from kleinkram.errors import MissionValidationError |
44 | 44 | from kleinkram.errors import ProjectExists |
45 | 45 | from kleinkram.errors import ProjectNotFound |
| 46 | +from kleinkram.errors import ProjectValidationError |
46 | 47 | from kleinkram.models import File |
47 | 48 | from kleinkram.models import Mission |
48 | 49 | from kleinkram.models import Project |
@@ -350,17 +351,30 @@ def _create_mission( |
350 | 351 | def _create_project( |
351 | 352 | client: AuthenticatedClient, project_name: str, description: str |
352 | 353 | ) -> UUID: |
353 | | - if not _project_name_is_available(client, project_name): |
354 | | - raise ProjectExists(f"Project with name: `{project_name}` already exists") |
355 | 354 |
|
356 | | - # TODO: check name and description are valid |
| 355 | + _validate_project_name(client, project_name, description) |
357 | 356 | payload = {"name": project_name, "description": description} |
358 | 357 | resp = client.post(CREATE_PROJECT, json=payload) |
359 | 358 | resp.raise_for_status() |
360 | 359 |
|
361 | 360 | return UUID(resp.json()["uuid"], version=4) |
362 | 361 |
|
363 | 362 |
|
| 363 | +def _validate_project_name( |
| 364 | + client: AuthenticatedClient, project_name: str, description: str |
| 365 | +) -> None: |
| 366 | + if not _project_name_is_available(client, project_name): |
| 367 | + raise ProjectExists(f"Project with name: `{project_name}` already exists") |
| 368 | + |
| 369 | + if project_name.endswith(" "): |
| 370 | + raise ProjectValidationError( |
| 371 | + f"Project name must not end with a tailing whitespace: `{project_name}`" |
| 372 | + ) |
| 373 | + |
| 374 | + if not description: |
| 375 | + raise ProjectValidationError("Project description is required") |
| 376 | + |
| 377 | + |
364 | 378 | def _validate_tag_value(tag_value, tag_datatype) -> None: |
365 | 379 | if tag_datatype == "NUMBER": |
366 | 380 | try: |
|
0 commit comments