"""Conftest file for pytest.""" import pandas as pd import pytest @pytest.fixture def mock_environments(): """Mock environments data.""" return [ { 'id': '1', 'type': 'environment', 'name': 'Environment 1' }, { 'id': '2', 'type': 'environment', 'name': 'Environment 2' }, { 'id': '3', 'type': 'environment', 'name': 'Environment 3' } ] @pytest.fixture def mock_traffic_types(): """Mock traffic types data.""" return [ { 'id': '1', 'name': 'Traffic Type 1', 'type': 'traffic_type' }, { 'id': '2', 'name': 'Traffic Type 2', 'type': 'traffic_type' } ] @pytest.fixture def mock_groups(): """Mock groups data.""" return [ { 'accountIdentifier': '1', 'identifier': '1', 'name': 'Group 1', 'description': '', 'externallyManaged': False, 'harnessManaged': False, 'ssoLinked': False, }, { 'accountIdentifier': '2', 'identifier': '2', 'name': 'Group 2', 'description': '', 'externallyManaged': False, 'harnessManaged': False, 'ssoLinked': False, } ] @pytest.fixture def mock_users(): """Mock users data.""" return [ { 'uuid': '1', 'name': 'User 1', 'email': 'user1@example.com', 'locked': False, 'disabled': False, 'externallyManaged': False, 'twoFactorAuthenticationEnabled': True }, { 'uuid': '2', 'name': 'User 2', 'email': 'user2@example.com', 'locked': False, 'disabled': False, 'externallyManaged': False, 'twoFactorAuthenticationEnabled': False }, ] @pytest.fixture def mock_feature_flags(mock_traffic_types, mock_groups, mock_users): """Mock feature flags data.""" return [ { 'id': '1', 'name': 'flag_1', 'description': 'Flag 1', 'traffic_type': mock_traffic_types[0], 'creationTime': 1753177168911, 'rolloutStatus': { 'id': '1', 'name': 'Rollout Status 1' }, 'tags': None, 'owners': [ { 'id': mock_groups[0]['identifier'], 'type': 'group' }, { 'id': mock_users[0]['uuid'], 'type': 'user' } ] }, { 'id': '2', 'name': 'flag_2', 'description': 'Flag 2', 'traffic_type': mock_traffic_types[1], 'creationTime': 'bad-time', 'rolloutStatus': { 'id': '2', 'name': 'Rollout Status 2' }, 'tags': [ { 'name': 'Team 2' } ], 'owners': [ { 'id': mock_groups[1]['identifier'], 'type': 'group' }, { 'id': mock_users[1]['uuid'], 'type': 'user' } ] } ] @pytest.fixture def paginate_mock_response(): """Fixture to paginate mock API responses.""" def _paginate(items, limit=50, key='objects'): """ Yield paginated mock responses simulating a paginated API. Args: items (list): List of mock items. limit (int): Max items per page (default 50). key (str): The key under which items are returned (default "objects"). Yields: dict: A mock page containing up to `limit` items. """ for i in range(0, len(items), limit): yield {key: items[i:i + limit]} yield {key: []} return _paginate @pytest.fixture def make_sample_dfs(): """Create sample DataFrames for testing export functions.""" flags_df = pd.DataFrame([{'Name': 'flag1', 'Description': 'test', 'Traffic Type': 'user', 'Rollout Status': 'active', 'Creation Time': '2023-07-01 10:00:00', 'Owners': 'Alice', 'Groups': 'Admins', 'Tags': 'teamA'}]) users_df = pd.DataFrame([{'name': 'Alice', 'email': 'a@example.com', 'status': 'active', '2fa': True, 'id': 'u1'}]) groups_df = pd.DataFrame([{'name': 'Admins', 'description': 'Admin group', 'id': 'g1'}]) return flags_df, users_df, groups_df