Completed
Push — main ( 7d4592...e74a90 )
by Jochen
03:11
created

tests.integration.announce.discord.helpers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4

3 Functions

Rating   Name   Duplication   Size   Complexity  
A assert_request() 0 9 1
A now() 0 2 1
A mocked_webhook_receiver() 0 5 2
1
"""
2
:Copyright: 2006-2020 Jochen Kupperschmidt
3
:License: Modified BSD, see LICENSE for details.
4
"""
5
6
from contextlib import contextmanager
7
from datetime import datetime
8
9
from requests_mock import Mocker
10
11
12
def now() -> datetime:
13
    return datetime.utcnow()
14
15
16
@contextmanager
17
def mocked_webhook_receiver(url: str):
18
    with Mocker() as mock:
19
        mock.post(url)
20
        yield mock
21
22
23
def assert_request(mock, expected_content: str) -> None:
24
    assert mock.called
25
26
    history = mock.request_history
27
    assert len(history) == 1
28
29
    actual = mock.last_request.json()
30
31
    assert actual == {'content': expected_content}
32