コード例 #1
0
    def test_verify(self):
        item = self.r.__getattribute__('Q_' + WikidataHelper.random_name())
        claim = pywikibot.Claim(self.r.bot.site,
                                self.r.P_source_code_repository, 0)
        url = "http://github.com/ceph/ceph"
        claim.setTarget(url)
        item.addClaim(claim)

        to_verify = pywikibot.ItemPage(self.r.bot.site, item.getID(), 0)
        assert {url: 'no protocol'} == self.r.verify(to_verify)

        protocol = pywikibot.Claim(self.r.bot.site, self.r.P_protocol, 0)
        protocol.setTarget(self.r.Q_git)
        claim.addQualifier(protocol, bot=True)

        to_verify = pywikibot.ItemPage(self.r.bot.site, item.getID(), 0)
        assert {url: 'verified'} == self.r.verify(to_verify)

        to_verify = pywikibot.ItemPage(self.r.bot.site, item.getID(), 0)
        assert {url: 'no need'} == self.r.verify(to_verify)

        claim.changeTarget("http://example.org")

        to_verify = pywikibot.ItemPage(self.r.bot.site, item.getID(), 0)
        assert {"http://example.org": 'fail'} == self.r.verify(to_verify)

        self.r.clear_entity_label(item.getID())
コード例 #2
0
    def test_fixup(self):
        bot = Bot.factory([
            '--verbose',
            '--test',
            '--user=FLOSSbotCI',
        ])
        fsd = FSD(bot, bot.args)

        to_fixup = fsd.__getattribute__('Q_' + WikidataHelper.random_name())
        assert 'not found' == fsd.fixup(to_fixup)
        fsd.clear_entity_label(to_fixup.getID())
        to_fixup = pywikibot.ItemPage(fsd.bot.site, to_fixup.getID(), 0)
        assert 'no label' == fsd.fixup(to_fixup)

        label = 'Loomio'
        item = fsd.__getattribute__('Q_' + label)
        # get rid of leftovers in case the item already exists
        fsd.clear_entity_label(item.getID())
        item = fsd.__getattribute__('Q_' + label)

        to_fixup = pywikibot.ItemPage(fsd.bot.site, item.getID(), 0)
        assert 'found' == fsd.fixup(to_fixup)

        to_fixup = pywikibot.ItemPage(fsd.bot.site, item.getID(), 0)
        assert 'already exists' == fsd.fixup(to_fixup)

        fsd.clear_entity_label(item.getID())
コード例 #3
0
 def test_verify_no_value(self):
     item = self.r.__getattribute__('Q_' + WikidataHelper.random_name())
     claim = pywikibot.Claim(self.r.bot.site,
                             self.r.P_source_code_repository, 'novalue')
     # the following sequence is wierd but it's the only combo
     # that works with pywikibot because of some broken
     # code paths when 'novalue' is set
     claim.setTarget('http://url.to.be.ignored')
     item.addClaim(claim)
     claim.changeTarget(None, 'novalue')
     item.get(force=True)
     assert {None: 'novalue or unknown'} == self.r.verify(item)
     self.r.clear_entity_label(item.getID())
コード例 #4
0
 def test_set_retrieved(self):
     bot = Bot.factory([
         '--test',
         '--user=FLOSSbotCI',
     ])
     plugin = Plugin(bot, bot.args)
     item = plugin.__getattribute__('Q_' + WikidataHelper.random_name())
     claim = pywikibot.Claim(plugin.bot.site,
                             plugin.P_source_code_repository, 0)
     claim.setTarget("http://repo.com/some")
     item.addClaim(claim)
     plugin.set_retrieved(item, claim)
     assert plugin.need_verification(claim) is False
     plugin.set_retrieved(item, claim, date(1965, 11, 2))
     assert plugin.need_verification(claim) is True
     plugin.clear_entity_label(item.getID())
コード例 #5
0
 def test_verify_no_value(self):
     bot = Bot.factory([
         '--verbose',
         '--test',
         '--user=FLOSSbotCI',
     ])
     qa = QA(bot, bot.args)
     item = qa.__getattribute__('Q_' + WikidataHelper.random_name())
     claim = pywikibot.Claim(qa.bot.site, qa.P_software_quality_assurance,
                             'novalue')
     claim.setTarget(qa.Q_Continuous_integration)
     item.addClaim(claim)
     claim.changeTarget(None, 'novalue')
     item.get(force=True)
     assert ['no ci'] == qa.verify(item)
     qa.clear_entity_label(item.getID())
コード例 #6
0
    def test_create_entity(self):
        bot = Bot.factory([
            '--test',
            '--user=FLOSSbotCI',
        ])
        plugin = Plugin(bot, bot.args)
        name = 'Q_' + WikidataHelper.random_name()
        item = plugin.__getattribute__(name)
        assert 1 == len(plugin.bot.entities['item'])
        plugin.clear_entity_label(item.getID())
        assert 0 == len(plugin.bot.entities['item'])
        item = plugin.__getattribute__(name)
        assert 1 == len(plugin.bot.entities['item'])

        property2datatype = {
            'P_source_code_repository': 'url',
            'P_website_username': '******',
            'P_protocol': 'wikibase-item',
        }

        bot = Bot.factory([
            '--test',
            '--user=FLOSSbotCI',
        ])
        wikidata_plugin = Plugin(bot, bot.args)
        for (attr, datatype) in property2datatype.items():
            plugin.reset_cache()
            property = plugin.__getattribute__(attr)
            assert 1 == len(plugin.bot.entities['property'])
            plugin.clear_entity_label(property)
            assert 0 == len(plugin.bot.entities['property'])
            for i in range(120):
                if (plugin.lookup_entity(attr, type='property') is None):
                    break
            property = plugin.__getattribute__(attr)
            assert 1 == len(plugin.bot.entities['property'])

            new_content = plugin.bot.site.loadcontent({'ids': property},
                                                      'datatype')
            wikidata_property = wikidata_plugin.__getattribute__(attr)
            wikidata_content = wikidata_plugin.bot.site.loadcontent(
                {'ids': wikidata_property}, 'datatype')
            assert (wikidata_content[wikidata_property]['datatype'] ==
                    new_content[property]['datatype']), attr
            assert (datatype == wikidata_content[wikidata_property]['datatype']
                    ), attr
