Esempio n. 1
0
    def test_get_personal_file_content__unauthorized(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/personal_file_content",
            "query_string": {
                "language": self.mock_language,
                "directory": "mock_subpath",
                "name": self.file_name,
            }
        }

        with app.test_client() as c:
            response = c.get(**mock_request)

        self.assertEqual(response._status, "401 UNAUTHORIZED")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("WWW-Authenticate"),
                         "Bearer realm=\"Access to user specific resources\"")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(
            response.get_json(), {
                "type": "AuthorizationViolation",
                "message": "Authorization Header is missing"
            })
Esempio n. 2
0
    def test_delete_personal_file_directory__inconsistency_file_exists_in_db_not_in_fs(
            self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/personal_file/2",
            "headers": {
                "Authorization": "Bearer " + self.token_valid_1
            },
        }

        with self.assertLogs(app.logger, level="INFO") as logs_list:
            with app.test_client() as c:
                response = c.delete(**mock_request)

        self.assertEqual(response._status, "200 OK")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(response.get_json(), {"message": "OK"})
        self.assertIsNone(
            file_model.SourceCodeFile.get_file_by_file_id_and_user_id(2, 1))

        self.assertEqual(
            len(logs_list.output),
            2,
            msg="There are expected exactly 2 log messages: {logs_list}".
            format(logs_list=logs_list))
        self.assertIn("ERROR:", logs_list.output[0])
        self.assertIn("Inconsistency during delete of file: ",
                      logs_list.output[0])
        self.assertIn("INFO:", logs_list.output[1])
        self.assertIn("Deleted file from DB: ", logs_list.output[1])
Esempio n. 3
0
    def test_get_personal_file_content__file_not_found(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/personal_file_content",
            "headers": {
                "Authorization": "Bearer " + self.token_valid_1
            },
            "query_string": {
                "language": self.mock_language,
                "directory": "mock_subpath",
                "name": "non-existing-file",
            }
        }

        with app.test_client() as c:
            response = c.get(**mock_request)

        self.assertEqual(response._status, "404 NOT FOUND")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(
            response.get_json(), {
                "type":
                "FileNotFound",
                "message":
                "The file could not be found. Are you sure it should exists? If this was an existing file that belonged to you, please try to delete it and re-upload it."
            })
Esempio n. 4
0
    def test_get_personal_file_content__extra_query_parameters(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/personal_file_content",
            "headers": {
                "Authorization": "Bearer " + self.token_valid_1
            },
            "query_string": {
                "language": self.mock_language,
                "directory": "mock_subpath",
                "name": self.file_name,
                "extra_1": True,
                "hack": "hack",
            }
        }

        with app.test_client() as c:
            response = c.get(**mock_request)

        self.assertEqual(response._status, "200 OK")
        self.assertEqual(response.headers.get("Content-Type"),
                         "text/plain; charset=utf-8")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(response.headers.get("Content-Disposition"),
                         "attachment; filename=" + self.file_name)

        response_file_content = response.get_data()
        with open(self.c_source_code_snippet_hello_c, "rb") as expected_file:
            expected_file_content = expected_file.read()
            self.assertEqual(response_file_content, expected_file_content)
    def test_login__invalid_form_fields(self):
        user_info_form_list = [{
            "username": "******",
            "password": "******",
        }, {
            "username": "******",
            "password": "******",
        }]

        for user_info_form in user_info_form_list:
            mock_request = {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/login",
                "data": user_info_form,
            }

            with app.test_client() as c:
                response = c.post(**mock_request)

            self.assertEqual(response._status, "400 BAD REQUEST")
            self.assertEqual(response.headers.get("Content-Type"),
                             "application/json")
            self.assertEqual(
                response.headers.get("Access-Control-Allow-Origin"),
                "http://localhost:3535")
            self.assertEqual(
                response.get_json(), {
                    "type": "LogInError",
                    "message": "Username, password or both are incorrect."
                })
