Debian Codegraph @

tests/network_link_control_test.py

raw symbols SCIP
1 # Copyright (C) 2021 - 2022 Christian Ledermann
2 #
3 # This library is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation; either version 2.1 of the License, or (at your option)
6 # any later version.
7 #
8 # This library is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this library; if not, write to the Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 """Test the Network Link Control classes."""
18
19 import datetime
20
21 from dateutil.tz import tzutc
22
23 from fastkml import views
24 from fastkml.network_link_control import NetworkLinkControl
25 from fastkml.times import KmlDateTime
26 from tests.base import Lxml
27 from tests.base import StdLibrary
28
29
30 class TestStdLibrary(StdLibrary):
31 """Test with the standard library."""
32
33 def test_network_link_control_obj(self) -> None:
34 dt = datetime.datetime.now(tz=tzutc())
35 kml_datetime = KmlDateTime(dt=dt)
36 view = views.Camera()
37
38 network_control_obj = NetworkLinkControl(
39 min_refresh_period=1.1,
40 max_session_length=100.1,
41 cookie="cookie",
42 message="message",
43 link_name="link_name",
44 link_description="link_description",
45 link_snippet="link_snippet",
46 expires=kml_datetime,
47 view=view,
48 )
49
50 assert network_control_obj.min_refresh_period == 1.1
51 assert network_control_obj.max_session_length == 100.1
52 assert network_control_obj.cookie == "cookie"
53 assert network_control_obj.message == "message"
54 assert network_control_obj.link_name == "link_name"
55 assert network_control_obj.link_description == "link_description"
56 assert network_control_obj.link_snippet == "link_snippet"
57 assert str(network_control_obj.expires) == str(kml_datetime)
58 assert str(network_control_obj.view) == str(view)
59
60 def test_network_link_control_kml(self) -> None:
61 doc = (
62 '<kml:NetworkLinkControl xmlns:kml="http://www.opengis.net/kml/2.2">'
63 "<kml:minRefreshPeriod>432000</kml:minRefreshPeriod>"
64 "<kml:maxSessionLength>-1</kml:maxSessionLength>"
65 "<kml:linkSnippet>A Snippet</kml:linkSnippet>"
66 "<kml:expires>2008-05-30</kml:expires>"
67 "</kml:NetworkLinkControl>"
68 )
69
70 nc = NetworkLinkControl.from_string(doc)
71
72 dt = datetime.date(2008, 5, 30)
73 kml_datetime = KmlDateTime(dt=dt)
74
75 nc_obj = NetworkLinkControl(
76 min_refresh_period=432000,
77 max_session_length=-1,
78 link_snippet="A Snippet",
79 expires=kml_datetime,
80 )
81
82 assert nc == nc_obj
83
84
85 class TestLxml(Lxml, TestStdLibrary):
86 """Test with lxml."""