Esempio n. 1
0
    def test_iso_time(self):
        element = et.fromstring("<foo><bar>2020-01-10T13:13:33Z</bar></foo>")
        dt = get_datetime_from_element(element, 'bar')

        self.assertIsNotNone(dt)
        self.assertIsInstance(dt, datetime.datetime)

        self.assertEqual(dt.year, 2020)
        self.assertEqual(dt.month, 1)
        self.assertEqual(dt.day, 10)

        self.assertEqual(dt.hour, 13)
        self.assertEqual(dt.minute, 13)
        self.assertEqual(dt.second, 33)
        self.assertEqual(str(dt.tzinfo), 'UTC')
Esempio n. 2
0
 def test_invalid_datetime(self):
     element = et.fromstring("<foo><bar>ipsum</bar></foo>")
     self.assertIsNone(get_datetime_from_element(element, 'bar'))
Esempio n. 3
0
    def test_empty_subelement(self):
        element = et.fromstring("<foo><bar></bar></foo>")
        self.assertFalse(get_datetime_from_element(element, 'bar'))

        element = et.fromstring("<foo><bar> </bar></foo>")
        self.assertFalse(get_datetime_from_element(element, 'bar'))
Esempio n. 4
0
 def resolve_start(root, _info):
     return get_datetime_from_element(root, 'start')
Esempio n. 5
0
 def resolve_open_time(root, _info):
     return get_datetime_from_element(root, 'open_time')
Esempio n. 6
0
 def resolve_trust_time(root, _info):
     trust = root.find('trust')
     return get_datetime_from_element(trust, 'time')
Esempio n. 7
0
 def resolve_update_time(root, _info):
     return get_datetime_from_element(root, 'update_time')
Esempio n. 8
0
 def resolve_scan_end(parent, _info):
     report = parent.find('report')
     return get_datetime_from_element(report, 'scan_end')
Esempio n. 9
0
 def resolve_modification_time(root, _info):
     return get_datetime_from_element(root.outer_report,
                                      'modification_time')
Esempio n. 10
0
 def resolve_scan_nvt_version(root, _info):
     return get_datetime_from_element(root, 'scan_nvt_version')
Esempio n. 11
0
 def resolve_timestamp(parent, _info):
     report = parent.find('report')
     return get_datetime_from_element(report, 'timestamp')
Esempio n. 12
0
 def resolve_last_seen(root, _info):
     return get_datetime_from_element(root, 'last_seen')
Esempio n. 13
0
 def resolve_expiration_time(root: XmlElement, _info):
     cert_info = root.find('certificate_info')
     return get_datetime_from_element(cert_info, 'expiration_time')
Esempio n. 14
0
 def resolve_closed_time(root, _info):
     return get_datetime_from_element(root, 'closed_time')
Esempio n. 15
0
 def resolve_activation_time(root, _info):
     return get_datetime_from_element(root, 'activation_time')
Esempio n. 16
0
 def resolve_timestamp(root, _info):
     return get_datetime_from_element(root.inner_report, 'timestamp')
Esempio n. 17
0
 def resolve_expiration_time(root, _info):
     return get_datetime_from_element(root, 'expiration_time')
Esempio n. 18
0
 def resolve_scan_end(root, _info):
     return get_datetime_from_element(root.inner_report, 'scan_end')
Esempio n. 19
0
 def resolve_date(root, _info):
     return get_datetime_from_element(root, 'date')
Esempio n. 20
0
 def test_none(self):
     self.assertIsNone(get_datetime_from_element(None, 'foo'))
Esempio n. 21
0
 def resolve_modification_time(root, _info):
     return get_datetime_from_element(root, 'creation_time')
Esempio n. 22
0
 def test_unkown_subelement(self):
     element = Element('foo')
     self.assertIsNone(get_datetime_from_element(element, 'bar'))
Esempio n. 23
0
 def resolve_end(root, _info):
     return get_datetime_from_element(root, 'end')
Esempio n. 24
0
 def resolve_newest(root, _info):
     return get_datetime_from_element(root, 'newest')