Skip to content

Commit

Permalink
Deprecate utils.attachment()
Browse files Browse the repository at this point in the history
  • Loading branch information
mesozoic committed Sep 9, 2024
1 parent 1df8798 commit 595a5d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions pyairtable/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import re
import textwrap
import warnings
from datetime import date, datetime
from functools import partial, wraps
from typing import (
Expand Down Expand Up @@ -106,6 +107,10 @@ def attachment(url: str, filename: str = "") -> CreateAttachmentByUrl:
"""
warnings.warn(
"attachment(url, filename) is deprecated; use {'url': url, 'filename': filename} instead.",
DeprecationWarning,
)
return {"url": url} if not filename else {"url": url, "filename": filename}


Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_integration_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pyairtable import Table
from pyairtable import formulas as fo
from pyairtable.utils import attachment, date_to_iso_str, datetime_to_iso_str
from pyairtable.utils import date_to_iso_str, datetime_to_iso_str

pytestmark = [pytest.mark.integration]

Expand Down Expand Up @@ -279,7 +279,7 @@ def test_integration_formula_composition(table: Table, cols):


def test_integration_attachment(table, cols, valid_img_url):
rec = table.create({cols.ATTACHMENT: [attachment(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")

Expand All @@ -288,8 +288,8 @@ def test_integration_attachment_multiple(table, cols, valid_img_url):
rec = table.create(
{
cols.ATTACHMENT: [
attachment(valid_img_url, filename="a.png"),
attachment(valid_img_url, filename="b.png"),
{"url": valid_img_url, "filename": "a.png"},
{"url": valid_img_url, "filename": "b.png"},
]
}
)
Expand All @@ -299,7 +299,7 @@ def test_integration_attachment_multiple(table, cols, valid_img_url):


def test_integration_upload_attachment(table, cols, valid_img_url, tmp_path):
rec = table.create({cols.ATTACHMENT: [attachment(valid_img_url, filename="a.png")]})
rec = table.create({cols.ATTACHMENT: [{"url": valid_img_url, "filename": "a.png"}]})
content = requests.get(valid_img_url).content
response = table.upload_attachment(rec["id"], cols.ATTACHMENT, "b.png", content)
assert response == {
Expand Down
13 changes: 8 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ def test_date_utils(date_obj, date_str):


def test_attachment():
assert utils.attachment("https://url.com") == {"url": "https://url.com"}
assert utils.attachment("https://url.com", filename="test.jpg") == {
"url": "https://url.com",
"filename": "test.jpg",
}
with pytest.deprecated_call():
assert utils.attachment("https://url.com") == {"url": "https://url.com"}

with pytest.deprecated_call():
assert utils.attachment("https://url.com", filename="test.jpg") == {
"url": "https://url.com",
"filename": "test.jpg",
}


@pytest.mark.parametrize(
Expand Down

0 comments on commit 595a5d6

Please sign in to comment.