import pytest
from .factory import BaseFactory,UserFactory,BlacklistFactory
from app import app,db
from app.config.settings import TestingConfig
from mongoengine import connect,disconnect
from flask_mongoengine import MongoEngine
from mongoengine.connection import _get_db


@pytest.fixture
def base_user_factory():
    """
    Fixture that return BaseFactory object
    """
    yield BaseFactory.create()


@pytest.fixture
def user_model_factory():
    """
    Fixture that return Userfactory object
    """
    yield UserFactory.create()

@pytest.fixture
def user_model_weak_pass():
    yield UserFactory.create(password="test123")

@pytest.fixture
def black_list_factory():
    yield BlacklistFactory.create()

@pytest.fixture
def user_model_login():
    return UserFactory.create(username="testlogin_user",email="test@test.com",password="(*&jhs11djHkjsd")

# @pytest.fixture
# def client():
#     """
#     pytest fixture thas change fask configuration for testing
#     """
#     app.create_app()
#     app.config.from_object(TestConfig)
#     with app.test_client() as client:
#         return client
    

@pytest.fixture
def client():
    disconnect()
    app.config.from_object(TestingConfig)  # Use the testing configuration

    # # Establish a connection to the testing database
    connection = connect('pige_testing', host='mongo-database', port=27017)
    
    with app.test_client() as client:
        yield client  # The tests will run using this client fixture
    connection.drop_database("pige_testing")
    # Clean up: Disconnect from the testing database and drop it
   