Skip to content

Conversation

@tyraziel
Copy link
Contributor

@tyraziel tyraziel commented Sep 29, 2025

SUMMARY

Introduces settings_for_isolated_testing.py to provide a self-contained test environment for awx testing.

Key Features:

  • SQLite database configuration for faster, isolated test runs
  • ServiceID mocking infrastructure to prevent UUID validation errors
  • Resource server sync disabling to avoid authentication errors in tests
  • Memory-based caching for test isolation

Testing Infrastructure Patterns:

  • Sample mock_dab_service_id() fixture for ServiceID.objects.first() calls
  • MOCK_DAB_SERVICE_ID setting to enable/disable mocking conditionally
  • RESOURCE_SERVER = {} configuration to disable external sync during testing
  • Comprehensive documentation for reuse in future DAB-related testing

This testing foundation enables reliable unit and integration testing
of django-ansible-base components without requiring external PostgreSQL
databases or live service dependencies.

Usage: pytest --ds=awx.main.tests.settings_for_isolated_testing

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • Other

🤖 Generated with Claude Code

Vibe-Coder: Andrew Potozniak [email protected]
Co-Authored-By: Claude [email protected]

  Introduces settings_for_isolated_testing.py to provide a self-contained
  test environment for awx testing.

  Key Features:
  - SQLite database configuration for faster, isolated test runs
  - ServiceID mocking infrastructure to prevent UUID validation errors
  - Resource server sync disabling to avoid authentication errors in tests
  - Memory-based caching for test isolation

  Testing Infrastructure Patterns:
  - Sample mock_dab_service_id() fixture for ServiceID.objects.first() calls
  - MOCK_DAB_SERVICE_ID setting to enable/disable mocking conditionally
  - RESOURCE_SERVER = {} configuration to disable external sync during testing
  - Comprehensive documentation for reuse in future DAB-related testing

  This testing foundation enables reliable unit and integration testing
  of django-ansible-base components without requiring external PostgreSQL
  databases or live service dependencies.

  Usage: pytest --ds=awx.main.tests.settings_for_isolated_testing

  🤖 Generated with [Claude Code](https://claude.ai/code)

  Vibe-Coder: Andrew Potozniak <[email protected]>
  Co-Authored-By: Claude <[email protected]>
@sonarqubecloud
Copy link

pytest --ds=awx.main.tests.settings_for_isolated_testing [test_file]

Enhanced Usage Notes:
1. ServiceID Mocking Pattern:
Copy link
Member

@chrismeyersfsu chrismeyersfsu Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this fixure in the comments. Why not include it in the PR? We aren't seeing tests fail in our CI because of ServiceID record not existing. Wondering why you are seeing it.

As I understand it a ServiceId record is supposed to be created via DAB migrations here https://github.com/ansible/django-ansible-base/blob/964c531cdb465ca9b0511ee75e2772bd3847ddc6/ansible_base/resource_registry/migrations/0001_initial.py#L31

@chrismeyersfsu
Copy link
Member

This file is very close to being a duplicate of https://github.com/ansible/awx/blob/devel/awx/main/tests/settings_for_test.py

It looks like the main difference is RESOURCE_SERVER = {} and the ServiceId mock autouse. We can incorporate the RESOURCE_SERVER = {} into settings_for_test.py and I'm not sure the ServiceId mock is needed because tests are passing in our CI without it. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants