-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding source in user database for analytics.
- Loading branch information
1 parent
eaf44a8
commit f118e90
Showing
7 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
migrations/versions/3867bb00a495_added_first_login_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""added_first_login_source | ||
Revision ID: 3867bb00a495 | ||
Revises: 661ec8a4c32e | ||
Create Date: 2023-09-15 02:06:24.006555 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '3867bb00a495' | ||
down_revision = '661ec8a4c32e' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('users', sa.Column('first_login_source', sa.String(), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('users', 'first_login_source') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from main import app | ||
from superagi.models.user import User | ||
|
||
client = TestClient(app) | ||
|
||
# Define a fixture for an authenticated user | ||
@pytest.fixture | ||
def authenticated_user(): | ||
# Create a mock user object with necessary attributes | ||
user = User() | ||
|
||
# Set user attributes | ||
user.id = 1 # User ID | ||
user.username = "testuser" # User's username | ||
user.email = "super6@agi.com" # User's email | ||
user.first_login_source = None # User's first login source | ||
user.token = "mock-jwt-token" | ||
|
||
return user | ||
|
||
# Test case for updating first login source when it's not set | ||
def test_update_first_login_source(authenticated_user): | ||
with patch('superagi.helper.auth.db') as mock_auth_db: | ||
source = "github" # Specify the source you want to set | ||
|
||
mock_auth_db.session.query.return_value.filter.return_value.first.return_value = authenticated_user | ||
response = client.post(f"users/first_login_source/{source}", headers={"Authorization": f"Bearer {authenticated_user.token}"}) | ||
|
||
# Verify the HTTP response | ||
assert response.status_code == 200 | ||
assert "first_login_source" in response.json() # Check if the "first_login_source" field is in the response | ||
assert response.json()["first_login_source"] == "github" # Check if the "source" field equals "github" |