示例#1
0
 def setUp(self):
     self.parser = MerxParser()
示例#2
0
 def setUp(self):
     self.parser = MerxParser()
示例#3
0
class MerxParserTest(unittest.TestCase):
    def setUp(self):
        self.parser = MerxParser()

    def testLoad(self):
        self.parser.load(self.parser.get_list_uri())

        # Make sure the PHPSESSID cookie is present
        #self.assertTrue(self.parser.headers['Cookie'].find('PHPSESSID=') != -1)

        # The request should exist now
        self.assertNotEquals(None, self.parser.request)

    def testParseList(self):
        self.parser.load(self.parser.get_list_uri())

        try:
            s = self.parser.request.read()
            self.parser.doc = pq(s)
        except lxml.etree.XMLSyntaxError as e:
            logging.error('Could not parse URI: %s' % self.list_uri)

        parsed_list = self.parser.parse_list()

        # 10 RFPs should have been parsed
        self.assertEquals(10, len(parsed_list))

        for rfp in parsed_list:
            self.assertEquals('merx', rfp['origin'])
            self.assertEquals(0, rfp['uri'].find('http://www.merx.com/'))
            self.assertNotEquals('', rfp['title'])
            self.assertNotEquals('', rfp['original_id'])

    def testNextWithoutDetails(self):
        # Parse without details
        parsed_list = self.parser.next(False)

        # 10 RFPs should have been parsed
        self.assertEquals(10, len(parsed_list))

        for rfp in parsed_list:
            self.assertEquals('merx', rfp['origin'])
            self.assertEquals(0, rfp['uri'].find('http://www.merx.com/'))
            self.assertNotEquals('', rfp['title'])
            self.assertNotEquals('', rfp['original_id'])

    def testNextWithDetails(self):
        # Parse with details
        parsed_list = self.parser.next()

        # 10 RFPs should have been parsed
        self.assertEquals(10, len(parsed_list))

        for rfp in parsed_list:
            self.assertEquals('merx', rfp['origin'])
            self.assertEquals(0, rfp['uri'].find('http://www.merx.com/'))
            self.assertNotEquals('', rfp['title'])
            self.assertNotEquals('', rfp['original_id'])
            self.assertNotEquals('', rfp['org'])
            self.assertNotEquals('', rfp['original_category'])
            # Location can be blank
            #self.assertTrue( rfp.has_key('location') )
            self.assertNotEquals('', rfp['description'])
            self.assertTrue(isinstance(rfp['parsed_on'], datetime.date))
            self.assertTrue(isinstance(rfp['published_on'], datetime.date))
            self.assertTrue(isinstance(rfp['ends_on'], datetime.date))

    def testHasNext(self):
        self.assertTrue(self.parser.has_next())
        self.parser.page = -1
        self.assertFalse(self.parser.has_next())
示例#4
0
class MerxParserTest(unittest.TestCase):

    def setUp(self):
        self.parser = MerxParser()

    def testLoad(self):
        self.parser.load(self.parser.get_list_uri())

        # Make sure the PHPSESSID cookie is present
        #self.assertTrue(self.parser.headers['Cookie'].find('PHPSESSID=') != -1)

        # The request should exist now
        self.assertNotEquals(None, self.parser.request)

    def testParseList(self):
        self.parser.load(self.parser.get_list_uri())

        try:
            s = self.parser.request.read()
            self.parser.doc = pq( s )
        except lxml.etree.XMLSyntaxError as e:
            logging.error( 'Could not parse URI: %s' % self.list_uri )

        parsed_list = self.parser.parse_list()

        # 10 RFPs should have been parsed
        self.assertEquals(10, len(parsed_list))

        for rfp in parsed_list:
            self.assertEquals('merx', rfp['origin'])
            self.assertEquals(0, rfp['uri'].find('http://www.merx.com/'))
            self.assertNotEquals('', rfp['title'])
            self.assertNotEquals('', rfp['original_id'])


    def testNextWithoutDetails(self):
        # Parse without details
        parsed_list = self.parser.next(False)

        # 10 RFPs should have been parsed
        self.assertEquals(10, len(parsed_list))

        for rfp in parsed_list:
            self.assertEquals('merx', rfp['origin'])
            self.assertEquals(0, rfp['uri'].find('http://www.merx.com/'))
            self.assertNotEquals('', rfp['title'])
            self.assertNotEquals('', rfp['original_id'])
    
    def testNextWithDetails(self):
        # Parse with details
        parsed_list = self.parser.next()

        # 10 RFPs should have been parsed
        self.assertEquals(10, len(parsed_list))

        for rfp in parsed_list:
            self.assertEquals('merx', rfp['origin'])
            self.assertEquals(0, rfp['uri'].find('http://www.merx.com/'))
            self.assertNotEquals('', rfp['title'])
            self.assertNotEquals('', rfp['original_id'])
            self.assertNotEquals('', rfp['org'])
            self.assertNotEquals('', rfp['original_category'])
            # Location can be blank
            #self.assertTrue( rfp.has_key('location') )
            self.assertNotEquals('', rfp['description'])
            self.assertTrue(isinstance(rfp['parsed_on'], datetime.date))
            self.assertTrue(isinstance(rfp['published_on'], datetime.date))
            self.assertTrue(isinstance(rfp['ends_on'], datetime.date))
    
    def testHasNext(self):
        self.assertTrue(self.parser.has_next())
        self.parser.page = -1
        self.assertFalse(self.parser.has_next())