"""
Functional tests for testing page content.

Note that [tests can not assert on the status code due to bug in selenium based webdriver tests]
(https://github.com/cobrateam/splinter/issues/509)

:copyright: Copyright 2013-2017, Dorian Pula <dorian.pula@amber-penguin-software.ca>
:license: AGPL v3+
"""

import pytest

from tests import utils

TEST_PAGE_TITLE = 'License'
TEST_PAGE_CONTENT = '''
# License (AGPL)
This is the text of the AGPL.
'''


@pytest.fixture(scope='module')
def test_page(db):
    return utils.generate_test_page(
        db, title=TEST_PAGE_TITLE, content=TEST_PAGE_CONTENT)


@pytest.fixture(scope='session')
def splinter_driver_kwargs():
    return {
        'browser': 'firefox',
        'platform': 'Linux',
        'name': 'Rookeries Test Basic Setup',
    }

# TODO: Add in tests to login via form.


def test_basic_page_setup_returns_page_not_found_on_unknown_page(
        browser, api_base_uri):
    unknown_test_page = utils.generate_random_suffix()
    browser.visit(f'{api_base_uri}/{unknown_test_page}')

    assert browser.title == 'Unknown Page - Rookeries'
    # TODO: Fix error page for Rookeries app.
    # page_title = browser.find_by_css('h1')[2]
    # assert page_title.text == f'"{unknown_test_page}" Page Not Found'


def test_basic_page_setup_on_known_page(browser, api_base_uri, test_page):
    browser.visit(f'{api_base_uri}/{test_page.slug}')

    assert browser.title == 'License - Rookeries'
    page_title = browser.find_by_css('h1')[2]
    assert page_title.text == 'License (AGPL)'