コード例 #7
0
    def test_search_entity(self):
        bot = Bot.factory([
            '--test',
            '--user=FLOSSbotCI',
            '--verbose',
        ])
        plugin = Plugin(bot, bot.args)
        # ensure space, - and _ are accepted
        name = WikidataHelper.random_name() + "-some thing_else"
        entity = {
            "labels": {
                "en": {
                    "language": "en",
                    "value": name,
                }
            },
        }
        first = plugin.bot.site.editEntity({'new': 'item'}, entity)
        first = pywikibot.ItemPage(bot.site, first['entity']['id'], 0)
        second = plugin.bot.site.editEntity({'new': 'item'}, entity)
        second = pywikibot.ItemPage(bot.site, second['entity']['id'], 0)

        with pytest.raises(ValueError) as e:
            plugin.search_entity(plugin.bot.site, name, type='item')
        assert "found multiple items" in str(e.value)

        claim = pywikibot.Claim(plugin.bot.site, plugin.P_instance_of, 0)
        claim.setTarget(plugin.Q_Wikimedia_disambiguation_page)
        first.addClaim(claim)

        found = plugin.search_entity(bot.site, name, type='item')
        assert found.getID() == second.getID()

        plugin.bot.site.editEntity({'new': 'item'}, entity)

        with pytest.raises(ValueError) as e:
            plugin.search_entity(plugin.bot.site, name, type='item')
        assert "found multiple items" in str(e.value)

        Plugin.authoritative['test'][name] = second.getID()
        found = plugin.search_entity(plugin.bot.site, name, type='item')
        assert found.getID() == second.getID()
コード例 #8
0
 def test_get_source_code_repository(self):
     item = self.r.__getattribute__('Q_' + WikidataHelper.random_name())
     claim_no_value = pywikibot.Claim(self.r.bot.site,
                                      self.r.P_source_code_repository,
                                      'novalue')
     # the following sequence is wierd but it's the only combo
     # that works with pywikibot because of some broken
     # code paths when 'novalue' is set
     claim_no_value.setTarget('http://url.to.be.ignored')
     item.addClaim(claim_no_value)
     claim_no_value.changeTarget(None, 'novalue')
     claim = pywikibot.Claim(self.r.bot.site,
                             self.r.P_source_code_repository, 0)
     url = "http://github.com/ceph/ceph"
     claim.setTarget(url)
     item.addClaim(claim)
     item.get(force=True)
     repositories = self.r.get_source_code_repositories(item)
     assert len(repositories) == 1
     assert repositories[0].getTarget() == url
     self.r.clear_entity_label(item.getID())
コード例 #9
0
 def setup_class(cls):
     WikidataHelper().login()
コード例 #10
0
 def setup_class(self):
     WikidataHelper().login()
コード例 #11
0
    def test_verify(self, m_get):
        url2code = {}

        def get(url, **kwargs):
            log.debug(url + " " + str(kwargs))

            class c:
                def __init__(self, code):
                    self.status_code = code

            return c(url2code.get(url, requests.codes.ok))

        m_get.side_effect = get
        bot = Bot.factory([
            '--verbose',
            '--test',
            '--user=FLOSSbotCI',
            '--verification-delay=0',
        ])
        qa = QA(bot, bot.args)
        item = qa.__getattribute__('Q_' + WikidataHelper.random_name())

        log.debug(">> do nothing if there is no source code repository")
        item.get(force=True)
        assert ['nothing'] == qa.verify(item)

        log.debug(">> add a source code repository")
        repository = pywikibot.Claim(qa.bot.site, qa.P_source_code_repository,
                                     0)
        url = "http://github.com/FAKE1/FAKE2"
        repository.setTarget(url)
        item.addClaim(repository)

        log.debug(">> add a qa statement")
        item.get(force=True)
        qa.fixup(item)

        log.debug(">> no ci found")
        item.get(force=True)
        url2code['https://travis-ci.org/FAKE1/FAKE2'] = 404
        assert ['no ci found'] == qa.verify(item)

        log.debug(">> verified")
        del url2code['https://travis-ci.org/FAKE1/FAKE2']
        assert ['verified'] == qa.verify(item)

        log.debug(">> no need")
        qa.args.verification_delay = 30
        assert ['no need'] == qa.verify(item)
        qa.args.verification_delay = 0

        log.debug(">> inconsistent qualifier")
        repository.changeTarget("http://github.com/other/other")
        item.get(force=True)
        assert (['archive URL gone',
                 'described at URL gone'] == qa.verify(item))

        log.debug(">> missing qualifier")
        qa_claim = item.claims[qa.P_software_quality_assurance][0]
        archive_URL = qa_claim.qualifiers[qa.P_archive_URL][0]
        qa_claim.removeQualifier(archive_URL)
        item.get(force=True)
        assert ['archive URL missing qualifier',
                'described at URL gone'] == qa.verify(item)

        qa.clear_entity_label(item.getID())