Beispiel #1
0
    def test_get_queryset_no_dates_provided(self):
        """Test what happens if neither start or end date/time are provided."""
        # Using invite because it's one of the easier models in Connect to
        # quickly create a timestamped instance with.
        timezone = get_current_timezone()
        invite1 = mommy.make(Invite)
        invite1.created_at = make_aware(datetime(2012, 12, 31, 23, 59),
                                        timezone)
        invite1.save()
        invite2 = mommy.make(Invite)
        invite2.created_at = make_aware(datetime(2013, 06, 01, 00, 01),
                                        timezone)
        invite2.save()
        invite3 = mommy.make(Invite)
        invite3.created_at = make_aware(datetime(2014, 01, 01, 00, 01),
                                        timezone)
        invite3.save()

        # Get the queryset
        mixin = DateTimeRangeListMixin()
        mixin.model = Invite
        mixin.request = self.request_factory.get('')
        queryset = mixin.get_queryset()
        self.assertIn(invite1, queryset)
        self.assertIn(invite2, queryset)
        self.assertIn(invite3, queryset)
    def test_get_queryset_no_dates_provided(self):
        """Test what happens if neither start or end date/time are provided."""
        # Using invite because it's one of the easier models in Connect to
        # quickly create a timestamped instance with.
        timezone = get_current_timezone()
        invite1 = mommy.make(Invite)
        invite1.created_at = make_aware(
            datetime(2012, 12, 31, 23, 59), timezone)
        invite1.save()
        invite2 = mommy.make(Invite)
        invite2.created_at = make_aware(
            datetime(2013, 06, 01, 00, 01), timezone)
        invite2.save()
        invite3 = mommy.make(Invite)
        invite3.created_at = make_aware(
            datetime(2014, 01, 01, 00, 01), timezone)
        invite3.save()

        # Get the queryset
        mixin = DateTimeRangeListMixin()
        mixin.model = Invite
        mixin.request = self.request_factory.get('')
        queryset = mixin.get_queryset()
        self.assertIn(invite1, queryset)
        self.assertIn(invite2, queryset)
        self.assertIn(invite3, queryset)
Beispiel #3
0
    def test_get_queryset_only_end_date(self):
        """Test updating queryset when only end date is provided."""
        # Using invite because it's one of the easier models in Connect to
        # quickly create a timestamped instance with.
        timezone = get_current_timezone()
        invite1 = mommy.make(Invite)
        invite1.created_at = make_aware(datetime(2012, 12, 31, 23, 59),
                                        timezone)
        invite1.save()
        invite2 = mommy.make(Invite)
        invite2.created_at = make_aware(datetime(2013, 06, 01, 00, 01),
                                        timezone)
        invite2.save()
        invite3 = mommy.make(Invite)
        invite3.created_at = make_aware(datetime(2014, 01, 01, 00, 01),
                                        timezone)
        invite3.save()

        # Get the queryset
        mixin = DateTimeRangeListMixin()
        mixin.model = Invite
        mixin.request = self.request_factory.get(
            '/?end_datetime=2013-12-31 11:59 pm')
        queryset = mixin.get_queryset()
        self.assertIn(invite1, queryset)
        self.assertIn(invite2, queryset)
        self.assertNotIn(invite3, queryset)
    def test_get_queryset_only_end_date(self):
        """Test updating queryset when only end date is provided."""
        # Using invite because it's one of the easier models in Connect to
        # quickly create a timestamped instance with.
        timezone = get_current_timezone()
        invite1 = mommy.make(Invite)
        invite1.created_at = make_aware(
            datetime(2012, 12, 31, 23, 59), timezone)
        invite1.save()
        invite2 = mommy.make(Invite)
        invite2.created_at = make_aware(
            datetime(2013, 06, 01, 00, 01), timezone)
        invite2.save()
        invite3 = mommy.make(Invite)
        invite3.created_at = make_aware(
            datetime(2014, 01, 01, 00, 01), timezone)
        invite3.save()

        # Get the queryset
        mixin = DateTimeRangeListMixin()
        mixin.model = Invite
        mixin.request = self.request_factory.get(
            '/?end_datetime=2013-12-31 11:59 pm'
        )
        queryset = mixin.get_queryset()
        self.assertIn(invite1, queryset)
        self.assertIn(invite2, queryset)
        self.assertNotIn(invite3, queryset)
