def test_set(self):
     """oairepository - testing selective harvesting with 'set' parameter"""
     self.assertNotEqual([], oai_repository_server.oaigetsysnolist(set="cern:experiment"))
     self.assert_("Multifractal analysis of minimum bias events" in \
                  ''.join([oai_repository_server.print_record(recID) for recID in \
                           oai_repository_server.oaigetsysnolist(set="cern:experiment")]))
     self.assert_("Multifractal analysis of minimum bias events" not in \
                  ''.join([oai_repository_server.print_record(recID) for recID in \
                           oai_repository_server.oaigetsysnolist(set="cern:theory")]))
     self.assertEqual([], oai_repository_server.oaigetsysnolist(set="nonExistingSet"))
 def test_set(self):
     """oairepository - testing selective harvesting with 'set' parameter"""
     self.assertNotEqual([], oai_repository_server.oaigetsysnolist(set="cern:experiment"))
     self.assert_("Multifractal analysis of minimum bias events" in \
                  ''.join([oai_repository_server.print_record(recID) for recID in \
                           oai_repository_server.oaigetsysnolist(set="cern:experiment")]))
     self.assert_("Multifractal analysis of minimum bias events" not in \
                  ''.join([oai_repository_server.print_record(recID) for recID in \
                           oai_repository_server.oaigetsysnolist(set="cern:theory")]))
     self.assertEqual([], oai_repository_server.oaigetsysnolist(set="nonExistingSet"))
    def test_from_and_until(self):
        """oairepository - testing selective harvesting with 'from' and 'until' parameters"""

        # List available records, get datestamps and play with them
        identifiers = oai_repository_server.oailistidentifiers("")
        datestamps = re.findall('<identifier>(?P<id>.*)</identifier>\s*<datestamp>(?P<date>.*)</datestamp>', identifiers)

        sample_datestamp = datestamps[0][1] # Take one datestamp
        sample_oai_id = datestamps[0][0] # Take corresponding oai id
        sample_id = search_engine.perform_request_search(p=sample_oai_id,
                                                         f=CFG_OAI_ID_FIELD)[0] # Find corresponding system number id

        # There must be some datestamps
        self.assertNotEqual([], datestamps)

        # We must be able to retrieve an id with the date we have just found
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(fromdate=sample_datestamp))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(untildate=sample_datestamp))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(untildate=sample_datestamp, \
                                                                 fromdate=sample_datestamp))

        # Same, with short format date. Eg 2007-12-13
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(fromdate=sample_datestamp.split('T')[0]))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(untildate=sample_datestamp.split('T')[0]))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(fromdate=sample_datestamp.split('T')[0], \
                                                                 untildate=sample_datestamp.split('T')[0]))

        # At later date (year after) we should not find our id again
        sample_datestamp_year = int(sample_datestamp[0:4])
        sample_datestamp_rest = sample_datestamp[4:]
        later_datestamp = str(sample_datestamp_year + 1) + sample_datestamp_rest
        self.assert_(sample_id not in oai_repository_server.oaigetsysnolist(fromdate=later_datestamp))

        # At earlier date (year before) we should not find our id again
        earlier_datestamp = str(sample_datestamp_year - 1) + sample_datestamp_rest
        self.assert_(sample_id not in oai_repository_server.oaigetsysnolist(untildate=earlier_datestamp))

        # From earliest date to latest date must include all oai records
        dates = [(time.mktime(time.strptime(date[1], "%Y-%m-%dT%H:%M:%SZ")), date[1]) for date in datestamps]
        dates = dict(dates)
        sorted_times = dates.keys()
        sorted_times.sort()
        earliest_datestamp = dates[sorted_times[0]]
        latest_datestamp = dates[sorted_times[-1]]
        self.assertEqual(len(oai_repository_server.oaigetsysnolist()), \
                         len(oai_repository_server.oaigetsysnolist(fromdate=earliest_datestamp, \
                                                            untildate=latest_datestamp)))
    def test_from_and_until(self):
        """oairepository - testing selective harvesting with 'from' and 'until' parameters"""

        # List available records, get datestamps and play with them
        identifiers = oai_repository_server.oailistidentifiers("")
        datestamps = re.findall('<identifier>(?P<id>.*)</identifier>\s*<datestamp>(?P<date>.*)</datestamp>', identifiers)

        sample_datestamp = datestamps[0][1] # Take one datestamp
        sample_oai_id = datestamps[0][0] # Take corresponding oai id
        sample_id = search_engine.perform_request_search(p=sample_oai_id,
                                                         f=CFG_OAI_ID_FIELD)[0] # Find corresponding system number id

        # There must be some datestamps
        self.assertNotEqual([], datestamps)

        # We must be able to retrieve an id with the date we have just found
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(fromdate=sample_datestamp))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(untildate=sample_datestamp))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(untildate=sample_datestamp, \
                                                                 fromdate=sample_datestamp))

        # Same, with short format date. Eg 2007-12-13
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(fromdate=sample_datestamp.split('T')[0]))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(untildate=sample_datestamp.split('T')[0]))
        self.assert_(sample_id in oai_repository_server.oaigetsysnolist(fromdate=sample_datestamp.split('T')[0], \
                                                                 untildate=sample_datestamp.split('T')[0]))

        # At later date (year after) we should not find our id again
        sample_datestamp_year = int(sample_datestamp[0:4])
        sample_datestamp_rest = sample_datestamp[4:]
        later_datestamp = str(sample_datestamp_year + 1) + sample_datestamp_rest
        self.assert_(sample_id not in oai_repository_server.oaigetsysnolist(fromdate=later_datestamp))

        # At earlier date (year before) we should not find our id again
        earlier_datestamp = str(sample_datestamp_year - 1) + sample_datestamp_rest
        self.assert_(sample_id not in oai_repository_server.oaigetsysnolist(untildate=earlier_datestamp))

        # From earliest date to latest date must include all oai records
        dates = [(time.mktime(time.strptime(date[1], "%Y-%m-%dT%H:%M:%SZ")), date[1]) for date in datestamps]
        dates = dict(dates)
        sorted_times = dates.keys()
        sorted_times.sort()
        earliest_datestamp = dates[sorted_times[0]]
        latest_datestamp = dates[sorted_times[-1]]
        self.assertEqual(len(oai_repository_server.oaigetsysnolist()), \
                         len(oai_repository_server.oaigetsysnolist(fromdate=earliest_datestamp, \
                                                            untildate=latest_datestamp)))
 def setUp(self):
     """Setting up some variables"""
     # Determine how many records are served
     self.number_of_records = oai_repository_server.oaigetsysnolist("", "", "")
     if CFG_OAI_LOAD < self.number_of_records:
         self.number_of_records = CFG_OAI_LOAD
 def setUp(self):
     """Setting up some variables"""
     # Determine how many records are served
     self.number_of_records = oai_repository_server.oaigetsysnolist("", "", "")
     if CFG_OAI_LOAD < self.number_of_records:
         self.number_of_records = CFG_OAI_LOAD