# -*- coding: utf-8 -*-
from {{{package.dottedname}}}.testing import {{{package.uppercasename}}}_FUNCTIONAL_TESTING
from {{{package.dottedname}}}.testing import {{{package.uppercasename}}}_INTEGRATION_TESTING
from {{{package.dottedname}}}.views.{{{view_python_file_name}}} import I{{{ view_python_class_name }}}
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from zope.component import getMultiAdapter
from zope.interface.interfaces import ComponentLookupError

import unittest


class ViewsIntegrationTest(unittest.TestCase):

    layer = {{{package.uppercasename}}}_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        api.content.create(self.portal, 'Folder', 'other-folder')
        api.content.create(self.portal, 'Document', 'front-page')

    def test_{{{view_name_normalized}}}_is_registered(self):
        view = getMultiAdapter(
            (self.portal['other-folder'], self.portal.REQUEST),
            name='{{{ view_name }}}'
        )
        self.assertTrue(I{{{ view_python_class_name }}}.providedBy(view))

    def test_{{{view_name_normalized}}}_not_matching_interface(self):
        view_found = True
        try:
            view = getMultiAdapter(
                (self.portal['front-page'], self.portal.REQUEST),
                name='{{{ view_name }}}'
            )
        except ComponentLookupError:
            view_found = False
        else:
            view_found = I{{{ view_python_class_name }}}.providedBy(view)
        self.assertFalse(view_found)


class ViewsFunctionalTest(unittest.TestCase):

    layer = {{{package.uppercasename}}}_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
