def archive_sip(sip_uuid): """Send the SIP for archiving. Retries every 4 hours, six times, which should work for up to 24 hours archiving system downtime. :param sip_uuid: UUID of the SIP for archiving. :type sip_uuid: str """ try: sip = SIPApi(SIP.query.get(sip_uuid)) archiver = BagItArchiver(sip) bagmeta = archiver.get_bagit_metadata(sip) if bagmeta is None: raise ArchivingError( 'Bagit metadata does not exist for SIP: {0}.'.format(sip.id)) if sip.archived: raise ArchivingError( 'SIP was already archived {0}.'.format(sip.id)) archiver.write_all_files() sip.archived = True db.session.commit() except Exception as exc: # On ArchivingError (see above), do not retry, but re-raise if not isinstance(exc, ArchivingError): archive_sip.retry(exc=exc) raise
def test_SIP(db): """Test SIP API class.""" user = create_test_user('*****@*****.**') agent = {'email': '*****@*****.**', 'ip_address': '1.1.1.1'} # we create a SIP model sip = SIP_.create(user_id=user.id, agent=agent) db.session.commit() # We create an API SIP on top of it api_sip = SIP(sip) assert api_sip.model is sip assert api_sip.id == sip.id assert api_sip.user is user assert api_sip.agent == agent assert api_sip.archivable is True assert api_sip.archived is False api_sip.archived = True db.session.commit() assert api_sip.archived is True assert sip.archived is True # test of the get method api_sip2 = SIP.get_sip(sip.id) assert api_sip2.id == api_sip.id