def test_report_usage_to_coda_success(athlete, mock_call_json_responses, coda, settings): athletes = AthleteFactory.create_batch(5) for athlete in athletes: RouteFactory.create_batch(5, athlete=athlete) ActivityFactory.create_batch(5, athlete=athlete) response_mocks = [ { "url": coda["doc_url"], "response_file": "coda_doc.json", }, { "url": coda["table_url"], "response_file": "coda_table.json", }, { "url": coda["table_url"] + "/columns", "response_file": "coda_columns.json", }, { "url": coda["table_url"] + "/rows", "method": "post", "response_file": "coda_request.json", "status": 202, }, ] response = mock_call_json_responses(report_usage_to_coda, response_mocks) assert response == "Updated {} rows in Coda table at https://coda.io/d/{}".format( Athlete.objects.count(), settings.CODA_DOC_ID)
def test_import_strava_activities_streams_task(athlete, mocker): activities = ActivityFactory.create_batch(10, athlete=athlete, streams=None) activity_ids = [activity.strava_id for activity in activities] mock_task = mocker.patch( "homebytwo.routes.tasks.import_strava_activity_streams_task.run" ) import_strava_activities_streams_task(activity_ids) mock_task.assert_called
def test_train_prediction_models_task(athlete): ActivityFactory.create_batch( 3, athlete=athlete, activity_type=ActivityTypeFactory(name="Run") ) ActivityFactory.create_batch( 2, athlete=athlete, activity_type=ActivityTypeFactory(name="Hike") ) ActivityFactory.create_batch( 1, athlete=athlete, activity_type=ActivityTypeFactory(name="Ride") ) response = train_prediction_models_task(athlete.id) expected = f"Prediction models trained for athlete: {athlete}." assert expected in response athlete_prediction_models = athlete.performances assert athlete_prediction_models.count() == 3 for model in athlete_prediction_models.all(): assert not model.model_score == 0.0