test/test_templates.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 24 Feb 2017 14:36:49 +0100
changeset 181 12721d10d5bd
child 182 c2b5337dbc99
permissions -rw-r--r--
Replace navigation box by top-level buttons with proper activation detection.

# copyright 2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from cubicweb.devtools.testlib import CubicWebTC

from cubicweb_sherpa.views.templates import _compute_active_path


def create_archive_unit(parent, title=None, **kwargs):
    """Create an archive unit and its mandatory children and return them.
    """
    cnx = kwargs.pop('cnx', getattr(parent, '_cw', None))
    kwargs.setdefault('user_annotation', u'archive unit title')
    au = cnx.create_entity('SEDAArchiveUnit', seda_archive_unit=parent, **kwargs)
    alt = cnx.create_entity('SEDAAltArchiveUnitArchiveUnitRefId',
                            reverse_seda_alt_archive_unit_archive_unit_ref_id=au)
    last = cnx.create_entity(
        'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
        reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt)
    cnx.create_entity('SEDATitle', seda_title=last, title=title)
    return au, alt, last


class ActivePathTC(CubicWebTC):

    def test_archive_transfer(self):
        with self.admin_access.cnx() as cnx:
            at = cnx.create_entity('SEDAArchiveTransfer', title=u'hop')
            au, alt, last = create_archive_unit(at)
            cnx.commit()

            for entity in (at, au, alt, last):
                with self.subTest(entity=entity):
                    self.assertEqual(_compute_active_path(entity.as_rset()),
                                     'sedaarchivetransfer')

    def test_archive_unit(self):
        with self.admin_access.cnx() as cnx:
            au, alt, last = create_archive_unit(None, cnx=cnx)
            cnx.commit()

            for entity in (au, alt, last):
                with self.subTest(entity=entity):
                    self.assertEqual(_compute_active_path(entity.as_rset()),
                                     'sedalib')

    def test_authority_record(self):
        with self.admin_access.cnx() as cnx:
            org_kind = cnx.find('AgentKind', name=u'authority').one()
            record = cnx.create_entity('AuthorityRecord', agent_kind=org_kind)
            cnx.create_entity('NameEntry', parts=u'record', form_variant=u'authorized',
                              name_entry_for=record)
            cnx.commit()

            self.assertEqual(_compute_active_path(record.as_rset()),
                             'authorityrecord')

    def test_concept_scheme(self):
        with self.admin_access.cnx() as cnx:
            scheme = cnx.create_entity('ConceptScheme', title=u'vocabulary')
            concept = scheme.add_concept(u'concept')
            cnx.commit()

            for entity in (scheme, concept):
                with self.subTest(entity=entity):
                    self.assertEqual(_compute_active_path(entity.as_rset()),
                                     'conceptscheme')


if __name__ == '__main__':
    import unittest
    unittest.main()