Commit aad20b0a authored by Karagkounis Dimitris's avatar Karagkounis Dimitris
Browse files

allow tox to use exported env variables

parent 94cbd489
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,20 @@ jobs:
      - name: Install tox
      - name: Install tox
        run: pip install tox
        run: pip install tox


      - name: Wait for MongoDB to be ready
        run: |
          for i in {30..0}; do
            if mongo --host localhost --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
              echo "MongoDB is up and running"
              break
            fi
            echo 'MongoDB is unavailable - sleeping'
            sleep 1
          done
        env:
          MONGO_URI: "mongodb://test_admin:test_password@localhost:27017/test_db?authSource=admin"


      - name: Run tox for python 3.12 - tests only
      - name: Run tox for python 3.12 - tests only
        env:
        env:
          MONGO_URI: "mongodb://test_admin:test_password@localhost:27017/test_db?authSource=admin"
          MONGO_URI: "mongodb://test_admin:test_password@localhost:27017/test_db?authSource=admin"
+3 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,9 @@ class MongoManager:
        """
        """
        Initializes the MongoDB connection using the URI from Config.
        Initializes the MongoDB connection using the URI from Config.
        """
        """
        if not mongo_uri:
            raise ValueError("MONGO_URI is not set in the environment configuration.")

        self.client = MongoClient(mongo_uri, maxPoolSize=50)
        self.client = MongoClient(mongo_uri, maxPoolSize=50)
        mongo_db_name: str = mongo_uri.split("/")[-1].split("?")[0]
        mongo_db_name: str = mongo_uri.split("/")[-1].split("?")[0]
        self.db = self.client[mongo_db_name]
        self.db = self.client[mongo_db_name]
+3 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,9 @@ def mongo_load_apps_collection_data():
    """Fixture to insert specific test data into a MongoDB collection before running app controllers tests."""
    """Fixture to insert specific test data into a MongoDB collection before running app controllers tests."""
    from edge_cloud_management_api.configs.env_config import config
    from edge_cloud_management_api.configs.env_config import config


    if not config.MONGO_URI:
        raise ValueError("MONGO_URI is not set in the environment configuration.")

    # rely on the loaded environmental variables to maintain consistency across app and tests
    # rely on the loaded environmental variables to maintain consistency across app and tests
    client = pymongo.MongoClient(config.MONGO_URI)
    client = pymongo.MongoClient(config.MONGO_URI)
    db_name: str = config.MONGO_URI.split("/")[-1].split("?")[0]
    db_name: str = config.MONGO_URI.split("/")[-1].split("?")[0]
+1 −0
Original line number Original line Diff line number Diff line
@@ -6,6 +6,7 @@ skip_missing_interpreters = true


[testenv]
[testenv]
description = run the tests with pytest
description = run the tests with pytest
passenv = MONGO_URI
package = wheel
package = wheel
wheel_build_env = .pkg
wheel_build_env = .pkg
deps =
deps =