Skip to content

Commit

Permalink
increase recommend coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
AditiR-42 committed Dec 12, 2024
1 parent 15d4c7a commit 5889d6a
Showing 1 changed file with 113 additions and 2 deletions.
115 changes: 113 additions & 2 deletions src/models/tests/integration/test_api_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import io
from unittest.mock import patch, MagicMock
from api_service.api.routers.summarize import process_pdf, get_grade
from api_service.api.routers.recommend import filter_dataframe, GenerativeModel
import pandas as pd
from fastapi import UploadFile, HTTPException
from fastapi import UploadFile
from io import BytesIO

BASE_URL = "http://localhost:9000"
Expand Down Expand Up @@ -514,4 +515,114 @@ async def test_get_grade_success(mock_privacy_grader):
"overall_grade": "A",
"overall_score": 95,
"category_scores": {"Category1": 90, "Category2": 100}
}
}

@pytest.fixture
def sample_df():
return pd.DataFrame({
'Service': ['App1', 'App2', 'App3'],
'Genre': ['Social', 'Music', 'Productivity'],
'privacy_rating': ['A', 'B', 'C'],
'Content Rating': ['Everyone', 'Teen', 'Mature'],
'app_score': [4.5, 4.0, 3.5],
'Installs': [1000000, 500000, 100000],
'num_ratings': [10000, 5000, 1000],
'num_reviews': [5000, 2500, 500],
'Free': [True, False, True],
'Contains Ads': [True, False, True]
})

@pytest.fixture
def mock_model():
mock = MagicMock(spec=GenerativeModel)
mock.generate_content.return_value = MagicMock(text="social")
return mock

def test_filter_by_genre(sample_df, mock_model):
with patch('your_module.df', sample_df), \
patch('your_module.model', mock_model):
criteria = {'Genre': 'Social Media'}
result = filter_dataframe(criteria)
assert len(result) == 1
assert result.iloc[0]['Service'] == 'App1'

def test_filter_by_privacy_rating(sample_df):
with patch('your_module.df', sample_df):
criteria = {'privacy_rating': 'B'}
result = filter_dataframe(criteria)
assert len(result) == 2
assert set(result['Service']) == {'App1', 'App2'}

def test_filter_by_content_rating(sample_df):
with patch('your_module.df', sample_df):
criteria = {'Content Rating': 'Teen'}
result = filter_dataframe(criteria)
assert len(result) == 1
assert result.iloc[0]['Service'] == 'App2'

def test_filter_by_app_score(sample_df):
with patch('your_module.df', sample_df):
criteria = {'app_score': 4.0}
result = filter_dataframe(criteria)
assert len(result) == 2
assert set(result['Service']) == {'App1', 'App2'}

def test_filter_by_installs(sample_df):
with patch('your_module.df', sample_df):
criteria = {'Installs': 500000}
result = filter_dataframe(criteria)
assert len(result) == 2
assert set(result['Service']) == {'App1', 'App2'}

def test_filter_by_num_ratings(sample_df):
with patch('your_module.df', sample_df):
criteria = {'num_ratings': 5000}
result = filter_dataframe(criteria)
assert len(result) == 2
assert set(result['Service']) == {'App1', 'App2'}

def test_filter_by_num_reviews(sample_df):
with patch('your_module.df', sample_df):
criteria = {'num_reviews': 2500}
result = filter_dataframe(criteria)
assert len(result) == 2
assert set(result['Service']) == {'App1', 'App2'}

def test_filter_by_free(sample_df):
with patch('your_module.df', sample_df):
criteria = {'Free': 'True'}
result = filter_dataframe(criteria)
assert len(result) == 2
assert set(result['Service']) == {'App1', 'App3'}

def test_filter_by_contains_ads(sample_df):
with patch('your_module.df', sample_df):
criteria = {'Contains Ads': 'False'}
result = filter_dataframe(criteria)
assert len(result) == 1
assert result.iloc[0]['Service'] == 'App2'

def test_multiple_criteria(sample_df):
with patch('your_module.df', sample_df):
criteria = {
'privacy_rating': 'B',
'Free': 'False',
'app_score': 3.5
}
result = filter_dataframe(criteria)
assert len(result) == 1
assert result.iloc[0]['Service'] == 'App2'

def test_no_matching_results(sample_df):
with patch('your_module.df', sample_df):
criteria = {'privacy_rating': 'D'}
result = filter_dataframe(criteria)
assert len(result) == 0

def test_service_criterion_updates_genre_and_privacy_rating(sample_df):
with patch('your_module.df', sample_df):
criteria = {'Service': 'App2'}
result = filter_dataframe(criteria)
assert len(result) == 1
assert result.iloc[0]['Genre'] == 'Music'
assert result.iloc[0]['privacy_rating'] == 'B'

0 comments on commit 5889d6a

Please sign in to comment.