From 440491a00ff7bb7b58a9b5bcea8b5533f1da3d2f Mon Sep 17 00:00:00 2001 From: Alex Levy Date: Mon, 16 Sep 2024 17:03:20 -0700 Subject: [PATCH] Fix flaky integration tests --- pyairtable/orm/model.py | 1 + pyairtable/utils.py | 1 + tests/integration/test_integration_api.py | 9 ++++++++- tests/integration/test_integration_orm.py | 4 ++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pyairtable/orm/model.py b/pyairtable/orm/model.py index 12ceaec3..5284a1c0 100644 --- a/pyairtable/orm/model.py +++ b/pyairtable/orm/model.py @@ -684,6 +684,7 @@ def __bool__(self) -> bool: "Model.save() now returns SaveResult instead of bool; switch" " to checking Model.save().created instead before the 4.0 release.", DeprecationWarning, + stacklevel=2, ) return self.created diff --git a/pyairtable/utils.py b/pyairtable/utils.py index 56f605c7..510630fc 100644 --- a/pyairtable/utils.py +++ b/pyairtable/utils.py @@ -110,6 +110,7 @@ def attachment(url: str, filename: str = "") -> CreateAttachmentByUrl: warnings.warn( "attachment(url, filename) is deprecated; use {'url': url, 'filename': filename} instead.", DeprecationWarning, + stacklevel=2, ) return {"url": url} if not filename else {"url": url, "filename": filename} diff --git a/tests/integration/test_integration_api.py b/tests/integration/test_integration_api.py index c55c03fc..66656f46 100644 --- a/tests/integration/test_integration_api.py +++ b/tests/integration/test_integration_api.py @@ -281,7 +281,14 @@ def test_integration_formula_composition(table: Table, cols): def test_integration_attachment(table, cols, valid_img_url): rec = table.create({cols.ATTACHMENT: [{"url": valid_img_url}]}) rv_get = table.get(rec["id"]) - assert rv_get["fields"]["attachment"][0]["url"].endswith("logo.png") + att = rv_get["fields"]["attachment"][0] + assert att["filename"] in ( + valid_img_url.rpartition("/")[-1], # sometimes taken from URL + "a." + valid_img_url.rpartition(".")[-1], # default if not + ) + original = requests.get(valid_img_url).content + attached = requests.get(att["url"]).content + assert original == attached def test_integration_attachment_multiple(table, cols, valid_img_url): diff --git a/tests/integration/test_integration_orm.py b/tests/integration/test_integration_orm.py index 65577683..0114b047 100644 --- a/tests/integration/test_integration_orm.py +++ b/tests/integration/test_integration_orm.py @@ -138,11 +138,11 @@ def test_integration_orm(Contact, Address): ) assert contact.first_name == "John" - assert contact.save() + assert contact.save().created assert contact.id contact.first_name = "Not Gui" - assert not contact.save() + assert not contact.save().created rv_address = contact.address[0] assert rv_address.exists()