1
- # Update this file from a profile with:
2
- # curl https://raw.githubusercontent.com/open-contracting/standard_profile_template/master/tests/test_common.py -o tests/test_common.py # noqa
1
+ import os
3
2
import re
4
3
import time
4
+ import warnings
5
5
6
6
import pytest
7
7
import requests
8
8
from selenium .common .exceptions import NoSuchElementException
9
9
from selenium .webdriver .support .ui import Select
10
10
11
- from . import languages , test_basic_params , test_search_params
11
+ from tests import languages , test_basic_params , test_search_params
12
+
13
+ cwd = os .getcwd ()
14
+
15
+
16
+ def custom_warning_formatter (message , category , filename , lineno , line = None ):
17
+ return str (message ).replace (cwd + os .sep , '' )
18
+
19
+
20
+ warnings .formatwarning = custom_warning_formatter
12
21
13
22
14
23
@pytest .mark .parametrize ('lang,text' , test_basic_params .items ())
@@ -44,6 +53,7 @@ def test_broken_links(browser, server, lang):
44
53
referrer = ''
45
54
hrefs = set ()
46
55
browser .get ('{}{}' .format (server , lang ))
56
+ failures = []
47
57
while True :
48
58
for link in browser .find_elements_by_partial_link_text ('' ):
49
59
href = re .sub (r'#.*$' , '' , link .get_attribute ('href' ))
@@ -58,9 +68,8 @@ def test_broken_links(browser, server, lang):
58
68
hrefs .add (href )
59
69
60
70
response = requests .get (href )
61
- assert response .status_code == 200 , 'expected 200, got {} for {} linked from {}' .format (
62
- response .status_code , href , referrer )
63
-
71
+ if response .status_code != 200 :
72
+ failures .append ([response .status_code , href , referrer ])
64
73
try :
65
74
# Scroll the link into view, to make it clickable.
66
75
link = browser .find_element_by_link_text ('Next' )
@@ -69,3 +78,7 @@ def test_broken_links(browser, server, lang):
69
78
link .click ()
70
79
except NoSuchElementException :
71
80
break
81
+
82
+ for status_code , href , referrer in failures :
83
+ warnings .warn ('expected 200, got {} for {} linked from {}\n ' .format (status_code , href , referrer ))
84
+ assert not failures , 'One or more links are broken. See warnings below.'
0 commit comments