Exemplo n.º 1
0
 def test_can_create_home(self):
     self.assertCanCreate(
         self.home, HomePage,
         nested_form_data({
             'title': 'Home Test Page',
             'event_slides': inline_formset([])
         }))
Exemplo n.º 2
0
    def test_assert_can_create_with_form_helpers(self):
        # same as test_assert_can_create, but using the helpers from wagtail.tests.utils.form_data
        # as an end-to-end test
        self.assertFalse(EventIndex.objects.exists())
        self.assertCanCreate(self.root, EventIndex, nested_form_data({
            'title': 'Event Index',
            'intro': rich_text('<p>Event intro</p>')
        }))
        self.assertTrue(EventIndex.objects.exists())

        self.assertCanCreate(self.root, StreamPage, nested_form_data({
            'title': 'Flierp',
            'body': streamfield([
                ('text', 'Dit is onze mooie text'),
                ('rich_text', rich_text('<p>Dit is onze mooie text in een ferrari</p>')),
                ('product', {'name': 'pegs', 'price': 'a pound'}),
            ]),
        }))

        self.assertCanCreate(self.root, SectionedRichTextPage, nested_form_data({
            'title': 'Fight Club',
            'sections': inline_formset([
                {'body': rich_text('<p>Rule 1: You do not talk about Fight Club</p>')},
                {'body': rich_text('<p>Rule 2: You DO NOT talk about Fight Club</p>')},
            ]),
        }))
Exemplo n.º 3
0
    def test_inline_formset(self):
        result = nested_form_data({
            "lines":
            inline_formset([
                {
                    "text": "Hello"
                },
                {
                    "text": "World"
                },
            ])
        })

        self.assertEqual(
            result,
            {
                "lines-TOTAL_FORMS": "2",
                "lines-INITIAL_FORMS": "0",
                "lines-MIN_NUM_FORMS": "0",
                "lines-MAX_NUM_FORMS": "1000",
                "lines-0-text": "Hello",
                "lines-0-ORDER": "0",
                "lines-0-DELETE": "",
                "lines-1-text": "World",
                "lines-1-ORDER": "1",
                "lines-1-DELETE": "",
            },
        )
Exemplo n.º 4
0
 def test_can_create_plant_collections(self):
     self.assertCanCreate(
         self.home, PlantCollectionsPage,
         nested_form_data({
             'title': 'Plant Collections Test Page',
             'intro': rich_text('Testing!'),
             'more_info_modal': rich_text('Testing!'),
             'plant_collections': inline_formset([])
         }))
Exemplo n.º 5
0
    def test_assert_can_create_with_form_helpers(self):
        # same as test_assert_can_create, but using the helpers from wagtail.tests.utils.form_data
        # as an end-to-end test
        self.assertFalse(EventIndex.objects.exists())
        self.assertCanCreate(
            self.root,
            EventIndex,
            nested_form_data({
                "title": "Event Index",
                "intro": rich_text("<p>Event intro</p>")
            }),
        )
        self.assertTrue(EventIndex.objects.exists())

        self.assertCanCreate(
            self.root,
            StreamPage,
            nested_form_data({
                "title":
                "Flierp",
                "body":
                streamfield([
                    ("text", "Dit is onze mooie text"),
                    (
                        "rich_text",
                        rich_text(
                            "<p>Dit is onze mooie text in een ferrari</p>"),
                    ),
                    ("product", {
                        "name": "pegs",
                        "price": "a pound"
                    }),
                ]),
            }),
        )

        self.assertCanCreate(
            self.root,
            SectionedRichTextPage,
            nested_form_data({
                "title":
                "Fight Club",
                "sections":
                inline_formset([
                    {
                        "body":
                        rich_text(
                            "<p>Rule 1: You do not talk about Fight Club</p>")
                    },
                    {
                        "body":
                        rich_text(
                            "<p>Rule 2: You DO NOT talk about Fight Club</p>")
                    },
                ]),
            }),
        )
Exemplo n.º 6
0
    def test_application_not_empty_on_error(self):
        """
        Submit an application where the cover letter and qualifications
        are valid but the references are invalid. The cover letter and
        qualifications should not be empty after the submission.
        """
        role = Role.objects.create(
            name_en='Test Role',
            name_sv='Test Roll',
            group=self.group,
            role_type='engaged',
        )
        position = Position.objects.create(
            role=role,
            recruitment_start=date.today() - timedelta(days=1),
            recruitment_end=date.today(),
            term_from=date.today() + timedelta(days=1),
            term_to=date.today() + timedelta(days=365),
        )
        url = \
            self.page.url + \
            self.page.reverse_subpage(
                'position',
                [position.id]
            )

        application_data = {
            "cover_letter": "This is my cover letter",
            "qualifications": "These are my qualifications",
            "status": "submitted"
        }

        invalid_reference_form = nested_form_data({
            'references':
            inline_formset([{
                'name': '',
                'position': '',
                'email': '',
                'phone_number': '',
                'comment': 'Is a cool person'
            }])
        })

        # Merge application data with reference form data
        post_data = {**application_data, **invalid_reference_form}

        response = self.client.post(url, post_data)

        self.assertNotEqual(response.status_code, 302)
        self.assertContains(response, application_data['cover_letter'])
        self.assertContains(response, application_data['qualifications'])
