def it_knows_when_it_has_a_header_part_to_help(self, has_definition_fixture):
        sectPr, expected_value = has_definition_fixture
        header = _Header(sectPr, None, WD_HEADER_FOOTER.FIRST_PAGE)

        has_definition = header._has_definition

        assert has_definition is expected_value
    def but_it_returns_None_when_its_the_first_header(self):
        doc_elm = element("w:document/w:sectPr")
        sectPr = doc_elm[0]
        header = _Header(sectPr, None, None)

        prior_header = header._prior_headerfooter

        assert prior_header is None
    def it_knows_when_it_has_a_header_part_to_help(self,
                                                   has_definition_fixture):
        sectPr, expected_value = has_definition_fixture
        header = _Header(sectPr, None, WD_HEADER_FOOTER.FIRST_PAGE)

        has_definition = header._has_definition

        assert has_definition is expected_value
    def but_it_returns_None_when_its_the_first_header(self):
        doc_elm = element("w:document/w:sectPr")
        sectPr = doc_elm[0]
        header = _Header(sectPr, None, None)

        prior_header = header._prior_headerfooter

        assert prior_header is None
    def it_can_drop_the_related_header_part_to_help(self, document_part_):
        sectPr = element("w:sectPr{r:a=b}/w:headerReference{w:type=even,r:id=rId42}")
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.EVEN_PAGE)

        header._drop_definition()

        assert sectPr.xml == xml("w:sectPr{r:a=b}")
        document_part_.drop_header_part.assert_called_once_with("rId42")
    def it_can_drop_the_related_header_part_to_help(self, document_part_):
        sectPr = element(
            "w:sectPr{r:a=b}/w:headerReference{w:type=even,r:id=rId42}")
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.EVEN_PAGE)

        header._drop_definition()

        assert sectPr.xml == xml("w:sectPr{r:a=b}")
        document_part_.drop_header_part.assert_called_once_with("rId42")
    def it_provides_access_to_its_header_part_to_help(self, document_part_,
                                                      header_part_):
        sectPr = element(
            "w:sectPr/w:headerReference{w:type=default,r:id=rId8}")
        document_part_.header_part.return_value = header_part_
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.PRIMARY)

        header_part = header._definition

        document_part_.header_part.assert_called_once_with("rId8")
        assert header_part is header_part_
    def it_can_add_a_header_part_to_help(self, document_part_, header_part_):
        sectPr = element("w:sectPr{r:a=b}")
        document_part_.add_header_part.return_value = header_part_, "rId3"
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.FIRST_PAGE)

        header_part = header._add_definition()

        document_part_.add_header_part.assert_called_once_with()
        assert sectPr.xml == xml(
            "w:sectPr{r:a=b}/w:headerReference{w:type=first,r:id=rId3}")
        assert header_part is header_part_
    def it_provides_access_to_its_header_part_to_help(
        self, document_part_, header_part_
    ):
        sectPr = element("w:sectPr/w:headerReference{w:type=default,r:id=rId8}")
        document_part_.header_part.return_value = header_part_
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.PRIMARY)

        header_part = header._definition

        document_part_.header_part.assert_called_once_with("rId8")
        assert header_part is header_part_
    def it_can_add_a_header_part_to_help(self, document_part_, header_part_):
        sectPr = element("w:sectPr{r:a=b}")
        document_part_.add_header_part.return_value = header_part_, "rId3"
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.FIRST_PAGE)

        header_part = header._add_definition()

        document_part_.add_header_part.assert_called_once_with()
        assert sectPr.xml == xml(
            "w:sectPr{r:a=b}/w:headerReference{w:type=first,r:id=rId3}"
        )
        assert header_part is header_part_
    def it_provides_access_to_the_prior_Header_to_help(
        self, request, document_part_, header_
    ):
        doc_elm = element("w:document/(w:sectPr,w:sectPr)")
        prior_sectPr, sectPr = doc_elm[0], doc_elm[1]
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.PRIMARY)
        # ---mock must occur after construction of "real" header---
        _Header_ = class_mock(request, "docx.section._Header", return_value=header_)

        prior_header = header._prior_headerfooter

        _Header_.assert_called_once_with(
            prior_sectPr, document_part_, WD_HEADER_FOOTER.PRIMARY
        )
        assert prior_header is header_
    def it_provides_access_to_the_prior_Header_to_help(self, request,
                                                       document_part_,
                                                       header_):
        doc_elm = element("w:document/(w:sectPr,w:sectPr)")
        prior_sectPr, sectPr = doc_elm[0], doc_elm[1]
        header = _Header(sectPr, document_part_, WD_HEADER_FOOTER.PRIMARY)
        # ---mock must occur after construction of "real" header---
        _Header_ = class_mock(request,
                              "docx.section._Header",
                              return_value=header_)

        prior_header = header._prior_headerfooter

        _Header_.assert_called_once_with(prior_sectPr, document_part_,
                                         WD_HEADER_FOOTER.PRIMARY)
        assert prior_header is header_