comparison tests/testCPE.py @ 41:bb1dd2a55643

CPE: Add a generic 'parse' method
author Benoît Allard <benoit.allard@greenbone.net>
date Mon, 29 Dec 2014 14:58:29 +0100
parents 1d9b2b06067e
children
comparison
equal deleted inserted replaced
40:1d9b2b06067e 41:bb1dd2a55643
1 # -*- coding: utf-8 -*-
2 # Description:
3 # Tests for the CPE parsing methods
4 #
5 # Authors:
6 # BenoƮt Allard <benoit.allard@greenbone.net>
7 #
8 # Copyright:
9 # Copyright (C) 2014 Greenbone Networks GmbH
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
1 import unittest 25 import unittest
2 26
3 from farolluz.parsers.cpe import CPE, CPEAttribute 27 from farolluz.parsers.cpe import CPE, CPEAttribute, parse
4 28
5 class testbindToURI(unittest.TestCase): 29 class testbindToURI(unittest.TestCase):
6 30
7 def test_example1(self): 31 def test_example1(self):
8 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('microsoft'), product=CPEAttribute('internet_explorer'), version=CPEAttribute(r'8\.0\.6001'), update=CPEAttribute('beta'), edition=CPEAttribute(any=True)) 32 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('microsoft'), product=CPEAttribute('internet_explorer'), version=CPEAttribute(r'8\.0\.6001'), update=CPEAttribute('beta'), edition=CPEAttribute(any=True))
208 self.assertEqual(cpe.sw_edition.value, "special") 232 self.assertEqual(cpe.sw_edition.value, "special")
209 self.assertEqual(cpe.target_sw.value, "ipod_touch") 233 self.assertEqual(cpe.target_sw.value, "ipod_touch")
210 self.assertEqual(cpe.target_hw.value, "80gb") 234 self.assertEqual(cpe.target_hw.value, "80gb")
211 self.assertTrue(cpe.other.any) 235 self.assertTrue(cpe.other.any)
212 self.assertTrue(cpe.language.any) 236 self.assertTrue(cpe.language.any)
237
238 class testParse(unittest.TestCase):
239
240 def testURI(self):
241 cpe = parse('cpe:/a:fogproject:fog:0.31')
242 self.assertEqual(cpe.part.value, 'a')
243
244 def testFS(self):
245 cpe = parse('cpe:2.3:a:tenable:web_ui:2.3.3:*:*:*:*:*:*')
246 self.assertEqual(cpe.vendor.value, 'tenable')
247
248 def testGarbage(self):
249 self.assertRaises(ValueError, parse, 'garbage')
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)