-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from palewire/create-folder
- Loading branch information
Showing
2 changed files
with
222 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Test folder related API enpoints.""" | ||
import random | ||
import string | ||
|
||
import pytest | ||
|
||
from datawrapper import Datawrapper | ||
|
||
|
||
def test_get_folders(): | ||
"""Test the get_folders method.""" | ||
dw = Datawrapper() | ||
folder_list = dw.get_folders() | ||
assert len(folder_list) > 0 | ||
|
||
|
||
def test_folder_crud(): | ||
"""Run folder related tests for creation, updating and deleting.""" | ||
# Connect | ||
dw = Datawrapper() | ||
|
||
# Get a randoms string suffix to use in our names | ||
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=5)) | ||
|
||
# Create a new folder | ||
folder_info = dw.create_folder(name="My new folder " + suffix) | ||
|
||
# Get the folder's data with a fresh get_folder call | ||
folder_info = dw.get_folder(folder_info["id"]) | ||
|
||
# Make a second folder | ||
second_folder_info = dw.create_folder(name="My second folder " + suffix) | ||
|
||
# Move the second folder into the first folder | ||
dw.update_folder( | ||
folder_id=second_folder_info["id"], parent_id=folder_info["id"] | ||
) | ||
|
||
# Get the folder's data with a fresh get_folder call | ||
second_folder_info = dw.get_folder(second_folder_info["id"]) | ||
|
||
# Verify it has the parent | ||
assert second_folder_info["parentId"] == folder_info["id"] | ||
|
||
# Change the name of the second folder | ||
dw.update_folder(folder_id=second_folder_info["id"], name="My second folder (renamed)") | ||
|
||
# Get it fresh and verify the change | ||
second_folder_info = dw.get_folder(second_folder_info["id"]) | ||
assert second_folder_info["name"] == "My second folder (renamed)" | ||
|
||
# Delete both folders | ||
dw.delete_folder(folder_info["id"]) | ||
|
||
# Verify that you can't get either | ||
with pytest.raises(Exception): | ||
dw.get_folder(folder_info["id"]) | ||
dw.get_folder(second_folder_info["id"]) |