Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test(cv_deploy): Add support for offline testing of CVClient #4744

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

ClausHolbechArista
Copy link
Contributor

Change Summary

Add support for offline testing of CVClient

Proposed changes

  • Create a recorder for API requests coming from CVClient.
  • Create a mock class to play back the recorded responses.
  • Various mockery to make cvclient happy in offline state.

How to test

Added a pytest fixture which automatically serves the relevant type of CVClient:

@pytest_asyncio.fixture
async def cv_client() -> AsyncGenerator[CVClient, None]:
    """
    Instance of CVClient.

    If CVAAS_AAWG_CI environment variable is set, but RECORDING environment variable is not set,
    this will return a proper instance of CVClient connected to cv-staging with the token.

    If CVAAS_AAWG_CI environment variable is set, but RECORDING environment variable is set,
    this will return an instance of CVClient connected to cv-staging with the token where all API calls will be recorded.

    Otherwise this will return an instance of CVClient where API calls are mocked using previously recorded API messages.
    """

Checklist

User Checklist

  • N/A

Repository Checklist

  • My code has been rebased from devel before I start
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and documentation have been updated accordingly.
  • I have updated molecule CI testing accordingly. (check the box if not applicable)

Copy link

Review docs on Read the Docs

To test this pull request:

# Create virtual environment for this testing below the current directory
python -m venv test-avd-pr-4744
# Activate the virtual environment
source test-avd-pr-4744/bin/activate
# Install all requirements including PyAVD
pip install "pyavd[ansible] @ git+https://github.com/ClausHolbechArista/avd.git@test/cv_workspace/pytest-mock-cv-api#subdirectory=python-avd" --force
# Point Ansible collections path to the Python virtual environment
export ANSIBLE_COLLECTIONS_PATH=$VIRTUAL_ENV/ansible_collections
# Install Ansible collection
ansible-galaxy collection install git+https://github.com/ClausHolbechArista/avd.git#/ansible_collections/arista/avd/,test/cv_workspace/pytest-mock-cv-api --force
# Optional: Install AVD examples
cd test-avd-pr-4744
ansible-playbook arista.avd.install_examples

Copy link

sonarcloud bot commented Nov 19, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant