|
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.app 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_html = Mock(url="it's a path?alt=style") |
|
22
|
|
|
request_html.headers.get = Mock(return_value="text/html") |
|
23
|
|
|
|
|
24
|
|
|
request_image = Mock(url="it's a path") |
|
25
|
|
|
request_image.headers.get = Mock(return_value="(not a browser)") |
|
26
|
|
|
|
|
27
|
|
|
request_share = Mock(url="it's a path?alt=style&share=true") |
|
28
|
|
|
request_share.headers.get = Mock(return_value="*/*") |
|
29
|
|
|
|
|
30
|
|
|
@patch('memegen.routes._utils.request', request_html) |
|
31
|
|
|
def it_returns_html_for_browsers(app): |
|
32
|
|
|
|
|
33
|
|
|
with app.test_request_context(): |
|
34
|
|
|
html = display("my_title", "my_path", raw=True) |
|
35
|
|
|
|
|
36
|
|
|
print(html) |
|
37
|
|
|
assert "<title>my_title</title>" in html |
|
38
|
|
|
assert 'url("it\'s a path?alt=style")' in html |
|
39
|
|
|
assert "ga('create', 'my_tid', 'auto');" in html |
|
40
|
|
|
|
|
41
|
|
|
@patch('memegen.routes._utils.send_file') |
|
42
|
|
|
@patch('memegen.routes._utils.request', request_image) |
|
43
|
|
|
def it_returns_an_image_otherwise(mock_send_file): |
|
44
|
|
|
|
|
45
|
|
|
display("my_title", "my_path") |
|
46
|
|
|
|
|
47
|
|
|
expect(mock_send_file.mock_calls) == [ |
|
48
|
|
|
call("my_path", mimetype='image/jpeg'), |
|
49
|
|
|
] |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
@patch('memegen.routes._utils.request', request_share) |
|
53
|
|
|
def it_returns_html_when_sharing(app): |
|
54
|
|
|
|
|
55
|
|
|
with app.test_request_context(): |
|
56
|
|
|
html = display("my_title", "my_path", share=True, raw=True) |
|
57
|
|
|
|
|
58
|
|
|
print(html) |
|
59
|
|
|
assert "<title>my_title</title>" in html |
|
60
|
|
|
assert 'url("it\'s a path?alt=style&share=true")' in html |
|
61
|
|
|
assert "ga('create', 'my_tid', 'auto');" in html |
|
62
|
|
|
|
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.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.