Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def run(self):

next = commands[i+1] if (i + 1) < count else None

command.update_last_id(last_id)
command.check_combination(state, next)
command.update_last_id(last_id)
command.run(client)

if command.is_error_status() and self.block_on_errors:
Expand Down
5 changes: 3 additions & 2 deletions src/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ def patch_item_fail(cls, mocker, item_id, status_code, json_result):
)

@classmethod
def add_statement_successful(cls, mocker, item_id):
def add_statement_successful(cls, mocker, item_id, response_json=None):
response_json = response_json if response_json else {"id": f"{item_id}$somestuff"}
mocker.patch(
cls.wikibase_url(f"/entities/items/{item_id}"),
json={"id": f"{item_id}$somestuff"},
json=response_json,
status_code=200,
)

Expand Down
47 changes: 47 additions & 0 deletions src/core/tests/test_batch_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,50 @@ def test_remove_qual_or_ref_errors(self, mocker):
self.assertEqual(commands[4].status, BatchCommand.STATUS_ERROR)
self.assertEqual(commands[4].error, BatchCommand.Error.NO_REFERENCE_PARTS)
self.assertEqual(commands[5].status, BatchCommand.STATUS_DONE)

@requests_mock.Mocker()
def test_combine_with_create(self, mocker):
ApiMocker.is_autoconfirmed(mocker)
ApiMocker.wikidata_property_data_types(mocker)
ApiMocker.create_item(mocker, "Q123")
ApiMocker.item_empty(mocker, "Q123")
ApiMocker.add_statement_successful(mocker, "Q123", {"id": "Q123$abcdef"})
ApiMocker.property_data_type(mocker, "P11", "string")
# ---
# COMBINING COMMANDS
# ---
raw = """
CREATE
LAST|P11|"should combine"
LAST|P11|"should combine"
LAST|P11|"should send!"
"""
batch = self.parse(raw)
batch.combine_commands = True
commands = batch.commands()
batch.run()
self.assertEqual(batch.status, Batch.STATUS_DONE)
self.assertEqual(commands[0].response_json, {"id": "Q123"}) # with API connection
self.assertEqual(commands[1].response_json, {}) # no API connection
self.assertEqual(commands[2].response_json, {}) # no API connection
self.assertEqual(commands[3].response_json, {"id": "Q123$abcdef"}) # with API connection
self.assertEqual(len(commands), 4)
for command in commands:
self.assertEqual(command.status, BatchCommand.STATUS_DONE)
# ---
# WITHOUT COMBINING COMMANDS
# ---
v1 = V1CommandParser()
batch = v1.parse("without", "user", raw)
batch.save_batch_and_preview_commands()
batch.combine_commands = False
batch.run()
commands = batch.commands()
self.assertEqual(batch.status, Batch.STATUS_DONE)
self.assertEqual(commands[0].response_json, {"id": "Q123"}) # with API connection
self.assertEqual(commands[1].response_json, {"id": "Q123$abcdef"}) # with API connection
self.assertEqual(commands[2].response_json, {"id": "Q123$abcdef"}) # with API connection
self.assertEqual(commands[3].response_json, {"id": "Q123$abcdef"}) # with API connection
self.assertEqual(len(commands), 4)
for command in commands:
self.assertEqual(command.status, BatchCommand.STATUS_DONE)