Skip to content

Commit

Permalink
Namor/SPT-14498: Bulk record create endpoint does not return a list o…
Browse files Browse the repository at this point in the history
…f created records (#148)

* SPT-14498: Bulk record create endpoint does not return a list of created records

Bulk record create endpoint does not return a list of created records

* Revert "SPT-14498: Bulk record create endpoint does not return a list of created records"

This reverts commit 00d5224.

* SPT-14498: return tracking ids on bulk record create.

add tests

* SPT-14498: Bulk record create endpoint does not return a list of created records

Bulk record create endpoint does not return a list of created records

* SPT-14498: Bulk record create endpoint does not return a list of created records

Bulk record create endpoint does not return a list of created records

* Revert "SPT-14498: Bulk record create endpoint does not return a list of created records"

This reverts commit ed14a3c.

* Revert "SPT-14498: Bulk record create endpoint does not return a list of created records"

This reverts commit d4cedba.

* Revert "SPT-14498: return tracking ids on bulk record create."

This reverts commit c3a428f.

* SPT-14498: return tracking id list on bulk create

return tracking Id list on bulk create.

* SPT-14498:return tracking id list on bulk create of records

add pytest

* SPT-14498: return tracking ids upon bulk create

bring back those changes.

* SPT-14498: return tracking id list on bulk create

remove two records so that actual does not go beyond 50 which is search limit.

Co-authored-by: Surya Pabbineedi <[email protected]>
  • Loading branch information
Tameezuddin and surya-pabbineedi authored Sep 9, 2022
1 parent 798ff50 commit 73d526c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 61 deletions.
147 changes: 88 additions & 59 deletions functional_tests/driver_tests/test_records_bulk_adaptor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random
import uuid
import pytest
import pendulum
from swimlane import exceptions
Expand Down Expand Up @@ -27,18 +29,31 @@ class TestRecordAdaptorBulkCreate:
def test_record_bulk_create_empty(helpers):
initialEmptyRecords = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', None)))
pytest.app.records.bulk_create({}, {}, {}, {})

pytest.app.records.bulk_create({},{},{},{})
emptyRecords = pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', None))
assert len(emptyRecords) == 4+initialEmptyRecords

def test_record_bulk_create_check_TrackingIds(helpers):
initialEmptyRecords = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', None)))
joy = str(uuid.uuid4())
recIds = pytest.app.records.bulk_create({'Text': joy}, {'Text': joy}, {
'Text': joy}, {'Text': joy})
emptyRecords = pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', None))
assert len(recIds) == 4

def test_record_bulk_create_with_values(helpers):
joy = str(uuid.uuid4())
initalRecords = len(pytest.app.records.search(
('Text', 'equals', 'Happy Joy'), ('Numeric', 'equals', None)))
pytest.app.records.bulk_create({'Text': 'Happy Joy'}, {'Text': 'Happy Joy'}, {
'Text': 'Happy Joy'}, {'Text': 'Happy Joy'})
('Text', 'equals', joy), ('Numeric', 'equals', None)))

pytest.app.records.bulk_create({'Text': joy}, {'Text': joy}, {
'Text': joy}, {'Text': joy})
matchingRecords = pytest.app.records.search(
('Text', 'equals', 'Happy Joy'), ('Numeric', 'equals', None))
('Text', 'equals', joy), ('Numeric', 'equals', None))
assert len(matchingRecords) == 4 + initalRecords

def test_record_bulk_create_with_invalid_field_name(helpers):
Expand Down Expand Up @@ -98,17 +113,18 @@ def test_record_bulk_delete_list_records_already_deleted(helpers):
pytest.waitOnJobByID(records)

def test_record_bulk_delete_filter(helpers):
i = random.randint(0,300)
initalRecords = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 234)))
pytest.app.records.bulk_create({'Numeric': 234}, {'Numeric': 234}, {
'Numeric': 234}, {'Numeric': 234})
('Text', 'equals', None), ('Numeric', 'equals', i)))
pytest.app.records.bulk_create({'Numeric': i}, {'Numeric': i}, {
'Numeric': i}, {'Numeric': i})
assert len(pytest.app.records.search(('Text', 'equals', None),
('Numeric', 'equals', 234))) == 4+initalRecords
('Numeric', 'equals', i))) == 4 + initalRecords
records = pytest.app.records.bulk_delete(
('Text', 'equals', None), ('Numeric', 'equals', 234))
('Text', 'equals', None), ('Numeric', 'equals', i))
pytest.waitOnJobByID(records)
assert len(pytest.app.records.search(('Text', 'equals', None),
('Numeric', 'equals', 234))) == initalRecords
('Numeric', 'equals', i))) == initalRecords