Esempio n. 6
0
    def test_get_personal_file_content__invalid_language(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/personal_file_content",
            "headers": {
                "Authorization": "Bearer " + self.token_valid_1
            },
            "query_string": {
                "language": "invalid-language",
                "directory": "mock_subpath",
                "name": self.file_name,
            }
        }

        with app.test_client() as c:
            response = c.get(**mock_request)

        self.assertEqual(response._status, "400 BAD REQUEST")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(
            response.get_json(), {
                "type": "GetFileError",
                "message": "Language invalid-language is not supported."
            })
    def test_compile_store__unauthorized(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/compile/C/store",
        }

        with app.test_client() as c:
            response = c.post(**mock_request)

        self.assertEqual(response._status, "401 UNAUTHORIZED")
        self.assertEqual(response.headers.get("Content-Type"), "application/json")
        self.assertEqual(response.headers.get("WWW-Authenticate"), "Bearer realm=\"Access to user specific resources\"")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"), "http://localhost:3535")
        self.assertEqual(response.get_json(), {"type": "AuthorizationViolation", "message": "Authorization Header is missing"})
    def test_signup__valid(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/signup",
            "data": self.new_user_info,
        }

        with app.test_client() as c:
            response = c.post(**mock_request)

        self.assertEqual(response._status, "200 OK")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(response.get_json(), {"message": "OK"})
Esempio n. 9
0
    def test_get_personal_file_content__insecured_parameters(self):
        insecured_query_parameters_list = [
            {
                "language": self.mock_language,
                "directory": "../mock_subpath",
                "name": "../hello.c",
            },
            {
                "language": self.mock_language,
                "directory": "../1/mock_subpath",
                "name": "hello.c",
            },
            {
                "language": self.mock_language,
                "directory": "../1/./mock_subpath",
                "name": "../mock_subpath/hello.c",
            },
        ]

        expected_response_status_list = [
            "200 OK",
            "404 NOT FOUND",
            "404 NOT FOUND",
        ]

        self.assertEqual(len(insecured_query_parameters_list),
                         len(expected_response_status_list))

        for index, insecured_query_parameters in enumerate(
                insecured_query_parameters_list):
            mock_request = {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/files/personal_file_content",
                "headers": {
                    "Authorization": "Bearer " + self.token_valid_1
                },
                "query_string": insecured_query_parameters
            }

            with app.test_client() as c:
                response = c.get(**mock_request)

            self.assertEqual(
                response._status,
                expected_response_status_list[index],
                msg="Failure with query parameters: {query_parameters_dict}".
                format(query_parameters_dict=insecured_query_parameters))
    def test_signup__username_exists_error(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/signup",
            "data": self.existing_user_info,
        }

        with app.test_client() as c:
            response = c.post(**mock_request)

        self.assertEqual(response._status, "400 BAD REQUEST")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(
            response.get_json(), {
                "type": "UniqueUsernameViolation",
                "message": "Username test_user_exists already exists"
            })
    def test_login__valid(self):
        user_info_form_list = [
            {
                "username": "******",
                "password": "******",
            },
            self.existing_user_info,
        ]

        for user_info_form in user_info_form_list:
            mock_request = {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/login",
                "data": user_info_form,
            }

            with app.test_client() as c:
                response = c.post(**mock_request)

            self.assertEqual(response._status, "200 OK")
            self.assertEqual(response.headers.get("Content-Type"),
                             "application/json")
            self.assertEqual(
                response.headers.get("Access-Control-Allow-Origin"),
                "http://localhost:3535")

            response_json = response.get_json()
            self.assertEqual(
                len(response_json.keys()),
                2,
                msg=
                "Response json does not contain exactly 2 keys: {response_json}"
                .format(response_json=response_json))
            self.assertEqual(response_json.get("message"), "OK")
            self.assertIsNotNone(response_json.get("jwt"))
            self.assertIsInstance(response_json.get("jwt"), str)
            self.assertEqual(
                len(response_json.get("jwt").split(".")),
                3,
                msg="JWToken should have three parts separated by a dot.")
Esempio n. 12
0
    def test_delete_personal_file_directory__file_does_not_exist_in_db(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/personal_file/4",
            "headers": {
                "Authorization": "Bearer " + self.token_valid_1
            },
        }

        with app.test_client() as c:
            response = c.delete(**mock_request)

        self.assertEqual(response._status, "404 NOT FOUND")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(
            response.get_json(), {
                "type": "FileNotFound",
                "message": "The file you are trying to delete does not exist"
            })
