Skip to content

Commit 7d73308

Browse files
chore: resolve merge conflict with upstream/main in test_moto.py
1 parent f45872b commit 7d73308

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/unit/test_moto.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,55 @@ def test_extract_ctas_manifest_paths_cross_bucket_raises(moto_s3_client: "S3Clie
760760

761761
with pytest.raises(InvalidArgumentValue, match="unexpected bucket"):
762762
_extract_ctas_manifest_paths(path=f"s3://bucket/{manifest_key}")
763+
764+
def test_dynamodb_read_items_with_key_schema(moto_dynamodb_client, moto_dynamodb_table) -> None:
765+
# Insert items
766+
items = [{"key": 1, "value": "A"}, {"key": 2, "value": "B"}]
767+
wr.dynamodb.put_items(items=items, table_name=moto_dynamodb_table)
768+
769+
# 1. Verify read_items works with key_schema passed
770+
key_schema = [{"AttributeName": "key", "KeyType": "HASH"}]
771+
df = wr.dynamodb.read_items(
772+
table_name=moto_dynamodb_table,
773+
key_schema=key_schema,
774+
allow_full_scan=True,
775+
)
776+
assert len(df) == 2
777+
assert set(df["value"]) == {"A", "B"}
778+
779+
# 2. Assert DescribeTable is NOT called when key_schema is provided
780+
call = botocore.client.BaseClient._make_api_call
781+
describe_table_calls = 0
782+
783+
def mock_make_api_call(self, operation_name, kwarg):
784+
nonlocal describe_table_calls
785+
if operation_name == "DescribeTable":
786+
describe_table_calls += 1
787+
return call(self, operation_name, kwarg)
788+
789+
with mock.patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call):
790+
# Call read_items with key_schema
791+
wr.dynamodb.read_items(
792+
table_name=moto_dynamodb_table,
793+
key_schema=key_schema,
794+
allow_full_scan=True,
795+
)
796+
assert describe_table_calls == 0
797+
798+
# Call read_items WITHOUT key_schema
799+
wr.dynamodb.read_items(
800+
table_name=moto_dynamodb_table,
801+
allow_full_scan=True,
802+
)
803+
assert describe_table_calls == 1
804+
805+
806+
def test_csv_pandas_mode_append(moto_s3_client: "S3Client") -> None:
807+
path = "s3://bucket/test_append.csv"
808+
df1 = pd.DataFrame({"col": [1, 2, 3]})
809+
df2 = pd.DataFrame({"col": [4, 5, 6]})
810+
wr.s3.to_csv(df=df1, path=path, index=False)
811+
wr.s3.to_csv(df=df2, path=path, index=False, pandas_mode="a", header=False)
812+
result = wr.s3.read_csv(path=path)
813+
assert len(result) == 6
814+
assert list(result["col"]) == [1, 2, 3, 4, 5, 6]

0 commit comments

Comments
 (0)