def test_record_bulk_delete_filter_invalid_field(helpers):
randomFieldName = 'Some Garbage'
Expand All @@ -132,7 +148,7 @@ def test_record_bulk_delete_filter_invalid_value(helpers):
pytest.app.name, pytest.app.acronym, randomFieldName)

def test_record_bulk_delete_list_twice(helpers):
textValue = "Delete Me twice"
textValue = str(uuid.uuid4())
pytest.app.records.bulk_create({'Text': textValue}, {'Text': textValue}, {
'Text': textValue}, {'Text': textValue})

Expand All @@ -159,36 +175,41 @@ def test_record_bulk_delete_list_twice(helpers):

class TestRecordAdaptorBulkModify:
def test_record_bulk_modify_filter(helpers):
i = random.randint(0,100)
inital99Records = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 99)))
('Text', 'equals', None), ('Numeric', 'equals', i)))
i1 = random.randint(0,100000)
inital989765Records = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 98765)))
pytest.app.records.bulk_create({'Numeric': 99}, {'Numeric': 99}, {
'Numeric': 99}, {'Numeric': 99})
('Text', 'equals', None), ('Numeric', 'equals', i1)))
pytest.app.records.bulk_create({'Numeric': i}, {'Numeric': i}, {
'Numeric': i}, {'Numeric': i})
records = pytest.app.records.bulk_modify(
('Text', 'equals', None), ('Numeric', 'equals', 99), values={'Numeric': 98765})
('Text', 'equals', None), ('Numeric', 'equals', i), values={'Numeric': i1})
pytest.waitOnJobByID(records)
assert len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 99))) == 0
('Text', 'equals', None), ('Numeric', 'equals', i))) == 0
assert len(pytest.app.records.search(('Text', 'equals', None), ('Numeric',
'equals', 98765))) == 4 + inital99Records + inital989765Records
'equals',
i1))) == 4 + inital99Records + inital989765Records

def test_record_bulk_modify_no_filter(helpers):
i = random.randint(0,100)
initial99Records = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 99)))
('Text', 'equals', None), ('Numeric', 'equals', i)))
i1 = random.randint(0,9999)
initial6666Records = len(
pytest.app.records.search(('Numeric', 'equals', 6666)))
pytest.app.records.bulk_create({'Numeric': 99}, {'Numeric': 99}, {
'Numeric': 99}, {'Numeric': 99})
pytest.app.records.search(('Numeric', 'equals', i1)))
pytest.app.records.bulk_create({'Numeric': i}, {'Numeric': i}, {
'Numeric': i}, {'Numeric': i})
with pytest.raises(ValueError) as excinfo:
records = pytest.app.records.bulk_modify(values={'Numeric': 6666})
records = pytest.app.records.bulk_modify(values={'Numeric': i1})
pytest.waitOnJobByID(records)
assert str(
excinfo.value) == 'Must provide at least one filter tuples or Records'
assert len(pytest.app.records.search(('Text', 'equals', None),
('Numeric', 'equals', 99))) == 4 + initial99Records
('Numeric', 'equals', i))) == 4 + initial99Records
assert len(pytest.app.records.search(
('Numeric', 'equals', 6666))) == initial6666Records
('Numeric', 'equals', i1))) == initial6666Records

def test_record_bulk_modify_no_filter_matches(helpers):
assert len(pytest.app.records.search(
Expand Down Expand Up @@ -225,21 +246,23 @@ def test_record_bulk_modify_filter_invalid_value(helpers):
pytest.app.name, pytest.app.acronym, randomValue)

def test_record_bulk_modify_list(helpers):
i = random.randint(0,99)
initial66Records = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 66)))
('Text', 'equals', None), ('Numeric', 'equals', i)))
i1 = random.randint(0,9999)
initial4321Records = len(pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 4321)))
pytest.app.records.bulk_create({'Numeric': 66}, {'Numeric': 66}, {
'Numeric': 66}, {'Numeric': 66})
('Text', 'equals', None), ('Numeric', 'equals', i1)))
pytest.app.records.bulk_create({'Numeric': i}, {'Numeric': i}, {
'Numeric': i}, {'Numeric': i})
recordList = pytest.app.records.search(
('Text', 'equals', None), ('Numeric', 'equals', 66))
('Text', 'equals', None), ('Numeric', 'equals', i))
records = pytest.app.records.bulk_modify(
*recordList, values={'Numeric': 4321})
*recordList, values={'Numeric': i1})
pytest.waitOnJobByID(records)
assert len(pytest.app.records.search(('Text', 'equals', None),
('Numeric', 'equals', 66))) == initial66Records
('Numeric', 'equals', i))) == initial66Records
assert len(pytest.app.records.search(('Text', 'equals', None),
('Numeric', 'equals', 4321))) == 4 + initial4321Records
('Numeric', 'equals', i1))) == 4 + initial4321Records