Esempio n. 13
0
    def test_delete_personal_file_directory__invalid_file_id(self):
        invalid_file_id_list = [
            "alphanumerical_file_id",
            "-1",
            "0",
        ]

        for invalid_file_id in invalid_file_id_list:
            mock_request = {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/files/personal_file/" + invalid_file_id,
                "headers": {
                    "Authorization": "Bearer " + self.token_valid_1
                },
            }

            with app.test_client() as c:
                response = c.delete(**mock_request)

            self.assertEqual(response._status,
                             "400 BAD REQUEST",
                             msg="Failure with file_id: {file_id}".format(
                                 file_id=invalid_file_id))
            self.assertEqual(response.headers.get("Content-Type"),
                             "application/json",
                             msg="Failure with file_id: {file_id}".format(
                                 file_id=invalid_file_id))
            self.assertEqual(
                response.headers.get("Access-Control-Allow-Origin"),
                "http://localhost:3535",
                msg="Failure with file_id: {file_id}".format(
                    file_id=invalid_file_id))
            self.assertEqual(
                response.get_json(), {
                    "type": "FileIDTypeError",
                    "message": "File ID value should be a positive integer"
                },
                msg="Failure with file_id: {file_id}".format(
                    file_id=invalid_file_id))
    def test_compile_and_compile_store__invalid_language(self):
        mock_request_list = [
            {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/compile/invalid-language",
            },
            {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/compile/invalid-language/store",
                "headers": {
                    "Authorization": "Bearer " + self.token_valid
                },
            }
        ]

        for mock_request in mock_request_list:
            with app.test_client() as c:
                response = c.post(**mock_request)

            self.assertEqual(response._status, "400 BAD REQUEST")
            self.assertEqual(response.headers.get("Content-Type"), "application/json")
            self.assertEqual(response.headers.get("Access-Control-Allow-Origin"), "http://localhost:3535")
            self.assertEqual(response.get_json(), {"type": "LanguageNotSupportedError", "message": "Language invalid-language is not supported."})
    def test_compile_C_and_compile_store_C__missing_form_and_files_parameters(self):
        data_list = [
            {},
            {
                "code": (self.c_source_code_snippet_hello_c, None),
            },
            {
                "compilation_options": '{"optimization_level": "O2", "iso_standard": "gnu11", "suppress_warnings": true, "output_filename": "-----hello"}',
            },
        ]

        mock_request_list = [
            {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/compile/C",
            },
            {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/compile/C/store",
                "headers": {
                    "Authorization": "Bearer " + self.token_valid
                },
            }
        ]

        for data in data_list:
            for mock_request in mock_request_list:
                mock_request["data"] = data

                with app.test_client() as c:
                    response = c.post(**mock_request)

                self.assertEqual(response._status, "400 BAD REQUEST")
                self.assertEqual(response.headers.get("Content-Type"), "application/json")
                self.assertEqual(response.headers.get("Access-Control-Allow-Origin"), "http://localhost:3535")
                self.assertEqual(response.get_json(), {"type": "IncorrectCompileBodyError", "message": "A form data should be provided that contains a file with key 'code' and a compilation options json with key 'compilation_options'."})
Esempio n. 16
0
    def test_delete_personal_file_directory(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/personal_file/1",
            "headers": {
                "Authorization": "Bearer " + self.token_valid_1
            },
        }

        with self.assertLogs(app.logger, level="INFO") as logs_list:
            with app.test_client() as c:
                response = c.delete(**mock_request)

        self.assertEqual(response._status, "200 OK")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        self.assertEqual(response.get_json(), {"message": "OK"})
        self.assertEqual(os.listdir(self.mock_root_upload_path + "/1"),
                         ["ath"])
        self.assertEqual(os.listdir(self.mock_root_upload_path + "/1/ath"), [])
        self.assertIsNone(
            file_model.SourceCodeFile.get_file_by_file_id_and_user_id(1, 1))

        self.assertEqual(
            len(logs_list.output),
            2,
            msg="There are expected exactly 2 log messages: {logs_list}".
            format(logs_list=logs_list))
        self.assertIn("INFO:", logs_list.output[0])
        self.assertIn(
            "Deleted file from FS: " + str(self.test_file_1) + "\nin path: " +
            self.full_file_path, logs_list.output[0])
        self.assertIn("INFO:", logs_list.output[1])
        self.assertIn("Deleted file from DB: ", logs_list.output[1])
    def test_signup__email_exists_error(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/signup",
            "data": {
                "username": "******",
                "password": "******",
                "email": "*****@*****.**",
            },
        }

        with app.test_client() as c:
            response = c.post(**mock_request)

        self.assertEqual(response._status, "400 BAD REQUEST")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://*****:*****@mail.com already exists"
            })
