import pytest

from django.test import Client
from django.utils import timezone

pytestmark = pytest.mark.django_db


class TestRendererFormView:

    def test_get_empty_form(self, client: Client):
        response = client.get('/renderer/')
        assert response.status_code == 200
        assert response.context['form']['date'].value() \
               == timezone.now().strftime('%Y-%m-%d')

    def test_render(self, client: Client):
        response = client.post('/renderer/render', data={
            'title': 'Sample Title',
            'date': '2009-11-15',
            'render_content': '# Example'
        })
        assert b'Sample Title' in response.content
        assert b'Example' in response.content
        assert response.content.startswith(b'%PDF')

    def test_html_render(self, client: Client):
        response = client.post('/renderer/renderhtml', data={
            'title': 'Sample Title',
            'date': '2009-11-15',
            'render_content': '# Example',
            'show_title': 'on',
        })
        assert b'Sample Title' in response.content
        assert b'<h1>Sample Title</h1>' in response.content
        assert b'Example' in response.content

    def test_hiding_title(self, client: Client):
        response = client.post('/renderer/renderhtml', data={
            'title': 'Sample Title',
            'date': '2009-11-15',
            'render_content': '# Example'
        })
        assert b'Sample Title' in response.content
        assert b'<h1>Sample Title</h1>' not in response.content
        assert b'Example' in response.content
