<filename>tests/useradministrationtests/test_user_controller.py
import unittest
from matflow.useradministration.User import User
from matflow.useradministration.UserController import UserController
from unittest.mock import patch
from unittest.mock import call
import requests
import json
from requests.auth import HTTPBasicAuth
from matflow.exceptionpackage.MatFlowException import (
    UserExistsException,
    SignUpException,
    InternalException,
)


class MyTestCase(unittest.TestCase):
    __basic: HTTPBasicAuth

    # setUp sets up a testUser and a testUserController
    def setUp(self):
        self.testUser = User("testUsername", "inactive", "Reviewer", "<PASSWORD>Password")
        self.testUserController = UserController()
        self.__basic = HTTPBasicAuth("airflow", "airflow")
        requests.delete(
            "http://localhost:8080/api/v1/users/testUsername", auth=self.__basic
        )

    # tearDown deletes the testUser
    def tearDown(self):
        requests.delete(
            "http://localhost:8080/api/v1/users/testUsername", auth=self.__basic
        )

    # UserController workflowtests

    # test getAllUsersAndDetails statuscode 200 method
    @unittest.skip("Airflow needs to be up")
    def testGetAllUsersAndDetails(self):
        self.assertEqual(
            requests.get(
                "http://localhost:8080/api/v1/users",
                auth=self.__basic,
            ).json(),
            self.testUserController.getAllUsersAndDetails(self.__basic),
        )

    # test getAllUsersAndDetails statuscode != 200 method
    @unittest.skip("Airflow needs to be up")
    def testGetAllUsersAndDetails(self):
        shouldBeNone = self.testUserController.getAllUsersAndDetails(
            HTTPBasicAuth("test", "test")
        )
        shouldNotbeNone = self.testUserController.getAllUsersAndDetails(self.__basic)
        self.assertNotEqual(shouldBeNone, shouldNotbeNone)

    # test createUser
    @unittest.skip("Airflow needs to be up")
    def testCreateUserWithWrongPwRepetition(self):
        with self.assertRaises(SignUpException) as context:
            self.testUserController.createUser(
                "testUsername", "testPassword", "<PASSWORD>", self.__basic
            )
            self.assertTrue("Not the same Password" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testCreateUserWithAlreadyTakenUsername(self):
        with self.assertRaises(SignUpException) as context:
            self.testUserController.createUser(
                "airflow", "testPassword", "<PASSWORD>", self.__basic
            )
            self.assertTrue("Signup failed, User already exists" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testCreateUserCorrectly(self):
        self.testUserController.createUser(
            "testUsername", "testPassword", "<PASSWORD>Password", self.__basic
        )

    # test deleteUser
    @unittest.skip("Airflow needs to be up")
    def testDeleteNonexistingUser(self):
        with self.assertRaises(UserExistsException) as context:
            self.testUserController.deleteUser(self.testUser, self.__basic)
            self.assertTrue("User doesn't exist" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testDeleteUser(self):
        self.testUserController.createUser(
            "testUsername", "testPassword", "<PASSWORD>Password", self.__basic
        )
        self.testUserController.deleteUser(self.testUser, self.__basic)

    # test override User
    @unittest.skip("Airflow needs to be up")
    def testOverrideNonExistingUser(self):
        with self.assertRaises(UserExistsException) as context:
            self.testUserController.overrideUser(self.testUser, self.__basic)
            self.assertTrue("User doesn't exist" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testOverrideUser(self):
        self.testUserController.createUser(
            "testUsername", "testPassword", "<PASSWORD>", self.__basic
        )
        self.testUserController.overrideUser(self.testUser, self.__basic)


if __name__ == "__main__":
    unittest.main()

<filename>tests/useradministrationtests/test_user_controller.py
import unittest
from matflow.useradministration.User import User
from matflow.useradministration.UserController import UserController
from unittest.mock import patch
from unittest.mock import call
import requests
import json
from requests.auth import HTTPBasicAuth
from matflow.exceptionpackage.MatFlowException import (
    UserExistsException,
    SignUpException,
    InternalException,
)


class MyTestCase(unittest.TestCase):
    __basic: HTTPBasicAuth

    # setUp sets up a testUser and a testUserController
    def setUp(self):
        self.testUser = User("testUsername", "inactive", "Reviewer", "<PASSWORD>Password")
        self.testUserController = UserController()
        self.__basic = HTTPBasicAuth("airflow", "airflow")
        requests.delete(
            "http://localhost:8080/api/v1/users/testUsername", auth=self.__basic
        )

    # tearDown deletes the testUser
    def tearDown(self):
        requests.delete(
            "http://localhost:8080/api/v1/users/testUsername", auth=self.__basic
        )

    # UserController workflowtests

    # test getAllUsersAndDetails statuscode 200 method
    @unittest.skip("Airflow needs to be up")
    def testGetAllUsersAndDetails(self):
        self.assertEqual(
            requests.get(
                "http://localhost:8080/api/v1/users",
                auth=self.__basic,
            ).json(),
            self.testUserController.getAllUsersAndDetails(self.__basic),
        )

    # test getAllUsersAndDetails statuscode != 200 method
    @unittest.skip("Airflow needs to be up")
    def testGetAllUsersAndDetails(self):
        shouldBeNone = self.testUserController.getAllUsersAndDetails(
            HTTPBasicAuth("test", "test")
        )
        shouldNotbeNone = self.testUserController.getAllUsersAndDetails(self.__basic)
        self.assertNotEqual(shouldBeNone, shouldNotbeNone)

    # test createUser
    @unittest.skip("Airflow needs to be up")
    def testCreateUserWithWrongPwRepetition(self):
        with self.assertRaises(SignUpException) as context:
            self.testUserController.createUser(
                "testUsername", "testPassword", "<PASSWORD>", self.__basic
            )
            self.assertTrue("Not the same Password" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testCreateUserWithAlreadyTakenUsername(self):
        with self.assertRaises(SignUpException) as context:
            self.testUserController.createUser(
                "airflow", "testPassword", "<PASSWORD>", self.__basic
            )
            self.assertTrue("Signup failed, User already exists" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testCreateUserCorrectly(self):
        self.testUserController.createUser(
            "testUsername", "testPassword", "<PASSWORD>Password", self.__basic
        )

    # test deleteUser
    @unittest.skip("Airflow needs to be up")
    def testDeleteNonexistingUser(self):
        with self.assertRaises(UserExistsException) as context:
            self.testUserController.deleteUser(self.testUser, self.__basic)
            self.assertTrue("User doesn't exist" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testDeleteUser(self):
        self.testUserController.createUser(
            "testUsername", "testPassword", "<PASSWORD>Password", self.__basic
        )
        self.testUserController.deleteUser(self.testUser, self.__basic)

    # test override User
    @unittest.skip("Airflow needs to be up")
    def testOverrideNonExistingUser(self):
        with self.assertRaises(UserExistsException) as context:
            self.testUserController.overrideUser(self.testUser, self.__basic)
            self.assertTrue("User doesn't exist" in context.exception)

    @unittest.skip("Airflow needs to be up")
    def testOverrideUser(self):
        self.testUserController.createUser(
            "testUsername", "testPassword", "<PASSWORD>", self.__basic
        )
        self.testUserController.overrideUser(self.testUser, self.__basic)


if __name__ == "__main__":
    unittest.main()

# setUp sets up a testUser and a testUserController # tearDown deletes the testUser # UserController workflowtests # test getAllUsersAndDetails statuscode 200 method # test getAllUsersAndDetails statuscode != 200 method # test createUser # test deleteUser # test override User