def test_record_bulk_modify_list_records_already_deleted(helpers):
deleteRecord = pytest.app.records.create(**{})
Expand All @@ -256,28 +279,30 @@ def test_record_bulk_modify_list_records_already_deleted(helpers):

class TestRecordAdaptorBulkModifyClear:
def test_record_bulk_modify_clear_numeric(helpers):
pytest.app.records.bulk_create({'Numeric': 9999999}, {'Numeric': 9999999}, {
'Numeric': 9999999}, {'Numeric': 9999999})
i = random.randint(0,10000000)
pytest.app.records.bulk_create({'Numeric': i}, {'Numeric': i}, {
'Numeric': i}, {'Numeric': i})
initialRecords = len(pytest.app.records.search(
('Numeric', 'equals', 9999999)))
('Numeric', 'equals', i)))
emptyNumericRecords = len(
pytest.app.records.search(('Numeric', 'equals', None)))
records = pytest.app.records.bulk_modify(
('Numeric', 'equals', 9999999), values={'Numeric': Clear()})
('Numeric', 'equals', i), values={'Numeric': Clear()})
pytest.waitOnJobByID(records)
assert initialRecords >= 4
assert len(pytest.app.records.search(('Numeric', 'equals', None))
) == initialRecords + emptyNumericRecords

def test_record_bulk_modify_clear_text(helpers):
pytest.app.records.bulk_create({'Text': '9999999'}, {'Text': '9999999'}, {
'Text': '9999999'}, {'Text': '9999999'})
s = str(uuid.uuid4())
pytest.app.records.bulk_create({'Text': s}, {'Text': s}, {
'Text': s}, {'Text': s})
initialRecords = len(pytest.app.records.search(
('Text', 'equals', '9999999')))
('Text', 'equals', s)))
emptyNumericRecords = len(
pytest.app.records.search(('Text', 'equals', None)))
records = pytest.app.records.bulk_modify(
('Text', 'equals', '9999999'), values={'Text': Clear()})
('Text', 'equals', s), values={'Text': Clear()})
pytest.waitOnJobByID(records)
assert initialRecords >= 4
assert len(pytest.app.records.search(('Text', 'equals', None))
Expand Down Expand Up @@ -312,28 +337,30 @@ def test_record_bulk_modify_clear_multi_selection(helpers):
('Multi-select', 'equals', None))) == initialRecords + emptyNumericRecords

def test_record_bulk_modify_clear_text_list(helpers):
pytest.app.records.bulk_create({'Text List': ['one']}, {'Text List': ['one']}, {
'Text List': ['one']}, {'Text List': ['one']})
one = str(uuid.uuid4())
pytest.app.records.bulk_create({'Text List': [one]}, {'Text List': [one]}, {
'Text List': [one]}, {'Text List': [one]})
initialRecords = len(pytest.app.records.search(
('Text List', 'equals', ['one'])))
('Text List', 'equals', [one])))
emptyNumericRecords = len(
pytest.app.records.search(('Text List', 'equals', None)))
records = pytest.app.records.bulk_modify(
('Text List', 'equals', ['one']), values={'Text List': Clear()})
('Text List', 'equals', [one]), values={'Text List': Clear()})
pytest.waitOnJobByID(records)
assert initialRecords >= 4
assert len(pytest.app.records.search(
('Text List', 'equals', None))) == initialRecords + emptyNumericRecords

