def setUp(self): """Set the environment for the tests up.""" super().setUp() self.tasks = TaskFactory.create_batch(5) TaskFactory.create_batch(5, archived=True)
def test_task_my_most_frequent(auth_client): user = auth_client.user tasks = TaskFactory.create_batch(6) report_date = date.today() - timedelta(days=20) old_report_date = date.today() - timedelta(days=90) # tasks[0] should appear as most frequently used task ReportFactory.create_batch(5, date=report_date, user=user, task=tasks[0]) # tasks[1] should appear as secondly most frequently used task ReportFactory.create_batch(4, date=report_date, user=user, task=tasks[1]) # tasks[2] should not appear in result, as too far in the past ReportFactory.create_batch(4, date=old_report_date, user=user, task=tasks[2]) # tasks[3] should not appear in result, as project is archived tasks[3].project.archived = True tasks[3].project.save() ReportFactory.create_batch(4, date=report_date, user=user, task=tasks[3]) # tasks[4] should not appear in result, as task is archived tasks[4].archived = True tasks[4].save() ReportFactory.create_batch(4, date=report_date, user=user, task=tasks[4]) url = reverse('task-list') response = auth_client.get(url, {'my_most_frequent': '10'}) assert response.status_code == status.HTTP_200_OK data = response.json()['data'] assert len(data) == 2 assert data[0]['id'] == str(tasks[0].id) assert data[1]['id'] == str(tasks[1].id)