def test_get_form_duration_stats_for_users(self): """ Tests the get_form_duration_stats_for_users basic ability to get duration stats """ user1, user2 = 'u1', 'u2' app1 = '123' xmlns1 = 'abc' start = datetime(2013, 7, 1) end = datetime(2013, 7, 30) time_start = datetime(2013, 6, 15, 0, 0, 0) completion_time = datetime(2013, 7, 15, 0, 0, 0) self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app1, xmlns=xmlns1, time_start=time_start, ) self._send_form_to_es( completion_time=completion_time, user_id=user2, app_id=app1, xmlns=xmlns1, time_start=time_start, ) self._send_form_to_es( completion_time=completion_time, user_id=None, app_id=app1, xmlns=xmlns1, time_start=time_start, ) results = get_form_duration_stats_for_users( self.domain, app1, xmlns1, [user1, user2, None], start, end, by_submission_time=False ) self.assertEqual(results['count'], 3) self.assertEqual(timedelta(milliseconds=results['max']), completion_time - time_start)
def test_get_form_duration_stats_for_users(self): """ Tests the get_form_duration_stats_for_users basic ability to get duration stats """ user1, user2 = 'u1', 'u2' app1 = '123' xmlns1 = 'abc' start = datetime(2013, 7, 1) end = datetime(2013, 7, 30) time_start = datetime(2013, 6, 15, 0, 0, 0) completion_time = datetime(2013, 7, 15, 0, 0, 0) self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app1, xmlns=xmlns1, time_start=time_start, ) self._send_form_to_es( completion_time=completion_time, user_id=user2, app_id=app1, xmlns=xmlns1, time_start=time_start, ) self._send_form_to_es( completion_time=completion_time, user_id=None, app_id=app1, xmlns=xmlns1, time_start=time_start, ) results = get_form_duration_stats_for_users( self.domain, app1, xmlns1, [user1, user2, None], start, end, by_submission_time=False ) self.assertEqual(results['count'], 3) self.assertEqual(timedelta(milliseconds=results['max']), completion_time - time_start)
def test_get_form_duration_stats_for_users_decoys(self): """ Tests the get_form_duration_stats_for_users ability to filter out forms that do not fit within the filters specified """ user1, user2 = 'u1', 'u2' app1, app2 = '123', '456' xmlns1, xmlns2 = 'abc', 'def' start = datetime(2013, 7, 1) end = datetime(2013, 7, 30) time_start = datetime(2013, 7, 2, 0, 0, 0) completion_time = datetime(2013, 7, 15, 0, 0, 0) received_on = datetime(2013, 7, 20, 0, 0, 0) received_on_late = datetime(2013, 8, 20, 0, 0, 0) self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app1, xmlns=xmlns1, time_start=time_start, received_on=received_on, ) # different app self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app2, xmlns=xmlns1, time_start=time_start, received_on=received_on, ) # different xmlns self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app1, xmlns=xmlns2, time_start=time_start, received_on=received_on, ) # out of time range self._send_form_to_es( completion_time=completion_time, user_id=user2, app_id=app1, xmlns=xmlns1, time_start=time_start, received_on=received_on_late, ) results = get_form_duration_stats_for_users(self.domain, app1, xmlns1, [user1, user2], start, end, by_submission_time=True) self.assertEqual(results['count'], 1) self.assertEqual(timedelta(milliseconds=results['max']), completion_time - time_start)
def test_get_form_duration_stats_for_users_decoys(self): """ Tests the get_form_duration_stats_for_users ability to filter out forms that do not fit within the filters specified """ user1, user2 = 'u1', 'u2' app1, app2 = '123', '456' xmlns1, xmlns2 = 'abc', 'def' start = datetime(2013, 7, 1) end = datetime(2013, 7, 30) time_start = datetime(2013, 7, 2, 0, 0, 0) completion_time = datetime(2013, 7, 15, 0, 0, 0) received_on = datetime(2013, 7, 20, 0, 0, 0) received_on_late = datetime(2013, 8, 20, 0, 0, 0) self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app1, xmlns=xmlns1, time_start=time_start, received_on=received_on, ) # different app self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app2, xmlns=xmlns1, time_start=time_start, received_on=received_on, ) # different xmlns self._send_form_to_es( completion_time=completion_time, user_id=user1, app_id=app1, xmlns=xmlns2, time_start=time_start, received_on=received_on, ) # out of time range self._send_form_to_es( completion_time=completion_time, user_id=user2, app_id=app1, xmlns=xmlns1, time_start=time_start, received_on=received_on_late, ) results = get_form_duration_stats_for_users( self.domain, app1, xmlns1, [user1, user2], start, end, by_submission_time=True ) self.assertEqual(results['count'], 1) self.assertEqual(timedelta(milliseconds=results['max']), completion_time - time_start)