Skip to content

Expand unit tests for services.py using mocks #66

@AuraMindNest

Description

@AuraMindNest

Problem

boost_weblate/endpoint/services.py mixes pure helpers with Weblate ORM usage, filesystem scanning, and git/subprocess calls, so it was hard to cover under the global coverage gate without a large test suite. Coverage was configured to omit that file entirely, which hid regressions in core sync logic.

Acceptance Criteria

  • Unit tests exercise pure helpers (_submodule_slug, truncate_component_name, truncate_component_slug, _build_extension_to_format with patched FILE_FORMATS).
  • Unit tests exercise BoostComponentService behaviour using mocks for subprocess.run, Weblate models (Project, Component, Language), transaction, and filesystem/OS helpers where needed, including success and failure paths (timeouts, permission checks, missing configs, git errors).
  • scan_documentation_files is covered using real temporary directories for realistic layout cases.
  • High-level flows process_submodule and process_all are covered by patching inner service methods and asserting structured success/error results.
  • Coverage collection includes endpoint/services.py (the dedicated omit entry for that path is removed from pyproject.toml).

Implementation Notes

  • Prefer unittest.mock.patch / MagicMock at the import site used by services (e.g. boost_weblate.endpoint.services.subprocess.run) so behaviour under test matches production call paths.
  • Use a small factory (_make_svc) to construct BoostComponentService with defaults and override only fields relevant to each test class.
  • ORM-heavy paths avoid a live database by stubbing objects.get_or_create, filter, get, and component methods such as create_translations_immediate and add_new_language.

References

  • pyproject.toml
  • tests/endpoint/test_services.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