Esempio n. 18
0
    def test_get_personal_files(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/files/all_personal",
            "headers": {
                "Authorization": "Bearer " + self.token_valid_1
            },
        }

        with app.test_client() as c:
            response = c.get(**mock_request)

        self.assertEqual(response._status, "200 OK")
        self.assertEqual(response.headers.get("Content-Type"),
                         "application/json")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"),
                         "http://localhost:3535")
        response_json_as_dict = response.get_json()

        self.assertEqual(
            sorted(response_json_as_dict.keys()),
            sorted(
                [self.file_info_1["language"], self.file_info_2["language"]]),
            msg=
            "Dictionary of languages has different keys\nReturned: {returned}\nExpected= {expected}"
            .format(
                returned=response_json_as_dict,
                expected=sorted([
                    self.file_info_1["language"], self.file_info_2["language"]
                ]),
            ))

        language_1_list = response_json_as_dict[self.file_info_1["language"]]
        language_2_list = response_json_as_dict[self.file_info_2["language"]]

        self.assertIsInstance(language_1_list, list)
        self.assertEqual(
            len(language_1_list),
            1,
            msg="The list should contain only one file\nReturned: {returned}".
            format(returned=language_1_list))
        self.assertIsInstance(language_2_list, list)
        self.assertEqual(
            len(language_2_list),
            1,
            msg="The list should contain only one file\nReturned: {returned}".
            format(returned=language_2_list))

        response_file_1 = language_1_list[0]
        response_file_2 = language_2_list[0]

        response_file_list = [response_file_1, response_file_2]
        test_file_list = [self.file_info_1, self.file_info_2]

        for i in range(2):
            self.assertEqual(len(response_file_list[i].keys()),
                             len(test_file_list[i].keys()) + 2)
            self.assertEqual(response_file_list[i]["id"],
                             test_file_list[i]["id"])
            self.assertEqual(response_file_list[i]["user_id"],
                             test_file_list[i]["user_id"])
            self.assertEqual(response_file_list[i]["name"],
                             test_file_list[i]["name"])
            self.assertEqual(response_file_list[i]["directory"],
                             test_file_list[i]["directory"])
            self.assertEqual(response_file_list[i]["compilation_options"],
                             test_file_list[i]["compilation_options"])
            self.assertEqual(response_file_list[i]["language"],
                             test_file_list[i]["language"])
            self.assertEqual(response_file_list[i]["status"],
                             test_file_list[i]["status"])
            self.assertIsInstance(
                response_file_list[i]["created_at"],
                str,
                msg="json_agg should convert the datetime to string")
            self.assertIsInstance(
                response_file_list[i]["updated_at"],
                str,
                msg="json_agg should convert the datetime to string")
    def test_signup__validation_errors(self):
        test_time = datetime.datetime.utcnow()

        invalid_user_schema_list = [
            {
                "id": 1,
                "username": "******",
                "password": "******",
                "email": "*****@*****.**",
                "created_at": test_time,
                "updated_at": test_time,
                "extra field": True,
            },
            {
                "id": 1,
            },
            {
                "username": "******",
                "password": "******",
                "email": "test_user@email",
            },
            {
                "username": "******",
                "password": "******",
                "email": "test_user",
            },
            {
                "username": "******",
                "password": "******",
                "email": "test [email protected]",
            },
            {
                "username": "******",
                "password": "******",
                "email": "*****@*****.**",
            },
            {
                "username": "******",
                "password": "******",
                "email": "*****@*****.**",
            },
            {
                "username":
                "******",  # Non-latin characters are not allowed in username
                "password":
                "******",  # Non-latin characters are allowed in password
                "email": "*****@*****.**",
            },
        ]

        expected_response_list = [
            {
                "created_at": ["Unknown field."],
                "extra field": ["Unknown field."],
                "id": ["Unknown field."],
                "updated_at": ["Unknown field."],
            },
            {
                "email": ["Missing data for required field."],
                "id": ["Unknown field."],
                "password": ["Missing data for required field."],
                "username": ["Missing data for required field."],
            },
            {
                "email": ["Not a valid email address."],
                "password": [
                    "Password length must be at least 6.",
                    "Password must contain at least 1 latin letter(s)."
                ],
                "username": [
                    "Username must contain only latin letters, numbers, _ and spaces. It must start and end with a letter. It must have length greater than 1."
                ],
            },
            {
                "email": ["Not a valid email address."],
                "password": [
                    "Password must not contain white spaces.",
                    "Password must contain at least 1 number(s).",
                ],
                "username": [
                    "Username must contain only latin letters, numbers, _ and spaces. It must start and end with a letter. It must have length greater than 1."
                ],
            },
            {
                "email": ["Not a valid email address."],
                "password": ["Password must not contain white spaces."],
                "username": [
                    "Username must contain only latin letters, numbers, _ and spaces. It must start and end with a letter. It must have length greater than 1."
                ],
            },
            {
                "password": ["Password must not contain white spaces."],
                "username": [
                    "Username must contain only latin letters, numbers, _ and spaces. It must start and end with a letter. It must have length greater than 1."
                ],
            },
            {
                "password": ["Password must not contain white spaces."],
            },
            {
                "password": ["Password must not contain white spaces."],
                "username": [
                    "Username must contain only latin letters, numbers, _ and spaces. It must start and end with a letter. It must have length greater than 1."
                ],
            },
        ]

        self.assertEqual(len(invalid_user_schema_list),
                         len(expected_response_list))

        for index, invalid_user_schema in enumerate(invalid_user_schema_list):
            mock_request = {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/signup",
                "data": invalid_user_schema,
            }

            with app.test_client() as c:
                response = c.post(**mock_request)

            self.assertEqual(response._status,
                             "400 BAD REQUEST",
                             msg="Failure with form: {form_dict}".format(
                                 form_dict=invalid_user_schema))
            self.assertEqual(response.headers.get("Content-Type"),
                             "application/json",
                             msg="Failure with form: {form_dict}".format(
                                 form_dict=invalid_user_schema))
            self.assertEqual(
                response.headers.get("Access-Control-Allow-Origin"),
                "http://localhost:3535",
                msg="Failure with form: {form_dict}".format(
                    form_dict=invalid_user_schema))
            self.assertEqual(response.get_json(), {
                "type": "SignUpError",
                "message": expected_response_list[index]
            },
                             msg="Failure with form: {form_dict}".format(
                                 form_dict=invalid_user_schema))
