jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, but someone else must approve Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[bugfix] ClaimCollection.toJSON() should not ignore new claims

Bug: T308245
Change-Id: I03195961d890b0476d1c2b7bc965da66a18c00a3
---
M pywikibot/page/_collections.py
M tests/wikibase_edit_tests.py
2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/pywikibot/page/_collections.py b/pywikibot/page/_collections.py
index 84ecfad..cbf9c6c 100644
--- a/pywikibot/page/_collections.py
+++ b/pywikibot/page/_collections.py
@@ -277,6 +277,7 @@

for claim, json in zip(self[prop], claims[prop]):
if 'id' not in json:
+ temp[prop].append(json)
continue

claim_ids.add(json['id'])
diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py
index 589d12d..0de943f 100755
--- a/tests/wikibase_edit_tests.py
+++ b/tests/wikibase_edit_tests.py
@@ -534,6 +534,67 @@
self.assertIsNone(self.item.sitelinks.get('enwikisource'))


+class TestWikibaseAddClaimToExisting(WikibaseTestCase):
+
+ """Run wikibase write tests for claims."""
+
+ family = 'wikidata'
+ code = 'test'
+
+ login = True
+ write = True
+
+ @staticmethod
+ def _clean_item_temp(repo, prop: str):
+ """
+ Return an item without any existing claims of the given property.
+
+ :param repo: repository to fetch item from
+ :type repo: pywikibot.site.DataSite
+ :param prop: P-value of the property to scrub
+ :return: scrubbed item
+ :rtype: pywikibot.ItemPage
+ """
+ item = pywikibot.ItemPage(repo, 'Q68')
+ item.get()
+ if prop in item.claims:
+ item.removeClaims(item.claims[prop])
+ item.get(force=True)
+ return item
+
+ def test_multiple_changes(self):
+ """Make multiple changes with EditEntity."""
+ testsite = self.get_repo()
+ prop = 'P95931'
+ item = self._clean_item_temp(testsite, prop)
+
+ # set initial claim
+ claim0 = pywikibot.page.Claim(testsite, prop)
+ target0 = 'treccid0'
+ claim0.setTarget(target0)
+ item.claims[prop] = [claim0]
+ item.editEntity(summary='Set initial claim')
+
+ # confirm initial claim
+ item.get(force=True)
+ claim1 = item.claims[prop][0]
+ self.assertEqual(claim1.getTarget(), target0)
+
+ # set second claim
+ claim1 = pywikibot.page.Claim(testsite, prop)
+ target1 = 'treccid1'
+ claim1.setTarget(target1)
+ item.claims[prop].append(claim1)
+ item.editEntity(summary='Set second claim')
+
+ # confirm two claims
+ item.get(force=True)
+ claim0 = item.claims[prop][0]
+ self.assertEqual(claim0.getTarget(), target0)
+ claim1 = item.claims[prop][1]
+ self.assertEqual(claim1.getTarget(), target1)
+
+
if __name__ == '__main__': # pragma: no cover
with suppress(SystemExit):
unittest.main()

To view, visit change 791428. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I03195961d890b0476d1c2b7bc965da66a18c00a3
Gerrit-Change-Number: 791428
Gerrit-PatchSet: 4
Gerrit-Owner: William Avery <will@willavery.net>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged