Exemple #1
0
    def test_update_non_shareable(self):
        """
        Tests updating groups that are non-shareable.
        """
        self.create_common_users_and_groups()
        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        auag = sync.get_all_users_and_groups()

        # Change Group 1 and Group 2 and verify change took.
        group1 = auag.get_group("Group 1")
        group1.visibility = Visibility.NON_SHAREABLE
        group2 = auag.get_group("Group 2")
        group2.visibility = Visibility.DEFAULT

        # sync updates
        sync.sync_users_and_groups(users_and_groups=auag)

        # verify changes
        auag = sync.get_all_users_and_groups()
        self.assertEqual(
            auag.get_group("Group 1").visibility, Visibility.NON_SHAREABLE)
        self.assertEqual(
            auag.get_group("Group 2").visibility, Visibility.DEFAULT)
        self.assertEqual(
            auag.get_group('Group "3"').visibility, Visibility.NON_SHAREABLE)
Exemple #2
0
    def test_delete_one_group(self):
        """Tests deleting a single groups."""

        self.create_common_users_and_groups()

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        sync.delete_group(groupname="Group1")
        auag = sync.get_all_users_and_groups()
        self.assertFalse(auag.has_group("Group1"))
        self.assertTrue(auag.has_group("Group2"))
        self.assertTrue(auag.has_group('Group"3"'))
Exemple #3
0
    def test_delete_user_list(self):
        """Tests deleting of a list of users."""

        self.create_common_users_and_groups()

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        sync.delete_users(usernames=["User1", "User2", "UserX"])
        auag = sync.get_all_users_and_groups()
        self.assertFalse(auag.has_user("User1"))
        self.assertFalse(auag.has_user("User2"))
        self.assertTrue(auag.has_user('User"3"'))
Exemple #4
0
    def test_getting_all(self):
        """
        Tests getting all users from the server.
        """

        self.create_common_users_and_groups()

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        auag = sync.get_all_users_and_groups()

        # There are four constant users, tsadmin, guest, su, system
        self.assertEqual(auag.number_users(), 7)
        # There are two constant groups, Administrator and System
        self.assertEqual(auag.number_groups(), 6)
Exemple #5
0
    def test_syncing_user_and_groups(self):
        """
        Tests adding users and groups to ThoughtSpot.
        """

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        auag = sync.get_all_users_and_groups()

        group1 = auag.get_group("Group 1")
        self.assertEqual("Group 1", group1.name)
        self.assertEqual("This is Group 1", group1.displayName)
        self.assertEqual("A group for testing.", group1.description)
        self.assertEqual([], group1.groupNames)
        self.assertEqual(Visibility.DEFAULT, group1.visibility)

        group2 = auag.get_group("Group 2")
        self.assertEqual("Group 2", group2.name)
        self.assertEqual("This is Group 2", group2.displayName)
        self.assertEqual("Another group for testing.", group2.description)
        self.assertEqual(["Group 1"], group2.groupNames)
        self.assertEqual(Visibility.NON_SHAREABLE, group2.visibility)

        user1 = auag.get_user("User1")
        self.assertEqual("User1", user1.name)
        self.assertEqual("User 1", user1.displayName)
        self.assertEqual(["All", "Group 1"], user1.groupNames)
        self.assertEqual(Visibility.DEFAULT, user1.visibility)

        user2 = auag.get_user("User2")
        self.assertEqual("User2", user2.name)
        self.assertEqual("User 2", user2.displayName)
        self.assertEqual(sorted(["All", "Group 1", "Group 2"]),
                         sorted(user2.groupNames))
        self.assertEqual(Visibility.NON_SHAREABLE, user2.visibility)
def dump_users_and_groups(args):
    """
    Gets users and groups from the server and dumps them in the correct format.
    :param args: The command line arguments.
    """
    sync = SyncUserAndGroups(
        tsurl=args.ts_url,
        username=args.username,
        password=args.password,
        disable_ssl=args.disable_ssl,
    )
    all_users_and_groups = sync.get_all_users_and_groups()

    print("writing to %s" % args.filename)

    if args.output_type == "json":
        with open(args.filename, "w") as outfile:
            outfile.write(all_users_and_groups.to_json())
    else:
        writer = UGXLSWriter()
        writer.write(users_and_groups=all_users_and_groups,
                     filename=args.filename)