def test_calling_document_uris_from_dc_when_no_dc(self, document_uris_from_dc): document_data = {} # No 'dc' key. claimant = 'http://localhost:5000/docs/help' parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_dc.assert_called_once_with({}, claimant)
def test_calling_document_uris_from_highwire_pdf_when_no_highwire( self, document_uris_from_highwire_pdf): document_data = {} # No 'highwire' key. claimant = 'http://localhost:5000/docs/help' parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_highwire_pdf.assert_called_once_with({}, claimant)
def test_calling_document_uris_from_links_when_no_links( self, document_uris_from_links): document_data = {} # No 'link' key. claimant = 'http://localhost:5000/docs/help' parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_links.assert_called_once_with([], claimant)
def test_calling_document_uris_from_dc_when_no_dc(self, document_uris_from_dc): document_data = {} # No 'dc' key. claimant = 'http://localhost:5000/docs/help' parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_dc.assert_called_once_with( {}, claimant)
def test_calling_document_uris_from_highwire_pdf_when_no_highwire( self, document_uris_from_highwire_pdf): document_data = {} # No 'highwire' key. claimant = 'http://localhost:5000/docs/help' parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_highwire_pdf.assert_called_once_with( {}, claimant)
def test_calling_document_uris_from_links_when_no_links( self, document_uris_from_links): document_data = {} # No 'link' key. claimant = 'http://localhost:5000/docs/help' parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_links.assert_called_once_with( [], claimant)
def test_it_calls_documents_uris_from_highwire_doi( self, document_uris_from_highwire_doi): document_data = { 'highwire': { 'doi': [ 'doi_1', 'doi_2', 'doi_3', ] } } claimant = 'http://localhost:5000/docs/help' document_uris_from_highwire_doi.return_value = [ mock.Mock(), mock.Mock(), mock.Mock()] document_uris = parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_highwire_doi.assert_called_once_with( document_data['highwire'], claimant) for document_uri in document_uris_from_highwire_doi.return_value: assert document_uri in document_uris
def validate(self, data): appstruct = self.structure.validate(data) new_appstruct = {} # Some fields are not to be set by the user, ignore them. for field in PROTECTED_FIELDS: appstruct.pop(field, None) new_appstruct['userid'] = self.request.authenticated_userid new_appstruct['target_uri'] = appstruct.pop('uri', u'') new_appstruct['text'] = appstruct.pop('text', u'') new_appstruct['tags'] = appstruct.pop('tags', []) # Replace the client's complex permissions object with a simple shared # boolean. if appstruct.pop('permissions')['read'] == [new_appstruct['userid']]: new_appstruct['shared'] = False else: new_appstruct['shared'] = True # The 'target' dict that the client sends is replaced with a single # annotation.target_selectors whose value is the first selector in # the client'ss target.selectors list. # Anything else in the target dict, and any selectors after the first, # are discarded. target = appstruct.pop('target', []) if target: # Replies and page notes don't have 'target'. target = target[0] # Multiple targets are ignored. new_appstruct['target_selectors'] = target['selector'] new_appstruct['groupid'] = appstruct.pop('group', u'__world__') new_appstruct['references'] = appstruct.pop('references', []) # Replies always get the same groupid as their parent. The parent's # groupid is added to the reply annotation later by the storage code. # Here we just delete any group sent by the client from replies. if new_appstruct['references'] and 'groupid' in new_appstruct: del new_appstruct['groupid'] new_appstruct['extra'] = appstruct # Transform the "document" dict that the client posts into a convenient # format for creating DocumentURI and DocumentMeta objects later. document_data = appstruct.pop('document', {}) document_uri_dicts = parse_document_claims.document_uris_from_data( copy.deepcopy(document_data), claimant=new_appstruct['target_uri']) document_meta_dicts = parse_document_claims.document_metas_from_data( copy.deepcopy(document_data), claimant=new_appstruct['target_uri']) new_appstruct['document'] = { 'document_uri_dicts': document_uri_dicts, 'document_meta_dicts': document_meta_dicts } return new_appstruct
def test_it_calls_document_uri_self_claim(self, document_uri_self_claim): claimant = 'http://example.com/claimant' document_uris = parse_document_claims.document_uris_from_data( {}, claimant) document_uri_self_claim.assert_called_once_with(claimant) assert document_uri_self_claim.return_value in document_uris
def validate(self, data): appstruct = self.structure.validate(data) new_appstruct = {} # Some fields are not to be set by the user, ignore them. for field in PROTECTED_FIELDS: appstruct.pop(field, None) new_appstruct['userid'] = self.request.authenticated_userid new_appstruct['target_uri'] = appstruct.pop('uri', u'') new_appstruct['text'] = appstruct.pop('text', u'') new_appstruct['tags'] = appstruct.pop('tags', []) # Replace the client's complex permissions object with a simple shared # boolean. if appstruct.pop('permissions')['read'] == [new_appstruct['userid']]: new_appstruct['shared'] = False else: new_appstruct['shared'] = True # The 'target' dict that the client sends is replaced with a single # annotation.target_selectors whose value is the first selector in # the client'ss target.selectors list. # Anything else in the target dict, and any selectors after the first, # are discarded. target = appstruct.pop('target', []) if target: # Replies and page notes don't have 'target'. target = target[0] # Multiple targets are ignored. new_appstruct['target_selectors'] = target['selector'] new_appstruct['groupid'] = appstruct.pop('group', u'__world__') new_appstruct['references'] = appstruct.pop('references', []) # Replies always get the same groupid as their parent. The parent's # groupid is added to the reply annotation later by the storage code. # Here we just delete any group sent by the client from replies. if new_appstruct['references'] and 'groupid' in new_appstruct: del new_appstruct['groupid'] new_appstruct['extra'] = appstruct # Transform the "document" dict that the client posts into a convenient # format for creating DocumentURI and DocumentMeta objects later. document_data = appstruct.pop('document', {}) document_uri_dicts = parse_document_claims.document_uris_from_data( copy.deepcopy(document_data), claimant=new_appstruct['target_uri']) document_meta_dicts = parse_document_claims.document_metas_from_data( copy.deepcopy(document_data), claimant=new_appstruct['target_uri']) new_appstruct['document'] = { 'document_uri_dicts': document_uri_dicts, 'document_meta_dicts': document_meta_dicts } return new_appstruct
def _document(document, claimant): """ Return document meta and document URI data from the given document dict. Transforms the "document" dict that the client posts into a convenient format for creating DocumentURI and DocumentMeta objects later. """ document = document or {} document_uri_dicts = parse_document_claims.document_uris_from_data( copy.deepcopy(document), claimant=claimant) document_meta_dicts = parse_document_claims.document_metas_from_data( copy.deepcopy(document), claimant=claimant) return { 'document_uri_dicts': document_uri_dicts, 'document_meta_dicts': document_meta_dicts }
def _document(document, claimant): """ Return document meta and document URI data from the given document dict. Transforms the "document" dict that the client posts into a convenient format for creating DocumentURI and DocumentMeta objects later. """ document = document or {} document_uri_dicts = parse_document_claims.document_uris_from_data( copy.deepcopy(document), claimant=claimant) document_meta_dicts = parse_document_claims.document_metas_from_data( copy.deepcopy(document), claimant=claimant) return { 'document_uri_dicts': document_uri_dicts, 'document_meta_dicts': document_meta_dicts }
def test_it_calls_document_uris_from_links(self, document_uris_from_links): document_data = { 'link': [ # In production these would be link dicts not strings. 'link_dict_1', 'link_dict_2', 'link_dict_3', ] } claimant = 'http://localhost:5000/docs/help' document_uris_from_links.return_value = [ mock.Mock(), mock.Mock(), mock.Mock()] document_uris = parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_links.assert_called_once_with( document_data['link'], claimant) for document_uri in document_uris_from_links.return_value: assert document_uri in document_uris
def test_it_gets_documents_uris_from_dc(self, document_uris_from_dc): document_data = { 'dc': { 'identifier': [ 'doi_1', 'doi_2', 'doi_3', ] } } claimant = 'http://localhost:5000/docs/help' document_uris_from_dc.return_value = [ mock.Mock(), mock.Mock(), mock.Mock()] document_uris = parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_dc.assert_called_once_with( document_data['dc'], claimant) for document_uri in document_uris_from_dc.return_value: assert document_uri in document_uris
def test_it_gets_documents_uris_from_dc(self, document_uris_from_dc): document_data = { 'dc': { 'identifier': [ 'doi_1', 'doi_2', 'doi_3', ] } } claimant = 'http://localhost:5000/docs/help' document_uris_from_dc.return_value = [ mock.Mock(), mock.Mock(), mock.Mock() ] document_uris = parse_document_claims.document_uris_from_data( document_data=document_data, claimant=claimant, ) document_uris_from_dc.assert_called_once_with(document_data['dc'], claimant) for document_uri in document_uris_from_dc.return_value: assert document_uri in document_uris