# Path: periods/models.py
# def today():
#     def timezone(self):
#     def first_days(self):
#     def cycle_count(self):
#     def get_previous_period(self, previous_to):
#     def get_next_period(self, after=None):
#     def get_cache_key(self, data_type):
#     def get_cycle_lengths(self):
#     def get_sorted_cycle_lengths(self):
#     def get_full_name(self):
#     def get_short_name(self):
#     def __str__(self):
#     def choices(cls, blank=False):
#     def __str__(self):
#     def _get_ordinal_value(self, index):
#     def cycle_length_minimum(self):
#     def cycle_length_maximum(self):
#     def _get_statistics_value(self, method_name, num_values_required=1):
#     def cycle_length_mean(self):
#     def cycle_length_median(self):
#     def cycle_length_mode(self):
#     def cycle_length_standard_deviation(self):
#     def current_cycle_length(self):
#     def first_date(self):
#     def first_day(self):
#     def set_start_date_and_day(self, min_timestamp):
#     def predicted_events(self):
#     def __str__(self):
#     def get_from_server(from_date):
#     def get_for_date(cls, from_date, to_date):
# def create_auth_token(sender, instance=None, created=False, **kwargs):
# def add_to_permissions_group(sender, instance, **kwargs):
# def create_statistics(sender, instance, **kwargs):
# def update_statistics(sender, instance, **kwargs):
# class User(AbstractEmailUser):
# class LabelChoicesEnum(enum.Enum):
# class FlowLevel(LabelChoicesEnum):
# class FlowColor(LabelChoicesEnum):
# class ClotSize(LabelChoicesEnum):
# class CrampLevel(LabelChoicesEnum):
# class FlowEvent(models.Model):
# class Statistics(models.Model):
#     class Meta:
# class AerisData(models.Model):
#     SPOTTING = 0
#     LIGHT = 1
#     MEDIUM = 2
#     HEAVY = 3
#     VERY_HEAVY = 4
#     PINK = 0
#     LIGHT_RED = 1
#     RED = 2
#     DARK_RED = 3
#     BROWN = 4
#     BLACK = 5
#     SMALL = 0
#     MEDIUM = 1
#     LARGE = 2
#     SLIGHT = 0
#     MODERATE = 1
#     SEVERE = 2
# 
# Path: periods/tests/factories.py
# class FlowEventFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = period_models.FlowEvent
# 
#     user = factory.SubFactory(UserFactory)
#     timestamp = pytz.utc.localize(datetime.datetime(2014, 1, 31, 17, 0, 0))
#     first_day = True
# 
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = get_user_model()
# 
#     first_name = u'Jessamyn'
#     birth_date = pytz.utc.localize(datetime.datetime(1995, 3, 1))
#     email = factory.Sequence(lambda n: "user_%d@example.com" % n)
#     password = factory.PostGenerationMethodCall('set_password', PASSWORD)
#     last_login = pytz.utc.localize(datetime.datetime(2015, 3, 1))


import datetime
import pytz
import re
import requests
from django.conf import settings
from django.contrib.auth import models as auth_models
from django.test import TestCase
from mock import MagicMock, patch
from periods import models as period_models
from periods.tests.factories import FlowEventFactory, UserFactory
        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)

    @patch('periods.models.today')
    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)

    @patch('periods.models.today')
    def test_update_statistics_periods_exist(self, mock_today):
        mock_today.return_value = TIMEZONE.localize(datetime.datetime(2014, 4, 5))

# Path: periods/models.py
# def today():
#     def timezone(self):
#     def first_days(self):
#     def cycle_count(self):
#     def get_previous_period(self, previous_to):
#     def get_next_period(self, after=None):
#     def get_cache_key(self, data_type):
#     def get_cycle_lengths(self):
#     def get_sorted_cycle_lengths(self):
#     def get_full_name(self):
#     def get_short_name(self):
#     def __str__(self):
#     def choices(cls, blank=False):
#     def __str__(self):
#     def _get_ordinal_value(self, index):
#     def cycle_length_minimum(self):
#     def cycle_length_maximum(self):
#     def _get_statistics_value(self, method_name, num_values_required=1):
#     def cycle_length_mean(self):
#     def cycle_length_median(self):
#     def cycle_length_mode(self):
#     def cycle_length_standard_deviation(self):
#     def current_cycle_length(self):
#     def first_date(self):
#     def first_day(self):
#     def set_start_date_and_day(self, min_timestamp):
#     def predicted_events(self):
#     def __str__(self):
#     def get_from_server(from_date):
#     def get_for_date(cls, from_date, to_date):
# def create_auth_token(sender, instance=None, created=False, **kwargs):
# def add_to_permissions_group(sender, instance, **kwargs):
# def create_statistics(sender, instance, **kwargs):
# def update_statistics(sender, instance, **kwargs):
# class User(AbstractEmailUser):
# class LabelChoicesEnum(enum.Enum):
# class FlowLevel(LabelChoicesEnum):
# class FlowColor(LabelChoicesEnum):
# class ClotSize(LabelChoicesEnum):
# class CrampLevel(LabelChoicesEnum):
# class FlowEvent(models.Model):
# class Statistics(models.Model):
#     class Meta:
# class AerisData(models.Model):
#     SPOTTING = 0
#     LIGHT = 1
#     MEDIUM = 2
#     HEAVY = 3
#     VERY_HEAVY = 4
#     PINK = 0
#     LIGHT_RED = 1
#     RED = 2
#     DARK_RED = 3
#     BROWN = 4
#     BLACK = 5
#     SMALL = 0
#     MEDIUM = 1
#     LARGE = 2
#     SLIGHT = 0
#     MODERATE = 1
#     SEVERE = 2
# 
# Path: periods/tests/factories.py
# class FlowEventFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = period_models.FlowEvent
# 
#     user = factory.SubFactory(UserFactory)
#     timestamp = pytz.utc.localize(datetime.datetime(2014, 1, 31, 17, 0, 0))
#     first_day = True
# 
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = get_user_model()
# 
#     first_name = u'Jessamyn'
#     birth_date = pytz.utc.localize(datetime.datetime(1995, 3, 1))
#     email = factory.Sequence(lambda n: "user_%d@example.com" % n)
#     password = factory.PostGenerationMethodCall('set_password', PASSWORD)
#     last_login = pytz.utc.localize(datetime.datetime(2015, 3, 1))


# Path: periods/tests/test_models.py
import datetime
import pytz
import re
import requests
from django.conf import settings
from django.contrib.auth import models as auth_models
from django.test import TestCase
from mock import MagicMock, patch
from periods import models as period_models
from periods.tests.factories import FlowEventFactory, UserFactory

        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)

    @patch('periods.models.today')
    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)

    @patch('periods.models.today')
    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,