tests.test_connectivity   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5

3 Functions

Rating   Name   Duplication   Size   Complexity  
A request_random_wiki_article() 0 7 1
A request_url() 0 10 3
A test_wikipedia_connectivity() 0 9 1
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