Esempio n. 20
0
    def test_get_personal_file_content__missing_query_parameters(self):
        query_parameters_list = [
            {},
            {
                "language": "invalid-language",
            },
            {
                "directory": "mock_subpath",
            },
            {
                "name": self.file_name,
            },
            {
                "language": "invalid-language",
                "directory": "mock_subpath",
            },
            {
                "language": "invalid-language",
                "name": self.file_name,
            },
            {
                "directory": "mock_subpath",
                "name": self.file_name,
            },
        ]

        for query_parameters in query_parameters_list:
            mock_request = {
                "base_url": "http://127.0.0.1:8080",
                "path": "/api/files/personal_file_content",
                "headers": {
                    "Authorization": "Bearer " + self.token_valid_1
                },
                "query_string": query_parameters
            }

            with app.test_client() as c:
                response = c.get(**mock_request)

            self.assertEqual(
                response._status,
                "400 BAD REQUEST",
                msg="Failure with query parameters: {query_parameters_dict}".
                format(query_parameters_dict=query_parameters))
            self.assertEqual(
                response.headers.get("Content-Type"),
                "application/json",
                msg="Failure with query parameters: {query_parameters_dict}".
                format(query_parameters_dict=query_parameters))
            self.assertEqual(
                response.headers.get("Access-Control-Allow-Origin"),
                "http://localhost:3535",
                msg="Failure with query parameters: {query_parameters_dict}".
                format(query_parameters_dict=query_parameters))
            self.assertEqual(
                response.get_json(), {
                    "type":
                    "GetFileError",
                    "message":
                    "A language, a directory and a name query parameters should be provided."
                },
                msg="Failure with query parameters: {query_parameters_dict}".
                format(query_parameters_dict=query_parameters))
