def test_creating_existing_user_fails(self):
        users_model = UsersModel()
        user_model = UserModel()

        user = "unit_test_fake_user"
        passwd = "fakepass"
        group = "unit_test_fake_group"
        profile = "unit_test_fake_profile"

        params = {"name": user, "password": passwd, "group": group, "profile": profile}

        with RollbackContext() as rollback:
            users_model.create(params)
            rollback.prependDefer(user_model.delete, user)

            with self.assertRaises(OperationFailed):
                users_model.create(params)
    def test_create_user(self):
        users_model = UsersModel()
        user_model = UserModel()

        user = "unit_test_fake_user"
        passwd = "fakepass"
        group = "unit_test_fake_group"
        profile = "unit_test_fake_profile"

        common_users = users_model.get_list()
        params = {"name": user, "password": passwd, "group": group, "profile": profile}
        with RollbackContext() as rollback:

            users_model.create(params)
            rollback.prependDefer(user_model.delete, user)

            new_users = users_model.get_list()
            self.assertEqual(len(new_users), len(common_users) + 1)

            enc_passwd = spwd.getspnam(user)[1]
            invalid_passwd = [None, "NP", "!", "!!", "", "LK", "*"]
            self.assertNotIn(enc_passwd, invalid_passwd)

            self.assertEqual(crypt.crypt(passwd, enc_passwd), enc_passwd)
 def test_get_users_list(self):
     model = UsersModel()
     users = model.get_list()
     self.assertGreaterEqual(len(users), 0)