def test_is_not_valid_with_all_deleted_forms(self): post_data = build_querydict({ 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MIN_NUM_FORMS': '1', 'form-MAX_NUM_FORMS': '1000', 'form-0-email_addr': '*****@*****.**', 'form-0-DELETE': 'on', 'form-1-email_addr': '', 'form-1-DELETE': 'on', }) formset = TicketForOthersFormSet(post_data) self.assertFalse(formset.is_valid())
def test_is_valid_with_valid_data_and_empty_form(self): post_data = build_querydict({ 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MIN_NUM_FORMS': '1', 'form-MAX_NUM_FORMS': '1000', 'form-0-email_addr': '*****@*****.**', 'form-0-name': 'Test 1', 'form-0-days': ['sat', 'sun'], 'form-1-email_addr': '', }) formset = TicketForOthersFormSet(post_data) self.assertTrue(formset.is_valid())
def test_from_pending_order_for_self_and_others(self): order = factories.create_pending_order_for_self_and_others() expected = { 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '2', 'form-0-days': ['sun', 'mon'], 'form-0-email_addr': '*****@*****.**', 'form-0-name': 'Bob', 'form-1-days': ['mon', 'tue'], 'form-1-email_addr': '*****@*****.**', 'form-1-name': 'Carol', } self.assertEqual( TicketForOthersFormSet.from_pending_order(order).data, expected)
def test_is_not_valid_with_no_nonempty_forms(self): post_data = build_querydict({ 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MIN_NUM_FORMS': '1', 'form-MAX_NUM_FORMS': '1000', 'form-0-email_addr': '', 'form-1-email_addr': '', }) formset = TicketForOthersFormSet(post_data) self.assertEqual(formset.errors, [{ 'email_addr': ['This field is required.'], 'name': ['This field is required.'], 'days': ['This field is required.'] }, {}])
def test_is_not_valid_with_no_days(self): post_data = build_querydict({ 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MIN_NUM_FORMS': '1', 'form-MAX_NUM_FORMS': '1000', 'form-0-email_addr': '*****@*****.**', 'form-0-name': 'Test 1', 'form-0-days': ['sat', 'sun'], 'form-1-email_addr': '*****@*****.**', 'form-1-name': 'Test 2', }) formset = TicketForOthersFormSet(post_data) self.assertEqual(formset.errors, [{}, { 'days': ['This field is required.'] }])
def test_email_addrs_and_days_with_valid_data_and_deleted_form(self): post_data = build_querydict({ 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MIN_NUM_FORMS': '1', 'form-MAX_NUM_FORMS': '1000', 'form-0-email_addr': '*****@*****.**', 'form-0-name': 'Test 1', 'form-0-days': ['sat', 'sun'], 'form-1-email_addr': '*****@*****.**', 'form-1-name': 'Test 2', 'form-1-days': ['sat', 'sun'], 'form-1-DELETE': 'on', }) formset = TicketForOthersFormSet(post_data) formset.errors # Trigger full clean self.assertEqual(formset.email_addrs_and_days, [('*****@*****.**', 'Test 1', ['sat', 'sun'])])
def test_from_pending_order_for_self(self): order = factories.create_pending_order_for_self() self.assertEqual( TicketForOthersFormSet.from_pending_order(order).data, {})