Completed
Push — master ( 156c71...ff0da6 )
by Jace
10:32
created

describe_display()   D

Complexity

Conditions 8

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 8
dl 0
loc 37
rs 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A it_returns_an_image_otherwise() 0 12 1
B it_returns_html_for_browsers() 0 10 5
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
0 ignored issues
show
Configuration introduced by
The import expecter could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
7
8
from memegen.app import create_app
9
from memegen.settings import get_config
10
from memegen.routes._common 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_html = Mock(path="it's a path")
22
    request_html.headers.get = Mock(return_value="text/html")
23
24
    request_image = Mock(path="it's a path")
25
    request_image.headers.get = Mock(return_value="(not a browser)")
26
27
    @patch('memegen.routes._common.request', request_html)
28
    def it_returns_html_for_browsers(app):
29
30
        with app.test_request_context():
31
            html = display("my_title", "my_path", raw=True)
32
33
        print(html)
34
        assert "<title>my_title</title>" in html
35
        assert 'url("it\'s a path")' in html
36
        assert "ga('create', 'my_tid', 'auto');" in html
37
38
    @patch('memegen.routes._common._track')
39
    @patch('memegen.routes._common.send_file')
40
    @patch('memegen.routes._common.request', request_image)
41
    def it_returns_an_image_otherwise(mock_send_file, mock_track):
42
43
        display("my_title", "my_path")
44
45
        expect(mock_track.mock_calls) == [
46
            call("my_title"),
47
        ]
48
        expect(mock_send_file.mock_calls) == [
49
            call("my_path", mimetype='image/jpeg'),
50
        ]
51