-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathannouncements_test.py
119 lines (97 loc) · 2.69 KB
/
announcements_test.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import pytest
from requests.exceptions import HTTPError
from ocflib.lab.announcements import get_all_announcements
from ocflib.lab.announcements import get_announcement
from ocflib.lab.announcements import get_metadata
TEST_FOLDER = 'tests'
TEST_IDS = [
'2002-01-01-00',
'2002-01-01-01',
'2002-01-02-00',
'2023-09-01-00',
'2023-10-01-00',
'2023-11-01-00',
]
# scope = module means that the fixture is only run once per module
@pytest.fixture(scope='module')
def get_all() -> [str]:
return get_all_announcements(folder=TEST_FOLDER)
# scope = module means that the fixture is only run once per module
@pytest.fixture(scope='module')
def announcement_data():
# Fetch data once for all tests in this module
return {id: get_announcement(id, folder=TEST_FOLDER) for id in TEST_IDS}
# Health check
@pytest.mark.parametrize(
'id',
TEST_IDS,
)
def test_get_announcement_pass(id):
assert 'testing' in get_announcement(id, folder=TEST_FOLDER)
# Those ids are invalid
@pytest.mark.parametrize(
'id',
[
'2002-01-00-00212',
'2002-01-01-aa',
'2002-01-02-21a',
'2002-223-02-00',
'2002-01-80-00',
],
)
def test_get_announcement_bad_id(id):
with pytest.raises(ValueError):
get_announcement(id, folder=TEST_FOLDER)
# Those announcements don't exist in the test folder
@pytest.mark.parametrize(
'id',
[
'2002-01-01-10',
'2002-01-01-12',
'2002-01-02-30',
],
)
def test_get_announcement_fail(id):
with pytest.raises(HTTPError):
get_announcement(id, folder=TEST_FOLDER)
# Those ids are valid
@pytest.mark.parametrize('id', TEST_IDS)
def test_get_id_pass(id, get_all):
found = False
for post in get_all:
if id == post:
found = True
break
assert found, f'ID {id} not found in announcements'
# Those ids don't exist in the test folder
@pytest.mark.parametrize(
'id',
[
'2002-01-01-10',
'2002-01-01-12',
'2002-01-02-30',
],
)
def test_get_id_fail(id, get_all):
for post in get_all:
assert id != post, f'Unexpected ID {id} found in announcements'
@pytest.mark.parametrize('id', TEST_IDS)
def test_get_metadata_pass(id, announcement_data):
content = announcement_data[id]
assert 'Victor' == get_metadata(content).author, 'author not found in metadata'
def test_get_metadata_missing_metadata():
content = """
---
title: test
date: 2020-01-01
---
"""
with pytest.raises(ValueError):
get_metadata(content)
def test_get_metadata_bad_format():
content = """
title: test
date: 2020-01-01
"""
with pytest.raises(ValueError):
get_metadata(content)