Beispiel #5
0
 def test_get_date_range_form_initial(self):
     """Test getting form initial values."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get(
         '/?start_datetime=2013-01-01 12:01 am'
         '&end_datetime=2013-12-31 11:59 pm')
     initial = mixin.get_date_range_form_initial()
     self.assertEqual(initial['start_datetime'], u'2013-01-01 12:01 am')
     self.assertEqual(initial['end_datetime'], u'2013-12-31 11:59 pm')
 def test_get_date_range_form_initial(self):
     """Test getting form initial values."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get(
         '/?start_datetime=2013-01-01 12:01 am'
         '&end_datetime=2013-12-31 11:59 pm'
     )
     initial = mixin.get_date_range_form_initial()
     self.assertEqual(initial['start_datetime'], u'2013-01-01 12:01 am')
     self.assertEqual(initial['end_datetime'], u'2013-12-31 11:59 pm')
Beispiel #7
0
 def test_get_date_range_form_kwargs(self):
     """Test getting form kwargs."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get(
         '/?start_datetime=2013-01-01 12:01 am'
         '&end_datetime=2013-12-31 11:59 pm')
     kwargs = mixin.get_date_range_form_kwargs()
     self.assertEqual(kwargs['initial']['start_datetime'],
                      u'2013-01-01 12:01 am')
     self.assertEqual(kwargs['initial']['end_datetime'],
                      u'2013-12-31 11:59 pm')
Beispiel #8
0
 def test_get_date_range_form(self):
     """Test form creation."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get(
         '/?start_datetime=2013-01-01 12:01 am'
         '&end_datetime=2013-12-31 11:59 pm')
     form = mixin.get_date_range_form()
     self.assertIsInstance(form, DateTimeRangeForm)
     self.assertEqual(form.initial['start_datetime'],
                      u'2013-01-01 12:01 am')
     self.assertEqual(form.initial['end_datetime'], u'2013-12-31 11:59 pm')
 def test_get_date_range_form_kwargs(self):
     """Test getting form kwargs."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get(
         '/?start_datetime=2013-01-01 12:01 am'
         '&end_datetime=2013-12-31 11:59 pm'
     )
     kwargs = mixin.get_date_range_form_kwargs()
     self.assertEqual(
         kwargs['initial']['start_datetime'],
         u'2013-01-01 12:01 am'
     )
     self.assertEqual(
         kwargs['initial']['end_datetime'],
         u'2013-12-31 11:59 pm'
     )
 def test_get_date_range_form(self):
     """Test form creation."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get(
         '/?start_datetime=2013-01-01 12:01 am'
         '&end_datetime=2013-12-31 11:59 pm'
     )
     form = mixin.get_date_range_form()
     self.assertIsInstance(form, DateTimeRangeForm)
     self.assertEqual(
         form.initial['start_datetime'],
         u'2013-01-01 12:01 am'
     )
     self.assertEqual(
         form.initial['end_datetime'],
         u'2013-12-31 11:59 pm'
     )
Beispiel #11
0
 def test_get_context_data(self):
     """Test adding form to context."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get('/')
     self.assertIsInstance(mixin.get_context_data()['date_range_form'],
                           DateTimeRangeForm)
 def test_get_context_data(self):
     """Test adding form to context."""
     mixin = DateTimeRangeListMixin()
     mixin.request = self.request_factory.get('/')
     self.assertIsInstance(
         mixin.get_context_data()['date_range_form'], DateTimeRangeForm)