def list_sets(): from flask_oaiserver.sets import (get_sets_list, get_sets_count) required_arg = [] optional_arg = [] exclusiv_arg = ["resumptionToken"] incoming = _get_all_request_args() _check_args(incoming, required_arg, optional_arg, exclusiv_arg) if g.error: return render_template("error.xml", incoming=incoming) else: sets = get_sets_list() resumption_token = {} if len(sets) < get_sets_count(): resumption_token["coursor"] = app.config['CFG_SETS_MAX_LENGTH'] resumption_token["date"] = datetime.strptime(g.response_date, "%Y-%m-%dT%H:%M:%Sz") \ + timedelta(hours=app.config['CFG_RESUMPTION_TOKEN_EXPIRE_TIME']) resumption_token["list_length"] = get_sets_count() # TODO: create a function to make a db entry on creation of the # resumption token resumption_token["token"] = uuid4() return render_template("list_sets.xml", incoming=incoming, sets=sets, resumption_token=resumption_token)
def test_list_sets_long(self): with self.app.test_client() as c: self.app.config['CFG_SETS_MAX_LENGTH'] = 3 result = c.get('/oai2d?verb=ListSets', follow_redirects=True) response_date = getattr(g, 'response_date', None) exp_date = datetime.strptime(response_date,"%Y-%m-%dT%H:%M:%Sz") + \ timedelta(hours=self.app.config['CFG_RESUMPTION_TOKEN_EXPIRE_TIME']) coursor = self.app.config['CFG_SETS_MAX_LENGTH'] list_size = get_sets_count() # TODO: remove placeholder value token = "xxx45abttyz" expected = """<?xml version="1.0" encoding="UTF-8"?> <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> <responseDate>{date}</responseDate> <requestverb="ListSets">{url}</request> <ListSets> <set> <setSpec>music</setSpec> <setName>Music collection</setName> <setDescription> <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> <dc:description>This is a collection of wide range of music.</dc:description> </oai_dc:dc> </setDescription> </set> <set> <setSpec>music:(chopin)</setSpec> <setName>Chopin collection</setName> <setDescription> <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> <dc:description>Collection of music composed by Chopin</dc:description> </oai_dc:dc> </setDescription> </set> <set> <setSpec>music:(techno)</setSpec> <setName>Techno music collection</setName> </set> <resumptionToken expirationDate="{exp_date}" completeListSize="{list_size}" cursor="{coursor}">{token}</resumptionToken> </ListSets> </OAI-PMH>""".format(date=response_date, url=self.oai_url, exp_date=exp_date, list_size=list_size, coursor=coursor, token=token) result_data = result.data.decode("utf-8") result_data = re.sub(' +', '', result_data.replace('\n', '')) expected = re.sub(' +', '', expected.replace('\n', '')) self.assertEqual(result_data, expected)