def test_should_filter_out_later_or_equal_dates(self):
        # GIVEN
        expected_date_to = '2016-07-02'
        cmd = self.CMD_TEST_DATE + '--date_to %s' % expected_date_to
        cmd = cmd.split()

        # WHEN
        main(start_cmd=cmd)

        # THEN
        filtered_logs = self.get_filtered_mongo_data()
        self.check_if_dates_earlier_than(date_to=expected_date_to,
                                         logs=filtered_logs)
Exemple #2
0
    def test_should_sort_users_by_join_time(self):
        # GIVEN
        expected_event = Event111.eventId

        cli_cmd = '-e %s --order_by join_time' % expected_event
        cli_cmd = cli_cmd.split()

        # WHEN
        ca_analytics.main(start_cmd=cli_cmd)

        # THEN
        ca_events = self.get_script_processed_data()
        self.check_if_participants_in_join_order(ca_events=ca_events)
    def test_should_return_none_when_no_join_timestamp(self):
        # GIVEN
        expected_user = UserNoJoinTimeLogs

        cli_cmd = '-u %s' % expected_user.userId
        cli_cmd = cli_cmd.split()

        # WHEN
        ca_analytics.main(start_cmd=cli_cmd)

        # THEN
        ca_events = self.get_script_processed_data()
        participant = ca_events[0].event_participants()[0]

        self.assertIsNone(participant.timestamp.join)
    def test_should_select_user_and_event_he_participated(self):
        # GIVEN
        user = User111
        expected_event = Event111

        cli_cmd = '-u %s -e %s' % (user.userId, expected_event.eventId)
        cli_cmd = cli_cmd.split()

        # WHEN
        main(start_cmd=cli_cmd)

        # THEN
        ca_events = self.get_script_processed_data()

        self.assertTrue(len(ca_events) == 1)
        self.assertEqual(expected_event.eventId, ca_events[0].event_id)
Exemple #5
0
    def test_should_sort_events_by_event_id(self):
        # GIVEN
        expected_events_sorted_by_event_id = [Event111, Event222, Event333]

        cli_cmd = '-e %s --order_by event_id' % ' '.join(
            [str(evnt.eventId) for evnt in expected_events_sorted_by_event_id])
        cli_cmd = cli_cmd.split()

        # WHEN
        ca_analytics.main(start_cmd=cli_cmd)

        # THEN
        ca_events = self.get_script_processed_data()
        self.check_if_events_valid(
            script_events_data=ca_events,
            expected_events_data=expected_events_sorted_by_event_id)
    def test_should_select_events_user_participated(self):
        # GIVEN
        user = User111
        expected_event_ids = [
            mongo_log.event_id for mongo_log in User111._participated_in
        ]

        cli_cmd = '-u %s' % user.userId
        cli_cmd = cli_cmd.split()

        # WHEN
        main(start_cmd=cli_cmd)

        # THEN
        ca_events = self.get_script_processed_data()
        actual_event_ids = [ca_event.event_id for ca_event in ca_events]

        self.assertEqual(expected_event_ids, actual_event_ids)
    def test_should_include_up_but_not_low_bound_when_period_given(self):
        # GIVEN
        expected_date_from = '2016-07-02'
        expected_date_to = '2016-07-05'
        cmd = (self.CMD_TEST_DATE + '--date_from %s --date_to %s' %
               (expected_date_from, expected_date_to))
        cmd = cmd.split()

        # WHEN
        main(start_cmd=cmd)

        # THEN
        filtered_logs = self.get_filtered_mongo_data()

        self.check_if_dates_later_or_equal_than(date_from=expected_date_from,
                                                logs=filtered_logs)
        self.check_if_dates_earlier_than(date_to=expected_date_to,
                                         logs=filtered_logs)
    def test_should_assign_last_date_seen_as_end_time_if_no_event_in_db(self):
        event_id = 123
        # GIVEN
        for test_participant in self._test_users:
            cli_cmd = '-u %s' % test_participant.userId
            cli_cmd = cli_cmd.split()

            # WHEN
            ca_analytics.main(start_cmd=cli_cmd)

            # THEN
            ca_events = self.get_script_processed_data()
            event = ca_events[0]

            all_seen_timestamps = (test_participant.get_all_seen_timestamps(
                event_id=event_id))
            expected_end_date = all_seen_timestamps[-1]

            self.assertEqual(expected_end_date, event.end_time)
Exemple #9
0
    def test_should_assign_last_leave_timestamp_as_event_end(self):
        # GIVEN
        expected_event = EventNoCouchData
        expected_end_time = self.get_events_first_user_timestamp(
            EventNoCouchData).leave

        cli_cmd = '-e %s' % expected_event.eventId
        cli_cmd = cli_cmd.split()

        # WHEN
        ca_analytics.main(start_cmd=cli_cmd)

        # THEN
        ca_event = self.get_script_processed_data()[0]
        timestamps = ca_event._participants_handler.leave_timestamps

        event_end_time = ca_event.end_time
        last_participant_timestamp = timestamps[-1]

        self.assertEqual(expected_end_time, last_participant_timestamp)
        self.assertEqual(expected_end_time, event_end_time)
    def test_should_get_data_about_two_events(self):
        # GIVEN
        expected_events = [Event111, Event222]
        expected_users = self.get_expected_users(event_list=expected_events)

        cli_cmd = '-e %s' % ' '.join([str(e.eventId) for e in expected_events])
        cli_cmd = cli_cmd.split()

        # WHEN
        main(start_cmd=cli_cmd)

        # THEN
        ca_events = self.get_script_processed_data()

        self.check_if_events_valid(script_events_data=ca_events,
                                   expected_events_data=expected_events)

        for ca_event, expected_event in zip(ca_events, expected_events):
            self.check_if_users_valid(
                script_events_users=ca_event.event_participants(),
                expected_events_users=expected_users[expected_event],
                event_id=expected_event.eventId)
    def test_should_select_all_users_attending_the_event(self):
        # GIVEN
        expected_event = Event111
        expected_events = [Event111]
        expected_users = self.get_expected_users(event_list=expected_events)

        cli_cmd = '-e %s' % expected_event.eventId
        cli_cmd = cli_cmd.split()

        # WHEN
        main(start_cmd=cli_cmd)

        # THEN
        ca_events = self.get_script_processed_data()

        self.check_if_events_valid(script_events_data=ca_events,
                                   expected_events_data=expected_events)

        # TODO: Move to check_if_users_valid(ca_events, expected_events)
        for ca_event, expected_event in zip(ca_events, expected_events):
            self.check_if_users_valid(
                script_events_users=ca_event.event_participants(),
                expected_events_users=expected_users[expected_event],
                event_id=expected_event.eventId)