def test_08_is_stale_not_stale(self):
     config.licence_stale_time = 15552000 # 6 months
     
     # a record with a single date, which is not stale
     n = datetime.datetime.now() # now
     threemonths = datetime.timedelta(days=90) # 3 months
     bibjson = {'license' : [{ 'provenance' : {'date' : datetime.datetime.strftime(n - threemonths, "%Y-%m-%dT%H:%M:%SZ")}}]}
     record = models.MessageObject(record={"bibjson" : bibjson})
     assert not cache.is_stale(record), bibjson
     
     # a record with multiple dates, neither of which is stale
     fourmonths = datetime.timedelta(days=120)
     bibjson = {'license' : [
                     {'provenance' : {'date' : datetime.datetime.strftime(n - threemonths, "%Y-%m-%dT%H:%M:%SZ")}},
                     {'provenance' : {'date' : datetime.datetime.strftime(n - fourmonths, "%Y-%m-%dT%H:%M:%SZ")}}
               ]}
     record = models.MessageObject(record={"bibjson" : bibjson})
     assert not cache.is_stale(record)
     
     # a record with multiple dates, only one of which is not stale
     oneyear = datetime.timedelta(days=365)
     bibjson = {'license' : [
                     {'provenance' : {'date' : datetime.datetime.strftime(n - threemonths, "%Y-%m-%dT%H:%M:%SZ")}},
                     {'provenance' : {'date' : datetime.datetime.strftime(n - oneyear, "%Y-%m-%dT%H:%M:%SZ")}}
               ]}
     record = models.MessageObject(record={"bibjson" : bibjson})
     assert not cache.is_stale(record)
 def test_06_is_stale_no_dates(self):
     bibjson = {'license' : []}
     assert cache.is_stale(bibjson)
     
     bibjson['license'].append({})
     bibjson['license'][0]['provenance'] = {}
     assert cache.is_stale(bibjson)
     
     bibjson['license'][0]['provenance']['date'] = None
     assert cache.is_stale(bibjson)
 def test_06_is_stale_no_dates(self):
     bibjson = {'license' : []}
     record = models.MessageObject(record={"bibjson" : bibjson})
     assert cache.is_stale(record)
     
     bibjson['license'].append({})
     bibjson['license'][0]['provenance'] = {}
     record = models.MessageObject(record={"bibjson" : bibjson})
     assert cache.is_stale(record)
     
     bibjson['license'][0]['provenance']['date'] = None
     record = models.MessageObject(record={"bibjson" : bibjson})
     assert cache.is_stale(record)
def _is_stale(bibjson):
    """
    Do a stale check on the bibjson object.
    
    arguments:
    bibjson -- the bibjson record to carry out the stale check on
    
    """
    return cache.is_stale(bibjson)
 def test_09_is_stale_stale(self):
     config.licence_stale_time = 15552000 # 6 months
     
     # a record with multiple dates, all of which are stale
     n = datetime.datetime.now() # now
     sevenmonths = datetime.timedelta(days=210) # 3 months
     oneyear = datetime.timedelta(days=365)
     bibjson = {'license' : [
                     {'provenance' : {'date' : datetime.datetime.strftime(n - sevenmonths, "%Y-%m-%dT%H:%M:%SZ")}},
                     {'provenance' : {'date' : datetime.datetime.strftime(n - oneyear, "%Y-%m-%dT%H:%M:%SZ")}}
               ]}
     assert cache.is_stale(bibjson)
 def test_07_is_stale_invalid_dates(self):
     bibjson = {'license' : [{ 'provenance' : {'date' : "wibble"} }, {'provenance' : {'date' : "whatever"}}]}
     assert cache.is_stale(bibjson)
 def test_05_is_stale_unlicenced(self):
     bibjson = {}
     assert cache.is_stale(bibjson)
def _is_stale(bibjson):
    """
    Do a stale check on the bibjson object.
    """
    return cache.is_stale(bibjson)
 def test_07_is_stale_invalid_dates(self):
     bibjson = {'license' : [{ 'provenance' : {'date' : "wibble"} }, {'provenance' : {'date' : "whatever"}}]}
     record = models.MessageObject(record={"bibjson" : bibjson})
     assert cache.is_stale(record)
 def test_05_is_stale_unlicenced(self):
     # bibjson = {}
     record = models.MessageObject(record={"bibjson" : {}})
     assert cache.is_stale(record)