Exemplo n.º 7
0
    def test_inline_formset(self):
        result = nested_form_data({'lines': inline_formset([
            {'text': 'Hello'},
            {'text': 'World'},
        ])})

        self.assertEqual(
            result,
            {
                'lines-TOTAL_FORMS': '2',
                'lines-INITIAL_FORMS': '0',
                'lines-MIN_NUM_FORMS': '0',
                'lines-MAX_NUM_FORMS': '1000',
                'lines-0-text': 'Hello',
                'lines-0-ORDER': '0',
                'lines-0-DELETE': '',
                'lines-1-text': 'World',
                'lines-1-ORDER': '1',
                'lines-1-DELETE': '',
            }
        )
Exemplo n.º 8
0
    def setUp(self):
        super().setUp()
        self.user = UserFactory(is_superuser=True)
        self.client.force_login(self.user)
        self.home_page = HomePage.objects.first()
        self.student_index = StudentIndexPageFactory(
            parent=self.home_page,
            title="Students",
            slug="students",
            introduction="students",
        )
        self.student = User.objects.create_user(
            username="******",
            first_name="fox",
            last_name="mulder",
            email="*****@*****.**",
            password="******",
        )
        self.collection = CollectionFactory(name="Student: fox mulder")

        student_group = Group.objects.get(name="Students")
        # Add the student group
        self.student.groups.add(student_group)
        self.student.save()

        self.post_data = {
            "title": "Fox Mulder",
            "slug": "fox",
            "student_title": "Dr",
            "first_name": "Fox",
            "last_name": "Mulder",
            "profile_image": "",
            "email": "",
            "programme": "",
            "degree_start_date": "",
            "degree_end_date": "",
            "degree_status": "",
            "link_to_final_thesis": "",
            "related_supervisor-TOTAL_FORMS": "0",
            "related_supervisor-INITIAL_FORMS": "0",
            "related_supervisor-MIN_NUM_FORMS": "0",
            "related_supervisor-MAX_NUM_FORMS": "1000",
            "introduction": "",
            "bio": rich_text(""),
            "related_project_pages-TOTAL_FORMS": "0",
            "related_project_pages-INITIAL_FORMS": "0",
            "related_project_pages-MIN_NUM_FORMS": "0",
            "related_project_pages-MAX_NUM_FORMS": "5",
            "gallery_slides-TOTAL_FORMS": "0",
            "gallery_slides-INITIAL_FORMS": "0",
            "gallery_slides-MIN_NUM_FORMS": "0",
            "gallery_slides-MAX_NUM_FORMS": "5",
            "biography": rich_text(""),
            "degrees": rich_text(""),
            "experience": rich_text(""),
            "awards": rich_text(""),
            "funding": rich_text(""),
            "exhibitions": rich_text(""),
            "publications": rich_text(""),
            "research_outputs": rich_text(""),
            "conferences": rich_text(""),
            "additional_information_title": "",
            "addition_information_content": rich_text(""),
            "relatedlinks-TOTAL_FORMS": "0",
            "relatedlinks-INITIAL_FORMS": "0",
            "relatedlinks-MIN_NUM_FORMS": "0",
            "relatedlinks-MAX_NUM_FORMS": "5",
            "related_area_of_expertise-TOTAL_FORMS": "0",
            "related_area_of_expertise-INITIAL_FORMS": "0",
            "related_area_of_expertise-MIN_NUM_FORMS": "0",
            "related_area_of_expertise-MAX_NUM_FORMS": "1000",
            "related_research_centre_pages-TOTAL_FORMS": "0",
            "related_research_centre_pages-INITIAL_FORMS": "0",
            "related_research_centre_pages-MIN_NUM_FORMS": "0",
            "related_research_centre_pages-MAX_NUM_FORMS": "1000",
            "related_schools-TOTAL_FORMS": "0",
            "related_schools-INITIAL_FORMS": "0",
            "related_schools-MIN_NUM_FORMS": "0",
            "related_schools-MAX_NUM_FORMS": "1000",
            "personal_links-TOTAL_FORMS": "0",
            "personal_links-INITIAL_FORMS": "0",
            "personal_links-MIN_NUM_FORMS": "0",
            "personal_links-MAX_NUM_FORMS": "5",
            "related_project_pages": inline_formset([]),
            "gallery_slides": inline_formset([]),
            "related_supervisor": inline_formset([]),
            "relatedlinks": inline_formset([]),
            "related_area_of_expertise": inline_formset([]),
            "related_research_centre_pages": inline_formset([]),
            "related_schools": inline_formset([]),
            "personal_links": inline_formset([]),
            "student_funding": rich_text(""),
            "seo_title": "",
            "show_in_menus": "on",
            "search_description": "",
            "social_image": "",
            "social_text": "",
            "listing_image": "",
            "listing_title": "",
            "listing_summary": "",
            "go_live_at": "",
            "expire_at": "",
            "student_user_image_collection": "",
            "student_user_account": "",
        }