Skip to content

Commit 9f46d94

Browse files
committed
Add tests for select option
1 parent b222add commit 9f46d94

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

setup.py

+6
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ def get_requirements(req_file):
3333
long_description_content_type="text/markdown",
3434
python_requires=">=3.6",
3535
install_requires=get_requirements("requirements.txt"),
36+
extras_require={
37+
"dev": [
38+
"black==21.12b0",
39+
"pytest",
40+
],
41+
}
3642
)

tests/test_base.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
import notion_df
3+
import pandas as pd
4+
from pydantic import ValidationError
5+
6+
def test_select_option():
7+
schema = notion_df.configs.DatabaseSchema(
8+
{"options": notion_df.configs.MultiSelectConfig()}
9+
)
10+
11+
df = pd.DataFrame([{"options": [1, 2, 3]}])
12+
dff = schema.transform(df)
13+
notion_df.values.PageProperty.from_series(dff.iloc[0], schema)
14+
15+
# Not working because of commas in the option string
16+
df = pd.DataFrame([{"options": ["a,b", "c,d"]}])
17+
dff = schema.transform(df)
18+
with pytest.raises(ValidationError):
19+
notion_df.values.PageProperty.from_series(dff.iloc[0], schema)
20+
21+
# The following also checks whether it can convert elements into strings
22+
df = pd.DataFrame([{"options": [[1, 2, 3], [4, 5, 6]]}])
23+
dff = schema.transform(df)
24+
with pytest.raises(ValidationError):
25+
notion_df.values.PageProperty.from_series(dff.iloc[0], schema)

0 commit comments

Comments
 (0)