Skip to content

Tests — HTTP Endpoint Tests #46

@whisper67265

Description

@whisper67265

Problem

The boost endpoint's HTTP layer (views, URL routing, authentication) has no test coverage. Without tests, regressions in input validation, auth enforcement, or response shapes will go undetected. A comprehensive HTTP test suite is needed that exercises the DRF views through Django's test client, covering happy paths, validation failures, and authentication edge cases.

Acceptance Criteria

  • GET /info/ returns 200 with JSON containing name, version, and capabilities keys
  • POST /add-or-update/ with missing required fields returns 400 with a structured error body listing the missing fields
  • POST /add-or-update/ with invalid field types (e.g., languages as a string instead of a list) returns 400
  • POST /add-or-update/ with valid payload and valid authentication returns 202 with a JSON body containing task_id
  • The task_id in the 202 response is a valid UUID string
  • Unauthenticated POST /add-or-update/ returns 401 or 403
  • Authentication with an invalid token returns 401 or 403
  • The Celery task is enqueued (mocked) with the correct arguments on a successful POST
  • Tests use APITestCase or Django's TestCase with self.client and do not require a running Celery worker

Implementation Notes

Use unittest.mock.patch to mock tasks.add_or_update.delay and assert it was called with the expected arguments. Use DRF's APIClient with credentials() for auth tests. Create a test user with User.objects.create_user() in setUp. The tests should be in tests/test_views.py or tests/endpoints/test_http.py, consistent with the existing test layout. Use @override_settings(CELERY_TASK_ALWAYS_EAGER=True) only if testing task execution end-to-end in a separate suite, not here.

References

  • Related files: tests/test_views.py (or tests/endpoints/test_http.py), src/boost_weblate/views.py, src/boost_weblate/urls.py
  • Depends on: views.py, urls.py, tasks.py

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions