|
@@ 60-76 (lines=17) @@
|
| 57 |
|
def it_handles_invalid_paths(template): |
| 58 |
|
expect(template.get_path("@#$%^")) == None |
| 59 |
|
|
| 60 |
|
def describe_path(): |
| 61 |
|
|
| 62 |
|
def is_returned_when_file_exists(template): |
| 63 |
|
template.root = "my_root" |
| 64 |
|
|
| 65 |
|
with patch('pathlib.Path.is_file', Mock(return_value=True)): |
| 66 |
|
path = template.path |
| 67 |
|
|
| 68 |
|
expect(path) == Path("my_root/abc/default.png") |
| 69 |
|
|
| 70 |
|
def is_none_when_no_file(template): |
| 71 |
|
template.root = "my_root" |
| 72 |
|
|
| 73 |
|
with patch('pathlib.Path.is_file', Mock(return_value=False)): |
| 74 |
|
path = template.path |
| 75 |
|
|
| 76 |
|
expect(path) == None |
| 77 |
|
|
| 78 |
|
def describe_default_path(): |
| 79 |
|
|
|
@@ 154-169 (lines=16) @@
|
| 151 |
|
with patch('requests.head', Mock(return_value=mock_response)): |
| 152 |
|
template.link = "example.com/fake" |
| 153 |
|
|
| 154 |
|
expect(template.validate_link()) == False |
| 155 |
|
|
| 156 |
|
@patch('pathlib.Path.is_file', Mock(return_value=True)) |
| 157 |
|
def with_cached_valid_link(template): |
| 158 |
|
template.link = "already_cached_site.com" |
| 159 |
|
|
| 160 |
|
expect(template.validate_link()) == True |
| 161 |
|
|
| 162 |
|
def describe_validate_size(): |
| 163 |
|
|
| 164 |
|
@pytest.mark.parametrize('dimensions,valid', [ |
| 165 |
|
((Template.MIN_WIDTH, Template.MIN_HEIGHT), True), |
| 166 |
|
((Template.MIN_WIDTH - 1, Template.MIN_HEIGHT), False), |
| 167 |
|
((Template.MIN_WIDTH, Template.MIN_HEIGHT - 1), False), |
| 168 |
|
((Template.MIN_WIDTH - 1, Template.MIN_HEIGHT - 1), False), |
| 169 |
|
]) |
| 170 |
|
@patch('PIL.Image.open') |
| 171 |
|
def with_various_dimenions(mock_open, template, dimensions, valid): |
| 172 |
|
mock_img = Mock() |