Esempio n. 21
0
	def setup_class(self):

		self.app = app.test_client()
    def test_compile_store_C__valid(self):
        mock_request = {
            "base_url": "http://127.0.0.1:8080",
            "path": "/api/compile/C/store",
            "headers": {
                "Authorization": "Bearer " + self.token_valid
            },
            "data": {
                "code": (self.c_source_code_snippet_hello_c, "hello.c"),
                "compilation_options": '{"optimization_level": "O2", "iso_standard": "gnu11", "suppress_warnings": true, "output_filename": "-----hello"}',
            },
        }

        with app.test_client() as c:
            response = c.post(**mock_request)

        self.assertEqual(response._status, "200 OK")
        self.assertEqual(response.headers.get("Content-Type"), "application/zip")
        self.assertEqual(response.headers.get("Access-Control-Allow-Origin"), "http://localhost:3535")
        self.assertEqual(response.headers.get("Content-Disposition"), "attachment; filename=results.zip")

        root_upload_path_list = os.listdir(self.handler_c.root_upload_path)
        self.assertEqual(root_upload_path_list, [str(self.user_info["id"])],
            msg="Path {path} does not contain only the '{user_id}' folder: {root_upload_path_list}".format(
                path=self.handler_c.root_upload_path,
                user_id=self.user_info["id"],
                root_upload_path_list=root_upload_path_list
            )
        )

        user_directory = self.handler_c.root_upload_path + "/" + str(self.user_info["id"])
        user_directory_list = os.listdir(user_directory)
        self.assertEqual(len(user_directory_list), 1,
            msg="Path {path} does not contain exactly one level_1 uploaded file directory: {entry_list}".format(
                path=user_directory,
                entry_list=user_directory_list
            )
        )

        user_directory_level_1 = user_directory + "/" + user_directory_list[0]
        user_directory_level_1_list = os.listdir(user_directory_level_1)
        self.assertEqual(len(user_directory_level_1_list), 1,
            msg="Path {path} does not contain only the level_2 file directory: {entry_list}".format(
                path=user_directory_level_1,
                entry_list=user_directory_level_1_list
            )
        )

        uploaded_file_directory = user_directory_level_1 + "/" + user_directory_level_1_list[0]
        uploaded_file_directory_list = os.listdir(uploaded_file_directory)
        self.assertEqual(len(uploaded_file_directory_list), 5,
            msg="Path {path} does not contain exactly 5 files: {entry_list}".format(
                path=uploaded_file_directory,
                entry_list=uploaded_file_directory_list
            )
        )
        self.assertIn("hello.c", uploaded_file_directory_list)
        self.assertIn("hello.html", uploaded_file_directory_list)
        self.assertIn("hello.js", uploaded_file_directory_list)
        self.assertIn("hello.wasm", uploaded_file_directory_list)
        self.assertIn("results.zip", uploaded_file_directory_list)
        self.assertTrue(filecmp.cmp(uploaded_file_directory + "/hello.c", self.c_source_code_snippet_hello_c))
        self.assertTrue(os.stat(uploaded_file_directory + "/hello.html").st_size != 0)
        self.assertTrue(os.stat(uploaded_file_directory + "/hello.js").st_size != 0)
        self.assertTrue(os.stat(uploaded_file_directory + "/hello.wasm").st_size != 0)

        with ZipFile(file=uploaded_file_directory + "/results.zip", mode="r") as file_system_zip:
            self.assertIsNone(file_system_zip.testzip())
            self.assertEqual(file_system_zip.namelist(), ["hello.html", "hello.js", "hello.wasm"])
            file_system_zip_infolist = file_system_zip.infolist()
            self.assertEqual(os.stat(uploaded_file_directory + "/hello.html").st_size, file_system_zip_infolist[0].file_size)
            self.assertEqual(os.stat(uploaded_file_directory + "/hello.js").st_size, file_system_zip_infolist[1].file_size)
            self.assertEqual(os.stat(uploaded_file_directory + "/hello.wasm").st_size, file_system_zip_infolist[2].file_size)

            with io.BytesIO(response.get_data()) as in_memory_response_zip:
                with ZipFile(in_memory_response_zip, 'r') as response_zip:
                    self.assertIsNone(response_zip.testzip())
                    self.assertEqual(response_zip.namelist(), ["hello.html", "hello.js", "hello.wasm"])
                    response_zip_infolist = response_zip.infolist()

                    self.assertEqual(file_system_zip_infolist[0].file_size, response_zip_infolist[0].file_size,
                        msg="HTML files do not have the same size inside the two zip files"
                    )
                    self.assertEqual(file_system_zip_infolist[1].file_size, response_zip_infolist[1].file_size,
                        msg="JS files do not have the same size inside the two zip files"
                    )
                    self.assertEqual(file_system_zip_infolist[2].file_size, response_zip_infolist[2].file_size,
                        msg="WASM files do not have the same size inside the two zip files"
                    )

        test_all_files = file_model.SourceCodeFile.get_all_files()
        self.assertEqual(len(test_all_files), 1,
            msg="There is not exactly 1 file in DB: {files}".format(
                files=test_all_files
            )
        )