test_v3bwfile.py 2.9 KB
Newer Older
juga's avatar
juga committed
1
2
# -*- coding: utf-8 -*-
"""Test generation of bandwidth measurements document (v3bw)"""
3
from sbws.globals import SPEC_VERSION
juga's avatar
juga committed
4
5
from sbws.lib.v3bwfile import (V3BwHeader, TERMINATOR, LINE_SEP,
                               KEYVALUE_SEP_V110)
6
from sbws import __version__ as version
juga's avatar
juga committed
7

8
timestamp = 1523974147
9
timestamp_l = str(timestamp)
10
11
12
version_l = KEYVALUE_SEP_V110.join(['version', SPEC_VERSION])
software_l = KEYVALUE_SEP_V110.join(['software', 'sbws'])
software_version_l = KEYVALUE_SEP_V110.join(['software_version', version])
13
file_created = '2018-04-25T13:10:57'
14
file_created_l = KEYVALUE_SEP_V110.join(['file_created', file_created])
juga's avatar
juga committed
15
16
17
18
latest_bandwidth = '2018-04-17T14:09:07'
latest_bandwidth_l = KEYVALUE_SEP_V110.join(['latest_bandwidth',
                                             latest_bandwidth])
header_ls = [timestamp_l, version_l, file_created_l, latest_bandwidth_l,
19
20
             software_l, software_version_l, TERMINATOR]
header_str = LINE_SEP.join(header_ls) + LINE_SEP
21
earliest_bandwidth = '2018-04-16T14:09:07'
22
23
earliest_bandwidth_l = KEYVALUE_SEP_V110.join(['earliest_bandwidth',
                                               earliest_bandwidth])
24
generator_started = '2018-04-16T14:09:05'
25
26
generator_started_l = KEYVALUE_SEP_V110.join(['generator_started',
                                              generator_started])
27
header_extra_ls = [timestamp_l, version_l,
28
                   earliest_bandwidth_l, file_created_l, generator_started_l,
juga's avatar
juga committed
29
                   latest_bandwidth_l,
30
                   software_l, software_version_l, TERMINATOR]
31
32
header_extra_str = LINE_SEP.join(header_extra_ls) + LINE_SEP

juga's avatar
juga committed
33
34
35

def test_v3bwheader_str():
    """Test header str"""
36
    header = V3BwHeader(timestamp_l, file_created=file_created)
37
38
39
40
    assert header_str == str(header)


def test_v3bwheader_extra_str():
41
    """Test header str with additional headers"""
42
    header = V3BwHeader(timestamp_l,
43
44
                        file_created=file_created,
                        generator_started=generator_started,
45
46
47
48
49
50
                        earliest_bandwidth=earliest_bandwidth)
    assert header_extra_str == str(header)


def test_v3bwheader_from_lines():
    """"""
51
    header_obj = V3BwHeader(timestamp_l,
52
53
                            file_created=file_created,
                            generator_started=generator_started,
54
                            earliest_bandwidth=earliest_bandwidth)
55
    header, _ = V3BwHeader.from_lines_v110(header_extra_ls)
56
57
58
59
60
    assert str(header_obj) == str(header)


def test_v3bwheader_from_text():
    """"""
61
    header_obj = V3BwHeader(timestamp_l,
62
63
                            file_created=file_created,
                            generator_started=generator_started,
64
                            earliest_bandwidth=earliest_bandwidth)
65
    header, _ = V3BwHeader.from_text_v110(header_extra_str)
66
    assert str(header_obj) == str(header)
juga's avatar
juga committed
67
68


juga's avatar
juga committed
69
70
71
def test_v3bwfile():
    """Test generate v3bw file (including relay_lines)."""
    pass