def test_last_auto_index_time(es_cdlc): assert_that(CustomDLC.latest_auto_time()).is_none() # this cdlc IS NOT the earliest in the index, so it will be considered non-continuous CustomDLC(_id=49792).update(from_auto_index=True) assert_that(CustomDLC.latest_auto_time()).is_none() assert_that(CustomDLC.earliest_not_auto()).is_equal_to(1589092730) # this cdlc IS the earliest in the index, so it AND ONLY IT will be considered continuous CustomDLC(_id=49706).update(from_auto_index=True) assert_that(CustomDLC.latest_auto_time()).is_equal_to(1589092730) assert_that(CustomDLC.earliest_not_auto()).is_equal_to(1589162625) # after this, all cdlcs marked as indexed are continuous, since no unmarked cdlcs are in between CustomDLC(_id=12990).update(from_auto_index=True) assert_that(CustomDLC.latest_auto_time()).is_equal_to(1589249216) assert_that(CustomDLC.earliest_not_auto()).is_equal_to(1589377216)
def try_write(self, cdlc: dict) -> Any: continuous_from = cdlc.pop(CONTINUOUS_FROM, None) is_continuous = self.__continuous and continuous_from is not None and continuous_from <= self.start_from() cdlc_id = cdlc.get('id', None) c = CustomDLC(_id=cdlc_id, from_auto_index=is_continuous, **cdlc) c.save() LOG.warning('Indexed CDLC #%s.', cdlc_id) return None if c.direct_download else c
def test_load_links(tl): # this simulates the scenario where link was empty due to error CustomDLC(_id=49841).update(direct_download='') with HTTMock(customsforge): tl.load_links() assert_that([hit.link for hit in CustomDLC.search()]) \ .is_length(6) \ .contains_only('magical_link')
def try_write(self, cdlc: dict) -> Any: cdlc_id = cdlc.get('id', None) art = cdlc.get('art', '') try: CustomDLC(_id=cdlc_id).update(art=art) except NotFoundError as e: LOG.warning('Art update failed for CDLC #%s, probably because it has not been loaded yet.', cdlc_id) debug_ex(e, 'fix my sins', LOG, silent=True) return None
def test_loading_continued(tl): # pretend we loaded cdlcs 2 days before TEST_DATE for cdlc_id in ['49706', '12990', '49792', '49841']: CustomDLC(_id=cdlc_id).update(from_auto_index=True) with HTTMock(customsforge): tl.load() hits = list(CustomDLC.search().filter('term', from_auto_index=True).filter('term', direct_download='magical_link')) # the only updated cdlcs are from the last two days (one each), and the latest cdlc before assert_that(hits).is_length(3)
def test_partial_update_for_non_existent_document(es_cdlc): try: CustomDLC(_id=100000).update(id=100000) assert False # exception should be thrown! except NotFoundError: assert_that(CustomDLC.get(100000, ignore=[404])).is_none()
def update(self, from_write: Any, direct_link: str): cdlc_id = from_write if cdlc_id and direct_link: CustomDLC(_id=cdlc_id).update(direct_download=direct_link) LOG.warning('Indexed direct link for CDLC #%s.', cdlc_id)