def test_add_meetup_form(self): """Test add Meetup form""" invalid_data = {'title': 'abc', 'date': timezone.now().date()} form = AddMeetupForm(data=invalid_data, created_by=self.systers_user, meetup_location=self.meetup_location) self.assertFalse(form.is_valid()) date = (timezone.now() + timedelta(2)).date() time = timezone.now().time() data = { 'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time, 'description': "It's a test meetup." } form = AddMeetupForm(data=data, created_by=self.systers_user, meetup_location=self.meetup_location) self.assertTrue(form.is_valid()) form.save() new_meetup = Meetup.objects.get(slug='foo') self.assertTrue(new_meetup.title, 'Foo') self.assertTrue(new_meetup.created_by, self.systers_user) self.assertTrue(new_meetup.meetup_location, self.meetup_location)
def test_add_meetup_form_with_passed_time(self): """Test add Meetup form with a time that has passed.""" date = timezone.now().date() time = (timezone.now() - timedelta(2)).time() data = { 'title': 'Foo', 'slug': 'foo', 'date': date, 'time': time, 'description': "It's a test meetup." } form = AddMeetupForm(data=data, created_by=self.systers_user, meetup_location=self.meetup_location) self.assertFalse(form.is_valid()) self.assertTrue(form.errors['time'], ["Time should not be a time that has already passed."])