Добавлены тесты для задачи [#22]
parent
7d3e770cdd
commit
255aa9b57a
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
title: Заглушка для тестов БД
|
title: Заглушка для тестов БД
|
||||||
description: Тестовая страница
|
description: Тестовая страница
|
||||||
template: onepage
|
template: tests:templates/test_markdown
|
||||||
---
|
---
|
||||||
|
|
||||||
Hello World!
|
Hello World!
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
title: Тест одиночного view
|
||||||
|
description: Тесты view
|
||||||
|
template: tests:templates/test_markdown
|
||||||
|
view: tests.views.test1
|
||||||
|
---
|
||||||
|
|
||||||
|
Hello World!
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
title: Тест нескольких view с конфигурацией
|
||||||
|
description: Тесты view
|
||||||
|
template: tests:templates/test_markdown
|
||||||
|
view:
|
||||||
|
- tests.views.test1
|
||||||
|
- tests.views.test2
|
||||||
|
- tests.views.test3:
|
||||||
|
a: 1
|
||||||
|
b: 2
|
||||||
|
---
|
||||||
|
|
||||||
|
Hello World!
|
|
@ -0,0 +1 @@
|
||||||
|
{{content}}
|
|
@ -2,15 +2,55 @@ import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pages():
|
def current_directory():
|
||||||
|
from pathlib import Path
|
||||||
|
return Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pages(current_directory):
|
||||||
from flatfilecms.resources import Root
|
from flatfilecms.resources import Root
|
||||||
return Root('../tests/pages', '../tests/data')
|
return Root(
|
||||||
|
str(current_directory / 'pages'),
|
||||||
|
str(current_directory / 'data'))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def request():
|
||||||
|
from pyramid.testing import DummyRequest
|
||||||
|
return DummyRequest()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def config(current_directory):
|
||||||
|
from pyramid.testing import testConfig
|
||||||
|
with testConfig() as config:
|
||||||
|
config.include('pyramid_jinja2')
|
||||||
|
yield config
|
||||||
|
|
||||||
|
|
||||||
def test_loading(pages):
|
def test_loading(pages):
|
||||||
assert 'index' in pages
|
assert 'index' in pages
|
||||||
|
|
||||||
|
|
||||||
def test_db_contains_pages(pages):
|
def test_loading_markdown(pages):
|
||||||
assert pages['index'].page['title'] == 'Заглушка для тестов БД'
|
assert pages['index'].page['title'] == 'Заглушка для тестов БД'
|
||||||
pass
|
|
||||||
|
|
||||||
|
def test_generating_markdown(pages, request, config):
|
||||||
|
from flatfilecms.views.pages import PagesView
|
||||||
|
view = PagesView(pages['index'], request)
|
||||||
|
assert view.process_yaml().text == 'Hello World!'
|
||||||
|
|
||||||
|
|
||||||
|
def test_view(pages, request, config):
|
||||||
|
from flatfilecms.views.pages import PagesView
|
||||||
|
view = PagesView(pages['view'], request)
|
||||||
|
assert view.process_yaml().text == 'Hello World! View1'
|
||||||
|
|
||||||
|
|
||||||
|
def test_views(pages, request, config):
|
||||||
|
from flatfilecms.views.pages import PagesView
|
||||||
|
view = PagesView(pages['views'], request)
|
||||||
|
assert view.process_yaml().text == \
|
||||||
|
'Hello World! View1 View2 View3(a:1, b:2)'
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
def test1(self):
|
||||||
|
self.context.page['content'] += ' View1'
|
||||||
|
|
||||||
|
|
||||||
|
def test2(self):
|
||||||
|
self.context.page['content'] += ' View2'
|
||||||
|
|
||||||
|
|
||||||
|
def test3(self, a, b):
|
||||||
|
self.context.page['content'] += f' View3(a:{a}, b:{b})'
|
Reference in New Issue