Project

General

Profile

Actions

Feature #132

open

API Tests - use the entity factory

Added by Sam Pearson 3 months ago. Updated 23 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
04/06/2026
Due date:
% Done:

0%

Estimated time:
Engineering Effort:
x-large
App Component:
API Testing
Feature:

Description

I've created an entity factory that allows the creation of tasks, projects, etc with simple functions, like so:

def create_task(auth_client, **kwargs):
    """Helper to create a task with custom properties"""
    payload = {
        "title": kwargs.get("title", "Sample Task"),
        "description": kwargs.get("description", ""),
        "status": kwargs.get("status", "open"),
    }

    with allure.step(f"Create task: {payload['title']}"):
        response = auth_client.post('/api/tasks', json=payload)
        assert response.status_code == 201, f"Failed to create task: {response.text}"
        task = response.json()

    return task


def create_project(auth_client, **kwargs):
    """Helper to create a project with custom properties"""
    payload = {
        "title": kwargs.get("title", "Test Project"),
        "description": kwargs.get("description", ""),
        "win_condition": kwargs.get("win_condition", ""),
        "reason": kwargs.get("reason", ""),
        "next_step": kwargs.get("next_step", ""),
    }

    with allure.step(f"Create project: {payload['title']}"):
        response = auth_client.post('/api/projects', json=payload)
        assert response.status_code == 201, f"Failed to create project: {response.text}"
        project = response.json()

    return project

This is the right way to create entities when the test just needs a thing to exist. Like if you just need a project to exist in order to attach a task to it, this is the right way to create that project.

It may actually be useful to create all entities like this, the use of kwargs lets you do whatever you want, and the function includes the boilerplate of checking for a 201 and such, so consider using it all over the place. Both to reduce boilerplate and to provide a single place to change test code if implementation changes.

Actions #1

Updated by Sam Pearson 3 months ago

  • Subject changed from use the entity factory to API Tests - use the entity factory
Actions #2

Updated by Sam Pearson 23 days ago

  • Engineering Effort set to x-large
  • App Component set to API Testing

XL - this is definitely going to spiral into a lot of work, as it touches all features

Actions

Also available in: Atom PDF