Skip to content

Commit 326c01a

Browse files
committed
test: remove_users_csv
1 parent 418bd65 commit 326c01a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/test_user.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import io
33
import os
44
from pathlib import Path
5+
import re
56
import unittest
67
from unittest.mock import patch
78

@@ -520,3 +521,34 @@ def test_add_idp_and_auth_error(self) -> None:
520521

521522
with pytest.raises(ValueError, match="User cannot have both authSetting and idpConfigurationId."):
522523
self.server.users.bulk_add(users)
524+
525+
def test_remove_users_csv(self) -> None:
526+
self.server.version = "3.15"
527+
users = [
528+
make_user("Alice", "Viewer"),
529+
make_user("Bob", "Explorer"),
530+
make_user("Charlie", "Creator", "SAML"),
531+
make_user("Dave"),
532+
make_user("Eve", "ServerAdministrator", "OpenID", "example.com", "Eve Example", "[email protected]"),
533+
make_user("Frank", "SiteAdministratorExplorer", "TableauIDWithMFA", email="[email protected]"),
534+
make_user("Grace", "SiteAdministratorCreator", "SAML", "example.com", "Grace Example", "[email protected]"),
535+
make_user("Hank", "Unlicensed"),
536+
make_user("Ivy", "Unlicensed", idp_id="0123456789"),
537+
]
538+
539+
data = remove_users_csv(users)
540+
assert isinstance(data, bytes), "remove_users_csv should return bytes"
541+
csv_data = data.decode("utf-8")
542+
records = re.split(r"\r?\n", csv_data.strip())
543+
assert len(records) == len(users), "Number of records in csv does not match number of users"
544+
545+
for user, record in zip(users, records):
546+
name, *rest = record.strip().split(",")
547+
assert len(rest) == 6, "Number of fields in csv does not match expected number"
548+
assert all([f == "" for f in rest]), "All fields except name should be empty"
549+
if user.domain_name is None:
550+
assert name == user.name, f"Name in csv does not match expected name: {user.name}"
551+
else:
552+
assert (
553+
name == f"{user.domain_name}\\{user.name}"
554+
), f"Name in csv does not match expected name: {user.domain_name}\\{user.name}"

0 commit comments

Comments
 (0)