| Total Complexity | 5 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # tests/test_connectivity.py |
||
| 2 | """Module for testing connectivity. |
||
| 3 | |||
| 4 | Meant to serve as template in case outgoing connections are to be tested. |
||
| 5 | """ |
||
| 6 | import pytest |
||
| 7 | import requests |
||
| 8 | |||
| 9 | |||
| 10 | def request_url(url): |
||
| 11 | """With wrapper to requests.get.""" |
||
| 12 | try: |
||
| 13 | with requests.get(url) as response: |
||
| 14 | response.raise_for_status() |
||
| 15 | return response |
||
| 16 | |||
| 17 | except requests.RequestException: |
||
| 18 | message = "Error: request_url failed." |
||
| 19 | return message |
||
| 20 | |||
| 21 | |||
| 22 | @pytest.fixture |
||
| 23 | def request_random_wiki_article(): |
||
| 24 | """Try reaching the wikipedia site to get a random article.""" |
||
| 25 | api_url = "https://en.wikipedia.org/api/rest_v1/page/random/summary" |
||
| 26 | response = request_url(api_url) |
||
| 27 | |||
| 28 | return response |
||
| 29 | |||
| 30 | |||
| 31 | @pytest.mark.con |
||
| 32 | def test_wikipedia_connectivity(request_random_wiki_article): |
||
| 33 | """Try reaching the wikipedia site to get a random article.""" |
||
| 34 | # pylint: disable=redefined-outer-name |
||
| 35 | # disabled here, sind redefinition is how fixtures work |
||
| 36 | |||
| 37 | answer = request_random_wiki_article |
||
| 38 | print(answer) |
||
| 39 | assert "Error" not in answer |
||
| 40 |