def test_record_bulk_modify_clear_numeric_list(helpers):
pytest.app.records.bulk_create({'Numeric List': [12345]}, {'Numeric List': [12345]}, {
'Numeric List': [12345]}, {'Numeric List': [12345]})
i = random.randint(0,99999)
pytest.app.records.bulk_create({'Numeric List': [i]}, {'Numeric List': [i]}, {
'Numeric List': [i]}, {'Numeric List': [i]})
initialRecords = len(pytest.app.records.search(
('Numeric List', 'equals', [12345])))
('Numeric List', 'equals', [i])))
emptyNumericRecords = len(pytest.app.records.search(
('Numeric List', 'equals', None)))
records = pytest.app.records.bulk_modify(
('Numeric List', 'equals', [12345]), values={'Numeric List': Clear()})
('Numeric List', 'equals', [i]), values={'Numeric List': Clear()})
pytest.waitOnJobByID(records)
assert initialRecords >= 4
assert len(pytest.app.records.search(
Expand All @@ -357,16 +384,17 @@ def test_record_bulk_modify_clear_multi_select_users(helpers):

def test_record_bulk_modify_clear_date_time(helpers):
baseTime = pendulum.now()
pytest.app.records.bulk_create({'Date & Time': baseTime}, {'Date & Time': baseTime}, {
'Date & Time': baseTime}, {'Date & Time': baseTime})
pytest.app.records.bulk_create({'Date & Time': baseTime}, {'Date & Time': baseTime})
initialRecords = len(pytest.app.records.search(
('Date & Time', 'equals', baseTime)))
emptyNumericRecords = len(pytest.app.records.search(
('Date & Time', 'equals', None)))
records = pytest.app.records.bulk_modify(
('Date & Time', 'equals', baseTime), values={'Date & Time': Clear()})
pytest.waitOnJobByID(records)
assert initialRecords >= 4
assert initialRecords >= 2
print(initialRecords)
print(emptyNumericRecords)
assert len(pytest.app.records.search(
('Date & Time', 'equals', None))) == initialRecords + emptyNumericRecords

Expand Down Expand Up @@ -448,7 +476,7 @@ def test_record_bulk_modify_clear_comments(helpers):

def test_record_bulk_modify_clear_references(helpers):
baseText = "Has Reference"
pytest.app.records.bulk_create({'Text': baseText}, {'Text': baseText}, {
pytest.app.records.bulk_create({'Text': baseText}, {'Text': baseText},{
'Text': baseText}, {'Text': baseText})
targetApp = pytest.swimlane_instance.apps.get(
name="PYTHON-Helpers Target App")
Expand Down Expand Up @@ -539,6 +567,7 @@ def test_record_bulk_modify_append_numeric_list(helpers):
'Numeric List': [456]}, {'Numeric List': [123, 456, 789]})
initialRecords = len(pytest.app.records.search(
('Numeric List', 'doesNotEqual', [])))
i3 = random.randint(500,600)
records = pytest.app.records.bulk_modify(
('Numeric List', 'doesNotEqual', []), values={'Numeric List': Append([543])})
pytest.waitOnJobByID(records)
Expand Down Expand Up @@ -655,7 +684,7 @@ def test_record_bulk_modify_append_attachment(helpers):
excinfo.value) == 'Field \'Attachment\' of Type \'AttachmentsField\', is not supported for bulk modify'

def test_record_bulk_modify_append_comments(helpers):
baseText = "Has Comment"
baseText = str(uuid.uuid4())
pytest.app.records.bulk_create({'Text': baseText}, {'Text': baseText}, {
'Text': baseText}, {'Text': baseText})
with pytest.raises(ValueError) as excinfo:
Expand Down Expand Up @@ -849,7 +878,7 @@ def test_record_bulk_modify_remove_attachment(helpers):
excinfo.value) == 'Field \'Attachment\' of Type \'AttachmentsField\', is not supported for bulk modify'

def test_record_bulk_modify_remove_comments(helpers):
baseText = "Has Comment"
baseText = str(uuid.uuid4())
pytest.app.records.bulk_create({'Text': baseText}, {'Text': baseText}, {
'Text': baseText}, {'Text': baseText})
with pytest.raises(ValueError) as excinfo:
Expand All @@ -860,7 +889,7 @@ def test_record_bulk_modify_remove_comments(helpers):

@pytest.mark.xfail(reason="SPT-7932: There was no error about the field type, but the passed in targetRecord, which is a record class, thinks it is a tuple??")
def test_record_bulk_modify_remove_references(helpers):
baseText = "Has Reference"
baseText = str(uuid.uuid4())
pytest.app.records.bulk_create({'Text': baseText}, {'Text': baseText}, {
'Text': baseText}, {'Text': baseText})
targetApp = pytest.swimlane_instance.apps.get(
Expand All @@ -873,7 +902,7 @@ def test_record_bulk_modify_remove_references(helpers):
assert len(record['Reference']) == 1

def test_record_bulk_modify_remove_multiple_text_list(helpers):
textForFilter = "text list remove multiple"
textForFilter = str(uuid.uuid4())
pytest.app.records.bulk_create(
{'Text': textForFilter, 'Text List': [
'a', 'b', 'c', 'd', 'e', 'a']},
Expand All @@ -898,7 +927,7 @@ def test_record_bulk_modify_remove_multiple_text_list(helpers):
assert (all(elem in ['a', 'd'] for elem in listDiff))

def test_record_bulk_modify_remove_multiple_numeric_list(helpers):
textForFilter = "numeric list remove multiple"
textForFilter = str(uuid.uuid4())
pytest.app.records.bulk_create(
{'Text': textForFilter, 'Numeric List': [1, 2, 3, 4, 5, 1]},
{'Text': textForFilter, 'Numeric List': [1, 2, 3, 4, 5]},
Expand Down
4 changes: 2 additions & 2 deletions swimlane/core/adapters/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ def bulk_create(self, *records):

new_records.append(record)

self._swimlane.request(
return self._swimlane.request(
'post',
'app/{}/record/batch'.format(self._app.id),
json=[r._raw for r in new_records]
)
).json()

# pylint: disable=too-many-branches
@requires_swimlane_version('2.17')
Expand Down

0 comments on commit 73d526c

Please sign in to comment.