def as_thing( self, t_created: datetime.datetime, status: int, source_file_path: str, t_resolved: datetime.datetime, ) -> Thing: logging.debug("SmithsonianItem.asThing") _thing = Thing( id=self.identifier, tcreated=t_created, item_type=None, authority_id=SmithsonianItem.AUTHORITY_ID, resolved_url=f"file://{source_file_path}", resolved_status=status, tresolved=t_resolved, resolve_elapsed=0, ) if not isinstance(self.source_item, dict): L.error("Item is not an object") return _thing _thing.item_type = "sample" _thing.resolved_media_type = SmithsonianItem.TEXT_CSV # Note that this field doesn't make sense for Smithsonian as the information is coming from a local file # _thing.resolve_elapsed = resolve_elapsed _thing.resolved_content = self.source_item return _thing
def reparseThing(thing: Thing) -> Thing: """Reparse the resolved_content""" _validateResolvedContent(thing) item = SESARItem(thing.resolved_content) thing.item_type = item.getItemType() thing.tstamp = igsn_lib.time.dtnow() return thing
def _add_some_things(session: Session, num_things: int, authority_id: str, tcreated: datetime.datetime = None): for i in range(num_things): new_thing = Thing(id=str(i), authority_id=authority_id, resolved_url="http://foo.bar", resolved_status=200, resolved_content={"foo": "bar"}) if tcreated is not None: new_thing.tcreated = tcreated session.add(new_thing) session.commit()
def test_read_things_with_things(session: Session): new_thing = Thing(id="123456", authority_id="test", resolved_url="http://foo.bar", resolved_status=200, resolved_content={"foo": "bar"}) session.add(new_thing) session.commit() count, pages, data = read_things_summary(session, 0, 0) assert 1 == count assert 0 == pages assert len(data) > 0
def asThing( self, t_created: datetime.datetime, status: int, resolved_url: str, t_resolved: datetime.datetime, resolve_elapsed: float, media_type: str = None, ) -> Thing: L = getLogger() L.debug("SESARItem.asThing") # Note: SESAR incorrectly returns "application/json;charset=UTF-8" for json-ld content if media_type is None: media_type = MEDIA_JSON_LD _thing = Thing( id=self.identifier, tcreated=t_created, item_type=None, authority_id=SESARItem.AUTHORITY_ID, resolved_url=resolved_url, resolved_status=status, tresolved=t_resolved, resolve_elapsed=resolve_elapsed, ) if not isinstance(self.item, dict): L.error("Item is not an object") return _thing _thing.item_type = self.getItemType() _thing.resolved_media_type = media_type _thing.resolve_elapsed = resolve_elapsed _thing.resolved_content = self.item return _thing
def test_get_thing_with_id_thing(session: Session): id = "123456" new_thing = Thing(id=id, authority_id="test", resolved_url="http://foo.bar", resolved_status=200, resolved_content={"foo": "bar"}) session.add(new_thing) session.commit() shouldnt_be_none = get_thing_with_id(session, id) assert shouldnt_be_none is not None assert shouldnt_be_none.primary_key is not None assert id == shouldnt_be_none.id
def test_last_time_thing_created(session: Session): test_authority = "test" created = last_time_thing_created(session, test_authority) assert created is None new_thing = Thing(id="123456", authority_id=test_authority, resolved_url="http://foo.bar", resolved_status=200, resolved_content={"foo": "bar"}, tcreated=datetime.datetime.now()) session.add(new_thing) session.commit() new_created = last_time_thing_created(session, test_authority) assert new_created is not None