-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
91 lines (78 loc) · 2.98 KB
/
test_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from src.app import insert_data_in_template, _get
import pytest
def test_insert_data_in_template():
html = """
<html>
<body>
<img src="{artist.image}" alt="Artist Image">
<h1>{track.name}</h1>
<p>Artist: {track.artist}</p>
<img src="{track.image}" alt="Track Image">
<a href="{track.url}">Listen to Track</a>
<a href="{playlist.public_url}">View Playlist</a>
<h2>{playlist.name}</h2>
<h3>{index.title}</h3>
<link rel="icon" href="{index.favicon}">
<a href="{icon.github}">GitHub</a>
<a href="{icon.linkedin}">LinkedIn</a>
<a href="{track.addedBy.url}">{track.addedBy.name}</a>
</body>
</html>
"""
track_data = {
"artist_image_url": "https://example.com/artist_image.jpg",
"track_name": "Track Name",
"artist_names": "Artist Name",
"track_image_url": "https://example.com/track_image.jpg",
"track_url": "https://example.com/track_url",
"added_by_public_url": "https://example.com/user",
"added_by_name": "Tony Montana",
}
playlist_info = {
"public_url": "https://example.com/playlist",
"name": "Playlist Name",
}
environment = {
"TITLE": "Page Title",
"FAVICON_URL": "https://example.com/favicon.ico",
"GITHUB": "https://github.com/example",
"LINKEDIN": "https://linkedin.com/example",
}
expected_result = """
<html>
<body>
<img src="https://example.com/artist_image.jpg" alt="Artist Image">
<h1>Track Name</h1>
<p>Artist: Artist Name</p>
<img src="https://example.com/track_image.jpg" alt="Track Image">
<a href="https://example.com/track_url">Listen to Track</a>
<a href="https://example.com/playlist">View Playlist</a>
<h2>Playlist Name</h2>
<h3>Page Title</h3>
<link rel="icon" href="https://example.com/favicon.ico">
<a href="https://github.com/example">GitHub</a>
<a href="https://linkedin.com/example">LinkedIn</a>
<a href="https://example.com/user">Tony Montana</a>
</body>
</html>
"""
result = insert_data_in_template(html, track_data, environment, playlist_info)
assert result == expected_result
def test_get():
obj = {
"key1": "value1",
"key2": "value2",
}
# should return value
result = _get(obj, "key1")
assert result == "value1"
# should return None because throw is implicitly False
result = _get(obj, "key3")
assert result == None
# should throw when key is missing
with pytest.raises(Exception) as exc_info:
_get(obj, "key3", throw=True)
assert str(exc_info.value) == "'key3' key was not found in dictionary"
# should return default value because throw is implicitly False
result = _get(obj, "key3", default_value="default")
assert result == "default"