示例#1
0
    def test_update_statistics_none_existing(self, mock_today):
        mock_today.return_value = pytz.utc.localize(
            datetime.datetime(2014, 4, 5))
        period = FlowEventFactory(user=self.period.user,
                                  timestamp=TIMEZONE.localize(
                                      datetime.datetime(2014, 2, 27)))

        period_models.update_statistics(period_models.FlowEvent, period)

        stats = period_models.Statistics.objects.get(user=self.period.user)
        self.assertEqual(27, stats.average_cycle_length)
        self.assertEqual(27, stats.all_time_average_cycle_length)
        self.assertEqual(37, stats.current_cycle_length)
        expected_events = [{
            'timestamp': datetime.date(2014, 3, 12),
            'type': 'projected ovulation'
        }, {
            'timestamp': datetime.date(2014, 3, 26),
            'type': 'projected period'
        }, {
            'timestamp': datetime.date(2014, 4, 8),
            'type': 'projected ovulation'
        }, {
            'timestamp': datetime.date(2014, 4, 22),
            'type': 'projected period'
        }, {
            'timestamp': datetime.date(2014, 5, 5),
            'type': 'projected ovulation'
        }, {
            'timestamp': datetime.date(2014, 5, 19),
            'type': 'projected period'
        }]
        self.assertEqual(expected_events, stats.predicted_events)
示例#2
0
    def test_update_statistics_deleted_user(self, mock_save):
        self.period.user.delete()
        pre_update_call_count = mock_save.call_count

        period_models.update_statistics(period_models.FlowEvent, self.period)

        self.assertEqual(pre_update_call_count, mock_save.call_count)
    def test_update_statistics_deleted_user(self, mock_save):
        self.period.user.delete()
        pre_update_call_count = mock_save.call_count

        period_models.update_statistics(period_models.FlowEvent, self.period)

        self.assertEqual(pre_update_call_count, mock_save.call_count)
    def test_update_statistics_none_existing(self, mocktoday):
        mocktoday.return_value = TIMEZONE.localize(datetime.datetime(2014, 4, 5))
        period = FlowEventFactory(user=self.period.user,
                                  timestamp=TIMEZONE.localize(datetime.datetime(2014, 2, 27)))

        period_models.update_statistics(period_models.FlowEvent, period)

        stats = period_models.Statistics.objects.get(user=self.period.user)
        self.assertEqual(27, stats.average_cycle_length)
        self.assertEqual(36, stats.current_cycle_length)
        expected_events = [{'timestamp': datetime.date(2014, 3, 12), 'type': 'projected ovulation'},
                           {'timestamp': datetime.date(2014, 3, 26), 'type': 'projected period'},
                           {'timestamp': datetime.date(2014, 4, 8), 'type': 'projected ovulation'},
                           {'timestamp': datetime.date(2014, 4, 22), 'type': 'projected period'},
                           {'timestamp': datetime.date(2014, 5, 5), 'type': 'projected ovulation'},
                           {'timestamp': datetime.date(2014, 5, 19), 'type': 'projected period'}]
        self.assertEqual(expected_events, stats.predicted_events)
示例#5
0
    def test_update_statistics_periods_exist(self, mock_today):
        mock_today.return_value = TIMEZONE.localize(datetime.datetime(2014, 4, 5))
        FlowEventFactory(user=self.period.user,
                         timestamp=TIMEZONE.localize(datetime.datetime(2014, 2, 14)))
        period = FlowEventFactory(user=self.period.user,
                                  timestamp=TIMEZONE.localize(datetime.datetime(2014, 2, 28)))
        FlowEventFactory(user=self.period.user,
                         timestamp=TIMEZONE.localize(datetime.datetime(2014, 3, 14)))

        period_models.update_statistics(period_models.FlowEvent, period)

        stats = period_models.Statistics.objects.get(user=self.period.user)
        self.assertEqual(14, stats.average_cycle_length)
        self.assertEqual(14, stats.all_time_average_cycle_length)
        self.assertEqual(22, stats.current_cycle_length)
        expected_events = [{'timestamp': datetime.date(2014, 3, 14), 'type': 'projected ovulation'},
                           {'timestamp': datetime.date(2014, 3, 28), 'type': 'projected period'},
                           {'timestamp': datetime.date(2014, 3, 28), 'type': 'projected ovulation'},
                           {'timestamp': datetime.date(2014, 4, 11), 'type': 'projected period'},
                           {'timestamp': datetime.date(2014, 4, 11), 'type': 'projected ovulation'},
                           {'timestamp': datetime.date(2014, 4, 25), 'type': 'projected period'}]
        self.assertEqual(expected_events, stats.predicted_events)