File: test_warning.py

package info (click to toggle)
pynina 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 756 kB
  • sloc: python: 761; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,549 bytes parent folder | download
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
from copy import deepcopy
from datetime import datetime, timedelta

from pynina import Warning

dummy_warning = Warning(
    "id",
    "headline",
    "severity",
    "description",
    "sender",
    [],
    [],
    "web",
    datetime.now().isoformat(),
    None,
    None,
)


def test_warning_valid_no_start_no_exp():
    """Test if a warning is valid when it has no start and no expiration time."""
    warning = deepcopy(dummy_warning)

    assert warning.is_valid


def test_warning_valid_no_exp():
    """Test if a warning is valid when it has a start but no expiration time."""
    warning = deepcopy(dummy_warning)
    warning.start = (datetime.now() - timedelta(hours=2)).isoformat()

    assert warning.is_valid


def test_warning_valid_no_start_exp_future():
    """Test if a warning is valid when it has an expiration time in the future but start time."""
    warning = deepcopy(dummy_warning)
    warning.expires = (datetime.now() + timedelta(hours=2)).isoformat()

    assert warning.is_valid


def test_warning_valid_no_start_exp_past():
    """Test if a warning is valid when it has an expiration time in the past but start time."""
    warning = deepcopy(dummy_warning)
    warning.expires = (datetime.now() - timedelta(hours=2)).isoformat()

    assert not warning.is_valid


def test_warning_valid_no_start_exp_now():
    """Test if a warning is valid when it has an expiration time is now but start time."""
    warning = deepcopy(dummy_warning)
    warning.expires = datetime.now().isoformat()

    assert not warning.is_valid