def test_url_new_citation_with_bibcode(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017arXiv170305698M'
        citation_change.cited = '2017iagt.conf.2017G'
        citation_change.content = 'http://www.github.com/capergroup/bayou'
        citation_change.content_type = adsmsg.CitationChangeContentType.url
        citation_change.resolved = True
        citation_change.status = adsmsg.Status.new
        expected_event_type = "relation_created"
        expected_original_relationship_name = "Cites"
        expected_source_bibcode = citation_change.citing
        expected_target_id = citation_change.content
        expected_target_id_schema = u"URL"
        expected_target_url = citation_change.content
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertTrue(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
        request = httpretty.last_request()
        self._assert_request(request, expected_json_body)
Example #2
0
    def next(self): # Python 3: def __next__(self)
        """Iterates over the results, grouping changes in chunks"""
        if self.offset >= self.n_changes or self.n_changes == 0:
            raise StopIteration
        else:
            citation_changes = adsmsg.CitationChanges()
            # Get citation changes from DB
            for instance in self._citation_changes_query().offset(self.offset).limit(self.group_changes_in_chunks_of).yield_per(100):
                ## Build protobuf message
                citation_change = citation_changes.changes.add()
                # Use new_ or previous_ fields depending if status is NEW/UPDATED or DELETED
                prefix = "previous_" if instance.status == "DELETED" else "new_"
                citation_change.citing = getattr(instance, prefix+"citing")
                resolved = getattr(instance, prefix+"resolved")
                citation_change.cited = getattr(instance, prefix+"cited")
                if getattr(instance, prefix+"doi"):
                    citation_change.content_type = adsmsg.CitationChangeContentType.doi
                elif getattr(instance, prefix+"pid"):
                    citation_change.content_type = adsmsg.CitationChangeContentType.pid
                elif getattr(instance, prefix+"url"):
                    citation_change.content_type = adsmsg.CitationChangeContentType.url
                citation_change.content = getattr(instance, prefix+"content")
                citation_change.resolved = getattr(instance, prefix+"resolved")
                citation_change.timestamp.FromDatetime(self.last_modification_date)
                citation_change.status = getattr(adsmsg.Status, instance.status.lower())
            self.session.commit()

            self.offset += self.group_changes_in_chunks_of
            return citation_changes
    def test_doi_updated_citation_with_bibcode(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '1998CP....232..343L'
        citation_change.content = '1991SPIE.1361.1048S'
        citation_change.content_type = adsmsg.CitationChangeContentType.doi
        citation_change.resolved = True
        citation_change.status = adsmsg.Status.updated
        expected_event_type = "relation_created"
        expected_original_relationship_name = "IsIdenticalTo"
        expected_source_bibcode = citation_change.cited
        expected_target_id = citation_change.content
        expected_target_id_schema = u"DOI"
        expected_target_url = "https://doi.org"
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertFalse(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
    def test_doi_deleted_citation_with_bibcode(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2000JMP....41.1788O'
        citation_change.cited = '1990JMP....31..316D'
        citation_change.content = '10.1063/1.528916'
        citation_change.content_type = adsmsg.CitationChangeContentType.doi
        citation_change.resolved = True
        citation_change.status = adsmsg.Status.deleted
        expected_event_type = "relation_deleted"
        expected_original_relationship_name = "Cites"
        expected_source_bibcode = citation_change.citing
        expected_target_id = citation_change.content
        expected_target_id_schema = "doi"
        expected_target_url = "https://doi.org/{}".format(expected_target_id)
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(
            citation_change, expected_json_body)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertTrue(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
        request = httpretty.last_request()
        self._assert_request(request, expected_json_body)
    def test_ascl_deleted_citation_with_bibcode(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017AJ....153..114F'
        citation_change.cited = '2012ascl.soft03003C'
        citation_change.content = 'ascl:1203.003'
        citation_change.content_type = adsmsg.CitationChangeContentType.pid
        citation_change.resolved = True
        citation_change.status = adsmsg.Status.deleted
        expected_event_type = "relation_deleted"
        expected_original_relationship_name = "Cites"
        expected_source_bibcode = citation_change.citing
        expected_target_id = citation_change.content
        expected_target_id_schema = "ascl"
        expected_target_url = "https://ascl.net/{}".format(expected_target_id)
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertFalse(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
    def test_url_updated_citation_with_bibcode(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2016NatSR...637369S'
        citation_change.cited = '2012JOSS...61..539R'  # previous_cited 2012ASSL..304..539R
        citation_change.content = 'http://mrbayes.sourceforge.net/'
        citation_change.content_type = adsmsg.CitationChangeContentType.url
        citation_change.resolved = True
        citation_change.status = adsmsg.Status.updated
        expected_event_type = "relation_created"
        expected_original_relationship_name = "IsIdenticalTo"
        expected_source_bibcode = citation_change.cited
        expected_target_id = citation_change.content
        expected_target_id_schema = u"URL"
        expected_target_url = citation_change.content
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertFalse(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
    def test_doi_new_citation(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2005CaJES..42.1987P'
        citation_change.cited = '...................'
        citation_change.content = '10.1016/0277-3791'
        citation_change.content_type = adsmsg.CitationChangeContentType.doi
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.new
        expected_event_type = "relation_created"
        expected_original_relationship_name = "Cites"
        expected_source_bibcode = citation_change.citing
        expected_target_id = citation_change.content
        expected_target_id_schema = u"DOI"
        expected_target_url = "https://doi.org"
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertTrue(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
        request = httpretty.last_request()
        self._assert_request(request, expected_json_body)
 def test_doi_updated_citation(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '1999ITGRS..37..917L'
     citation_change.cited = '...................'  # previous_cited 1997ASAJ..101Q3182L
     citation_change.content = '10.1121/1.419176'
     citation_change.content_type = adsmsg.CitationChangeContentType.doi
     citation_change.resolved = False
     citation_change.status = adsmsg.Status.updated
     is_link_alive = False
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     event_data = webhook.citation_change_to_event_data(
         citation_change, parsed_metadata)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertFalse(
         emitted,
         "Non-agreed citation change was assigned to an agreed event")
    def test_ascl_new_citation_with_bibcode(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017A&A...603A.117S'
        citation_change.cited = '2011ascl.soft06002P'
        citation_change.content = 'ascl:1106.002'
        citation_change.content_type = adsmsg.CitationChangeContentType.pid
        citation_change.resolved = True
        citation_change.status = adsmsg.Status.new
        expected_event_type = "relation_created"
        expected_original_relationship_name = "Cites"
        expected_source_bibcode = citation_change.citing
        expected_target_id = citation_change.content
        expected_target_id_schema = u"ASCL"
        expected_target_url = "http://ascl.net/"
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertTrue(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
        request = httpretty.last_request()
        self._assert_request(request, expected_json_body)
    def test_ascl_deleted_citation(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = ''
        citation_change.cited = '...................'
        citation_change.content = ''
        citation_change.content_type = adsmsg.CitationChangeContentType.pid
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.deleted
        expected_event_type = "relation_deleted"
        expected_original_relationship_name = "Cites"
        expected_source_bibcode = citation_change.citing
        expected_target_id = citation_change.content
        expected_target_id_schema = u"ASCL"
        expected_target_url = "http://ascl.net/"
        expected_json_body = self._build_expected_json_body(
            expected_event_type, expected_original_relationship_name,
            expected_source_bibcode, expected_target_id,
            expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                     self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                     event_data,
                                     timeout=30)
        self.assertFalse(
            emitted,
            "Agreed citation change was NOT assigned to an agreed event")
Example #11
0
 def test_url_updated_citation(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '2016CMAME.305..579P'
     citation_change.cited = '...................'  # previous_cited 2015LIACo...3....2T
     citation_change.content = 'https://github.com/su2code/TestCases'
     citation_change.content_type = adsmsg.CitationChangeContentType.url
     citation_change.resolved = False
     citation_change.status = adsmsg.Status.updated
     is_link_alive = False
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     event_data = webhook.citation_change_to_event_data(
         citation_change, parsed_metadata)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertFalse(
         emitted,
         "Non-agreed citation change was assigned to an agreed event")
Example #12
0
 def test_ascl_updated_citation(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '2013MNRAS.432.1658C'
     citation_change.cited = '...................'  # previous_cited 2012ascl.soft05004P
     citation_change.content = 'ascl:1205.004'
     citation_change.content_type = adsmsg.CitationChangeContentType.pid
     citation_change.resolved = False
     citation_change.status = adsmsg.Status.updated
     is_link_alive = False
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     event_data = webhook.citation_change_to_event_data(
         citation_change, parsed_metadata)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertFalse(
         emitted,
         "Non-agreed citation change was assigned to an agreed event")
Example #13
0
 def _common_citation_changes_doi(self, status):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '2005CaJES..42.1987P'
     citation_change.cited = '...................'
     citation_change.content = '10.5281/zenodo.11020'
     citation_change.content_type = adsmsg.CitationChangeContentType.doi
     citation_change.resolved = False
     citation_change.status = status
     return citation_changes
Example #14
0
 def test_url_updated_citation(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '2016CMAME.305..579P'
     citation_change.cited = '...................' # previous_cited 2015LIACo...3....2T
     citation_change.content = 'https://github.com/su2code/TestCases'
     citation_change.content_type = adsmsg.CitationChangeContentType.url
     citation_change.resolved = False
     citation_change.status = adsmsg.Status.updated
     event_data = webhook.citation_change_to_event_data(citation_change)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'], self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'], event_data, timeout=30)
     self.assertFalse(emitted, "Non-agreed citation change was assigned to an agreed event")
Example #15
0
    def test_process_citation_changes_malformed_url(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017arXiv170610086M'
        citation_change.cited = '...................'
        citation_change.content = 'malformedhttps://github.com/ComputationalRadiationPhysics/graybat'
        citation_change.content_type = adsmsg.CitationChangeContentType.url
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.new

        with patch.object(webhook, 'emit_event', return_value=True) as webhook_emit_event:
            tasks.task_process_citation_changes(citation_changes)
            self.assertFalse(webhook_emit_event.called) # because URL does not match an URL pattern
Example #16
0
    def test_ascl_updated_citation(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2013MNRAS.432.1658C'
        citation_change.cited = '...................' # previous_cited 2012ascl.soft05004P
        citation_change.content = 'ascl:1205.004'
        citation_change.content_type = adsmsg.CitationChangeContentType.pid
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.updated

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'], self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'], event_data, timeout=30)
        self.assertFalse(emitted, "Non-agreed citation change was assigned to an agreed event")
Example #17
0
    def test_doi_updated_citation(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '1999ITGRS..37..917L'
        citation_change.cited = '...................' # previous_cited 1997ASAJ..101Q3182L
        citation_change.content = '10.1121/1.419176'
        citation_change.content_type = adsmsg.CitationChangeContentType.doi
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.updated

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'], self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'], event_data, timeout=30)
        self.assertFalse(emitted, "Non-agreed citation change was assigned to an agreed event")
Example #18
0
    def test_process_citation_changes_ascl(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017MNRAS.470.1687B'
        citation_change.cited = '...................'
        citation_change.content = 'ascl:1210.002'
        citation_change.content_type = adsmsg.CitationChangeContentType.pid
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.new

        with patch.object(webhook, 'emit_event', return_value=True) as webhook_emit_event:
            with patch.object(url, 'is_alive', return_value=True) as url_is_alive:
                tasks.task_process_citation_changes(citation_changes)
                self.assertTrue(url_is_alive.called)
                self.assertTrue(webhook_emit_event.called)
Example #19
0
    def test_process_citation_changes_empty(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017arXiv170610086M'
        citation_change.cited = '...................'
        citation_change.content = ''
        citation_change.content_type = adsmsg.CitationChangeContentType.url
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.new

        with patch.object(webhook, 'emit_event', return_value=True) as webhook_emit_event:
            with patch.object(url, 'is_alive', return_value=True) as url_is_alive:
                tasks.task_process_citation_changes(citation_changes)
                self.assertFalse(url_is_alive.called)
                self.assertFalse(webhook_emit_event.called)
Example #20
0
    def test_process_citation_changes_doi(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2005CaJES..42.1987P'
        citation_change.cited = '...................'
        citation_change.content = '10.1016/0277-3791'
        citation_change.content_type = adsmsg.CitationChangeContentType.doi
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.new

        with patch.object(webhook, 'emit_event', return_value=True) as webhook_emit_event:
            with patch.object(doi, 'is_software', return_value=True) as doi_is_software:
                tasks.task_process_citation_changes(citation_changes)
                self.assertTrue(doi_is_software.called)
                self.assertTrue(webhook_emit_event.called)
Example #21
0
    def test_process_citation_changes_url(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017arXiv170610086M'
        citation_change.cited = '...................'
        citation_change.content = 'https://github.com/ComputationalRadiationPhysics/graybat'
        citation_change.content_type = adsmsg.CitationChangeContentType.url
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.new

        with patch.object(webhook, 'emit_event', return_value=True) as webhook_emit_event:
            with patch.object(url, 'is_alive', return_value=True) as url_is_alive:
                tasks.task_process_citation_changes(citation_changes)
                self.assertTrue(url_is_alive.called)
                self.assertFalse(webhook_emit_event.called) # because we don't know if an URL is software
Example #22
0
 def test_doi_new_citation(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '2005CaJES..42.1987P'
     citation_change.cited = '...................'
     citation_change.content = '10.1016/0277-3791'
     citation_change.content_type = adsmsg.CitationChangeContentType.doi
     citation_change.resolved = False
     citation_change.status = adsmsg.Status.new
     expected_event_type = "relation_created"
     expected_original_relationship_name = "Cites"
     expected_source_bibcode = citation_change.citing
     expected_target_id = citation_change.content
     expected_target_id_schema = "doi"
     expected_target_url = "https://doi.org/{}".format(expected_target_id)
     is_link_alive = True
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     expected_json_body = self._build_expected_json_body(
         expected_event_type, expected_original_relationship_name,
         expected_source_bibcode, expected_target_id,
         expected_target_id_schema, expected_target_url,
         parsed_metadata.get('doctype', ""),
         parsed_metadata.get('license_url', ""))
     event_data = webhook.citation_change_to_event_data(
         citation_change, parsed_metadata)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertTrue(
         emitted,
         "Agreed citation change was NOT assigned to an agreed event")
     request = httpretty.last_request()
     self._assert_request(request, expected_json_body)
Example #23
0
 def test_url_new_citation_with_bibcode(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '2017arXiv170305698M'
     citation_change.cited = '2017iagt.conf.2017G'
     citation_change.content = 'http://www.github.com/capergroup/bayou'
     citation_change.content_type = adsmsg.CitationChangeContentType.url
     citation_change.resolved = True
     citation_change.status = adsmsg.Status.new
     expected_event_type = "relation_created"
     expected_original_relationship_name = "Cites"
     expected_source_bibcode = citation_change.citing
     expected_target_id = citation_change.content
     expected_target_id_schema = "url"
     expected_target_url = citation_change.content
     is_link_alive = True
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     expected_json_body = self._build_expected_json_body(
         expected_event_type, expected_original_relationship_name,
         expected_source_bibcode, expected_target_id,
         expected_target_id_schema, expected_target_url,
         parsed_metadata.get('doctype', ""),
         parsed_metadata.get('license_url', ""))
     event_data = webhook.citation_change_to_event_data(
         citation_change, parsed_metadata)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertTrue(
         emitted,
         "Agreed citation change was NOT assigned to an agreed event")
     request = httpretty.last_request()
     self._assert_request(request, expected_json_body)
Example #24
0
 def test_url_updated_citation_with_bibcode(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '2016NatSR...637369S'
     citation_change.cited = '2012JOSS...61..539R'  # previous_cited 2012ASSL..304..539R
     citation_change.content = 'http://mrbayes.sourceforge.net/'
     citation_change.content_type = adsmsg.CitationChangeContentType.url
     citation_change.resolved = True
     citation_change.status = adsmsg.Status.updated
     expected_event_type = "relation_created"
     expected_original_relationship_name = "IsIdenticalTo"
     expected_source_bibcode = citation_change.cited
     expected_target_id = citation_change.content
     expected_target_id_schema = "url"
     expected_target_url = citation_change.content
     is_link_alive = True
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     expected_json_body = self._build_expected_json_body(
         expected_event_type, expected_original_relationship_name,
         expected_source_bibcode, expected_target_id,
         expected_target_id_schema, expected_target_url,
         parsed_metadata.get('doctype', ""),
         parsed_metadata.get('license_url', ""))
     event_data = webhook.citation_change_to_event_data(
         citation_change, parsed_metadata)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertFalse(
         emitted,
         "Agreed citation change was NOT assigned to an agreed event")
Example #25
0
    def test_url_new_citation(self):
        citation_changes = adsmsg.CitationChanges()
        citation_change = citation_changes.changes.add()
        citation_change.citing = '2017arXiv170610086M'
        citation_change.cited = '...................'
        citation_change.content = 'https://github.com/ComputationalRadiationPhysics/graybat'
        citation_change.content_type = adsmsg.CitationChangeContentType.url
        citation_change.resolved = False
        citation_change.status = adsmsg.Status.new
        expected_event_type = "relation_created"
        expected_original_relationship_name = "Cites"
        expected_source_bibcode = citation_change.citing
        expected_target_id = citation_change.content
        expected_target_id_schema = u"url"
        expected_target_url = citation_change.content
        expected_json_body = self._build_expected_json_body(expected_event_type, expected_original_relationship_name, expected_source_bibcode, expected_target_id, expected_target_id_schema, expected_target_url)

        event_data = webhook.citation_change_to_event_data(citation_change)
        emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'], self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'], event_data, timeout=30)
        self.assertTrue(emitted, "Agreed citation change was NOT assigned to an agreed event")
        request = httpretty.last_request()
        self._assert_request(request, expected_json_body)
Example #26
0
 def test_doi_updated_citation_with_bibcode(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = '1998CP....232..343L'
     citation_change.content = '1991SPIE.1361.1048S'
     citation_change.content_type = adsmsg.CitationChangeContentType.doi
     citation_change.resolved = True
     citation_change.status = adsmsg.Status.updated
     expected_event_type = "relation_created"
     expected_original_relationship_name = "IsIdenticalTo"
     expected_source_bibcode = citation_change.cited
     expected_target_id = citation_change.content
     expected_target_id_schema = "doi"
     expected_target_url = "https://doi.org/{}".format(expected_target_id)
     is_link_alive = True
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     expected_json_body = self._build_expected_json_body(
         expected_event_type, expected_original_relationship_name,
         expected_source_bibcode, expected_target_id,
         expected_target_id_schema, expected_target_url,
         parsed_metadata.get('doctype', ""),
         parsed_metadata.get('license_url', ""))
     event_data = webhook.citation_change_to_event_data(
         citation_change, parsed_metadata)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertFalse(
         emitted,
         "Agreed citation change was NOT assigned to an agreed event")
Example #27
0
 def test_ascl_deleted_citation(self):
     citation_changes = adsmsg.CitationChanges()
     citation_change = citation_changes.changes.add()
     citation_change.citing = ''
     citation_change.cited = '...................'
     citation_change.content = ''
     citation_change.content_type = adsmsg.CitationChangeContentType.pid
     citation_change.resolved = False
     citation_change.status = adsmsg.Status.deleted
     expected_event_type = "relation_deleted"
     expected_original_relationship_name = "Cites"
     expected_source_bibcode = citation_change.citing
     expected_target_id = citation_change.content
     expected_target_id_schema = "ascl"
     expected_target_url = "https://ascl.net/{}".format(expected_target_id)
     is_link_alive = True
     license_info = {
         'license_url': 'https://creativecommons.org/publicdomain/zero/1.0/'
     }
     parsed_metadata = {
         'link_alive': is_link_alive,
         "doctype": "software",
         'license_name': license_info.get('license_name', ""),
         'license_url': license_info.get('license_url', "")
     }
     expected_json_body = self._build_expected_json_body(
         expected_event_type, expected_original_relationship_name,
         expected_source_bibcode, expected_target_id,
         expected_target_id_schema, expected_target_url,
         parsed_metadata.get('doctype', ""),
         parsed_metadata.get('license_url', ""))
     event_data = webhook.citation_change_to_event_data(citation_change)
     emitted = webhook.emit_event(self.app.conf['ADS_WEBHOOK_URL'],
                                  self.app.conf['ADS_WEBHOOK_AUTH_TOKEN'],
                                  event_data,
                                  timeout=30)
     self.assertFalse(
         emitted,
         "Agreed citation change was NOT assigned to an agreed event")