Esempio n. 1
0
    def move(self, from_path, to_path, file_type, msg, ret):
        """
        helper for testing move moves static files, removes temp app directory and writes to log
        """
        if file_type == "dir":
            static_type = os.path.basename(from_path)
            static_file = os.path.join(to_path, "%s_file" % static_type)

        elif file_type == "file":
            static_type = os.path.basename(from_path)
            static_file = os.path.join(to_path, static_type)

        else:
            static_type = ""
            static_file = ""

        serve_django_static = ServeStatic(
            self.dist_version, self.app_home, self.log_file, self.log_level, git_repo=self.git_repo, venv=self.venv
        )
        move = serve_django_static.move(
            from_path, to_path, file_type, reqs_file=self.reqs_file, sys_deps_file=self.sys_deps_file
        )

        self.assertEqual(move, ret)
        self.assertTrue(os.path.isfile(static_file))
        with open(static_file) as static:
            static_file_list = [s for s in static]
            self.assertEqual(["%s stuff\n" % static_type], static_file_list, static_file_list)
        self.log(msg)
Esempio n. 2
0
    def test_move_exits_on_error(self, clone_app_mock, own_app_mock, copy_config_mock, add_app_to_path_mock):
        """
        tests move exits on error and writes to log
        """
        os.makedirs(os.path.dirname(self.static_path))
        serve_django_static = ServeStatic(
            self.dist_version, self.app_home, self.log_file, self.log_level, git_repo=self.git_repo
        )

        try:
            serve_django_static.move(os.path.join(self.app_home, self.app_name, "static"), self.static_path, "dir")

        except SystemExit as error:
            self.assertEqual(1, error.code, "move exited with: " + str(error))
            self.log("ERROR: file not found: %s" % os.path.join(self.app_home, self.app_name, "static"))
        self.assertEqual([], clone_app_mock.mock_calls, clone_app_mock.mock_calls)
        self.assertEqual([], copy_config_mock.mock_calls, copy_config_mock.mock_calls)
        self.assertEqual([], add_app_to_path_mock.mock_calls, add_app_to_path_mock.mock_calls)
        self.assertEqual([], own_app_mock.mock_calls, own_app_mock.mock_calls)
Esempio n. 3
0
    def test_move_handles_already_existing_static_dir(
        self, clone_app_mock, own_app_mock, copy_config_mock, add_app_to_path_mock
    ):
        """
        tests that move moves static files even if static directory already exists
        """
        to_dir = os.path.join(self.app_home, self.app_name, "static")
        os.makedirs(to_dir)
        os.makedirs(self.static_path)
        with open(os.path.join(self.app_home, self.app_name, "static/static_file"), "w") as static_file:
            static_file.write("static stuff\n")

        serve_django_static = ServeStatic(
            self.dist_version,
            self.app_home,
            self.log_file,
            self.log_level,
            git_repo=self.git_repo,
            sys_deps_file=self.sys_deps_file,
            reqs_file=self.reqs_file,
            venv=self.venv,
        )
        serve_django_static.move(to_dir, self.static_path, "dir")

        self.assertTrue(os.path.isfile(os.path.join(self.static_path, "static_file")))
        with open(os.path.join(self.static_path, "static_file")) as static_file:
            static_file_list = [s for s in static_file]
            self.assertEqual(["static stuff\n"], static_file_list, static_file_list)
        self.log("INFO: static moved to %s" % self.static_path)
        self.assertEqual([call(self.app_home)], clone_app_mock.mock_calls, clone_app_mock.mock_calls)
        self.assertEqual([call(self.app_home, uwsgi=False)], copy_config_mock.mock_calls, copy_config_mock.mock_calls)
        self.assertEqual([call(self.app_home)], add_app_to_path_mock.mock_calls, add_app_to_path_mock.mock_calls)
        self.assertEqual(
            [
                call(self.app_home, self.web_user, self.web_user),
                call(os.path.dirname(self.venv), self.web_user, self.web_user),
            ],
            own_app_mock.mock_calls,
            own_app_mock.mock_calls,
        )