Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bonk1t committed Jan 21, 2024
1 parent aff6cb9 commit d262dba
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion nalgonda/dependencies/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def get_user(username: str) -> UserInDB | None:
user = UserRepository().get_user_by_id(username)
if user:
return UserInDB(**user)
return UserInDB(**user, username=username)


async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]) -> UserInDB:
Expand Down
6 changes: 2 additions & 4 deletions tests/functional/v1/api/test_agency_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def test_get_agency_config(client, mock_firestore_client):
mock_data = {
"agency_id": "test_agency",
"owner_id": "test_user",
"owner_id": TEST_USER_ID,
"agency_manifesto": "Test Manifesto",
"main_agent": None,
"agents": [],
Expand All @@ -20,7 +20,7 @@ def test_get_agency_config(client, mock_firestore_client):
assert response.json() == mock_data


def test_update_agency_config_success(client, mock_firestore_client, mock_get_current_active_user):
def test_update_agency_config_success(client, mock_firestore_client, mock_get_current_active_user): # noqa: ARG001
# Setup initial data in mock Firestore client
initial_data = {
"agency_id": "test_agency",
Expand All @@ -43,8 +43,6 @@ def test_update_agency_config_success(client, mock_firestore_client, mock_get_cu
assert response.status_code == 200
assert response.json() == {"message": "Agency configuration updated successfully"}

mock_get_current_active_user.assert_called_once()


def test_get_agency_config_not_found(client):
# Simulate non-existent agency by not setting up any data for it
Expand Down
4 changes: 1 addition & 3 deletions tests/functional/v1/api/test_agent_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_get_agent_config(client, mock_firestore_client):
assert response.json() == MOCK_DATA


def test_update_agent_config(client, mock_get_current_active_user):
def test_update_agent_config(client, mock_get_current_active_user): # noqa: ARG001
agent_config_data = MOCK_DATA.copy()

with patch("nalgonda.services.agent_manager.AgentManager") as mock_agent_manager:
Expand All @@ -31,5 +31,3 @@ def test_update_agent_config(client, mock_get_current_active_user):

assert response.status_code == 200
assert response.json() == {"agent_id": AGENT_ID}

mock_get_current_active_user.assert_called_once()
8 changes: 2 additions & 6 deletions tests/functional/v1/api/test_tool_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from tests.test_utils import TEST_USER_ID


def test_get_tool_list(client, mock_firestore_client, mock_get_current_active_user):
def test_get_tool_list(client, mock_firestore_client, mock_get_current_active_user): # noqa: ARG001
user_id = TEST_USER_ID
tool_config_data = {
"tool_id": "tool1",
Expand All @@ -17,10 +17,8 @@ def test_get_tool_list(client, mock_firestore_client, mock_get_current_active_us
assert response.status_code == 200
assert response.json() == [tool_config_data]

mock_get_current_active_user.assert_called_once()


def test_approve_tool_config(client, mock_firestore_client, mock_get_current_superuser):
def test_approve_tool_config(client, mock_firestore_client, mock_get_current_superuser): # noqa: ARG001
tool_id = "tool1"
tool_config_data = {
"tool_id": tool_id,
Expand All @@ -39,5 +37,3 @@ def test_approve_tool_config(client, mock_firestore_client, mock_get_current_sup
# Verify if the tool configuration is approved in the mock Firestore client
updated_config = mock_firestore_client.to_dict()
assert updated_config["approved"] is True

mock_get_current_superuser.assert_called_once()
8 changes: 6 additions & 2 deletions tests/test_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@


def get_current_active_user_override():
return UserInDB(id=TEST_USER_ID, username="test_user", hashed_password="hashed_password_test", disabled=False)
return UserInDB(id=TEST_USER_ID, username=TEST_USER_ID, hashed_password="hashed_password_test", disabled=False)


def get_current_superuser_override():
return UserInDB(
id=TEST_USER_ID, username="test_user", hashed_password="hashed_password_test", disabled=False, is_superuser=True
id=TEST_USER_ID,
username=TEST_USER_ID,
hashed_password="hashed_password_test",
disabled=False,
is_superuser=True,
)
10 changes: 5 additions & 5 deletions tests/unit/services/test_agency_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def test_get_agency_repopulate_cache(agency_manager):
async def test_update_agency(agency_manager):
agency_config = AgencyConfig(
agency_id="test_agency",
owner_id="test_user",
owner_id=TEST_USER_ID,
agency_manifesto="manifesto",
agents=["agent1_id"],
)
Expand Down Expand Up @@ -130,7 +130,7 @@ async def test_repopulate_cache_no_config(agency_manager):
async def test_repopulate_cache_success(agency_manager, mock_firestore_client):
agency_config = AgencyConfig(
agency_id="test_agency",
owner_id="test_user",
owner_id=TEST_USER_ID,
agency_manifesto="manifesto",
agents=["agent1_id"],
)
Expand Down Expand Up @@ -159,7 +159,7 @@ async def test_repopulate_cache_success(agency_manager, mock_firestore_client):
async def test_load_and_construct_agents_success():
agency_config = AgencyConfig(
agency_id="test_agency",
owner_id="test_user",
owner_id=TEST_USER_ID,
agency_manifesto="Test manifesto",
agents=["agent1_id"],
)
Expand All @@ -184,7 +184,7 @@ async def test_load_and_construct_agents_success():
async def test_load_and_construct_agents_agent_not_found():
agency_config = AgencyConfig(
agency_id="test_agency",
owner_id="test_user",
owner_id=TEST_USER_ID,
agency_manifesto="Test manifesto",
agents=["agent1_id"],
)
Expand All @@ -205,7 +205,7 @@ async def test_construct_agency_single_layer_chart():
# Mock AgencyConfig
agency_config = AgencyConfig(
agency_id="test_agency",
owner_id="test_user",
owner_id=TEST_USER_ID,
agency_manifesto="manifesto",
agents=["agent1_id", "agent2_id"],
main_agent="agent1_name",
Expand Down

0 comments on commit d262dba

Please sign in to comment.