Passed
Push — master ( 00d837...bc5250 )
by Jace
49s
created

describe_display()   F

Complexity

Conditions 9

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 9
c 5
b 0
f 0
dl 0
loc 37
rs 3
1
# pylint: disable=unused-variable,expression-not-assigned
2
3
from unittest.mock import patch, call, Mock
4
5
import pytest
6
from expecter import expect
7
8
from memegen.factory import create_app
9
from memegen.settings import get_config
10
from memegen.routes._utils import display
11
12
13
def describe_display():
14
15
    @pytest.fixture
16
    def app():
17
        app = create_app(get_config('test'))
18
        app.config['GOOGLE_ANALYTICS_TID'] = 'my_tid'
19
        return app
20
21
    request_image = Mock(url="it's a path")
22
    request_image.headers.get = Mock(return_value="(not a browser)")
23
    request_image.base_url = "it's a path"
24
    request_image.args = {}
25
26
    request_share = Mock(url="it's a path?alt=style&share=true")
27
    request_share.headers.get = Mock(return_value="*/*")
28
    request_share.base_url = "it's a path"
29
    request_share.args = {'alt': ['style'], 'share': ['true']}
30
31
    @patch('memegen.routes._utils.send_file')
32
    @patch('memegen.routes._utils.request', request_image)
33
    def it_returns_an_image_otherwise(mock_send_file, app):
34
        with app.test_request_context():
35
            display("my_title", "my_path")
36
37
        expect(mock_send_file.mock_calls) == [
38
            call("my_path", mimetype='image/jpeg'),
39
        ]
40
41
    @patch('memegen.routes._utils.request', request_share)
42
    def it_returns_html_when_sharing(app):
43
        with app.test_request_context():
44
            html = display("my_title", "my_path", share=True, raw=True)
45
46
        print(html)
47
        assert "<title>my_title</title>" in html
48
        assert 'src="it\'s a path?alt=style"' in html
49
        assert "ga('create', 'my_tid', 'auto');" in html
50