Exemplo n.º 1
0
    def test_remove_static(self, own_app_mock, clone_app_mock):
        """
        tests that remove_static removes the static directories and files, writes to log
        """
        user = "******"
        os.makedirs(self.static_path)
        os.makedirs(self.media_path)
        os.makedirs(self.uwsgi_path)
        os.makedirs(self.down_path)
        os.makedirs(os.path.join(self.app_home, self.app_name, self.app_name))
        os.makedirs(os.path.join(os.path.dirname(self.app_home), "conf.d"))
        conf = [
            {"file": "settings.json", "move_to": os.path.join(self.app_home, self.app_name)},
            {"file": "settings_admin.py", "move_to": os.path.join(self.app_home, self.app_name, self.app_name)},
            {"file": "%s_uwsgi.ini" % self.app_name, "move_to": self.app_home},
        ]
        for f in conf:
            with open(os.path.join(os.path.dirname(self.app_home), "conf.d", f["file"]), "w") as config:
                config.write("%s file\n" % f["file"])
        if self.dist_version == "14.04":
            self.python_version = "python3.4"
        elif self.dist_version == "16.04":
            self.python_version = "python3.5"
        os.makedirs(os.path.join(self.venv, "lib", self.python_version, "site-packages"))

        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.serve_static(user, user, self.down_path, self.static_path, self.media_path, self.uwsgi_path)

        serve_django_static.remove_static(self.down_path, self.static_path, self.media_path, self.uwsgi_path)

        fds = [
            {"path": self.down_path, "file": "index.html"},
            {"path": self.static_path, "file": "static_file"},
            {"path": self.media_path, "file": "media_file"},
            {"path": self.uwsgi_path, "file": "uwsgi_params"},
        ]
        for f in fds:
            self.assertTrue(os.path.exists(f["path"]), "%s was removed" % f["path"])
            self.assertFalse(os.path.exists(os.path.join(f["path"], f["file"])), "%s was not removed" % f["file"])
            self.log("INFO: removed files in %s" % f["path"])
Exemplo n.º 2
0
    def test_run_main_remove_static(self, own_app_mock, clone_app_mock):
        """
        tests run main script with remove static parameter returns no error
        """
        user = "******"
        os.makedirs(self.static_path)
        os.makedirs(self.media_path)
        os.makedirs(self.uwsgi_path)
        os.makedirs(self.down_path)
        webserver.DIST_VERSION = self.dist_version
        os.makedirs(os.path.join(self.app_home, self.app_name, self.app_name))
        os.makedirs(os.path.join(os.path.dirname(self.app_home), "conf.d"))
        conf = [
            {"file": "settings.json", "move_to": os.path.join(self.app_home, self.app_name)},
            {"file": "settings_admin.py", "move_to": os.path.join(self.app_home, self.app_name, self.app_name)},
            {"file": "%s_uwsgi.ini" % self.app_name, "move_to": self.app_home},
        ]
        for f in conf:
            with open(os.path.join(os.path.dirname(self.app_home), "conf.d", f["file"]), "w") as config:
                config.write("%s file\n" % f["file"])
        if self.dist_version == "14.04":
            self.python_version = "python3.4"
        elif self.dist_version == "16.04":
            self.python_version = "python3.5"
        os.makedirs(os.path.join(self.venv, "lib", self.python_version, "site-packages"))

        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.serve_static(user, user, self.down_path, self.static_path, self.media_path, self.uwsgi_path)

        sys.argv = ["webserver", "-x", "-l", "DEBUG"]
        try:
            main()
        except SystemExit as sysexit:
            self.assertEqual("0", str(sysexit), "main returned: " + str(sysexit))

        fds = [self.down_path, self.static_path, self.media_path, self.uwsgi_path]
        for f in fds:
            self.assertTrue(os.path.exists(f), "%s not present" % f)
            self.log("INFO: removed files in %s" % f)
Exemplo n.º 3
0
    def test_serve_static(self, own_app_mock, clone_app_mock):
        """
        tests serve_static creates app_home and static directories and runs install app and collectstatic commands,
        writes to log
        """
        user = "******"
        os.makedirs(self.static_path)
        os.makedirs(self.media_path)
        os.makedirs(self.uwsgi_path)
        os.makedirs(self.down_path)
        os.makedirs(os.path.join(self.app_home, self.app_name, self.app_name))
        os.makedirs(os.path.join(os.path.dirname(self.app_home), "conf.d"))
        conf = [
            {"file": "settings.json", "move_to": os.path.join(self.app_home, self.app_name)},
            {"file": "settings_admin.py", "move_to": os.path.join(self.app_home, self.app_name, self.app_name)},
            {"file": "%s_uwsgi.ini" % self.app_name, "move_to": self.app_home},
        ]
        for f in conf:
            with open(os.path.join(os.path.dirname(self.app_home), "conf.d", f["file"]), "w") as config:
                config.write("%s file\n" % f["file"])
        if self.dist_version == "14.04":
            self.python_version = "python3.4"
        elif self.dist_version == "16.04":
            self.python_version = "python3.5"
        os.makedirs(os.path.join(self.venv, "lib", self.python_version, "site-packages"))

        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,
        )
        ret = serve_django_static.serve_static(
            user, user, self.down_path, self.static_path, self.media_path, self.uwsgi_path
        )

        # check that serve_static returns no error
        self.assertEqual(0, ret, str(ret))

        # check that temp path where app was cloned to was removed
        self.assertFalse(os.path.exists(self.app_home))

        # check that static, media and uwsgi files and directory structures have been correctly moved
        fds = [
            {"name": "index.html", "path": self.down_path, "file": "index.html"},
            {"name": "static", "path": self.static_path, "file": "static_file"},
            {"name": "media", "path": self.media_path, "file": "media_file"},
            {"name": "uwsgi_params", "path": self.uwsgi_path, "file": "uwsgi_params"},
        ]
        for f in fds:
            self.assertTrue(os.path.isdir(f["path"]), f["path"])
            self.assertTrue(os.path.isfile(os.path.join(f["path"], f["file"])), f["file"])
            with open(os.path.join(f["path"], f["file"])) as static:
                static_list = [s for s in static]
                self.assertEqual(["%s stuff\n" % f["name"]], static_list, static_list)

        # check that all expected log entries are present
        # for install_app and collect_static
        msgs = [
            "INFO: successfully cloned app_name to %s" % self.app_home,
            "INFO: virtualenv %s already exists" % self.venv,
            "INFO: successfully installed: numpy==1.11.0",
            "INFO: successfully installed: biopython(1.66) cssselect(0.9.1) Django(1.9.5) django-debug-toolbar(1.4) "
            "django-with-asserts(0.0.1) lxml(3.6.0) numpy(1.11.0) psycopg2(2.6.1) requests(2.9.1) sqlparse(0.1.19)",
            "INFO: successfully installed: libpq-dev python3-numpy libxml2-dev libxslt1-dev zlib1g-dev",
            "INFO: changed permissions of %s to %s" % (os.path.dirname(self.venv), "500"),
            "INFO: successfully collected static for %s" % self.app_name,
        ]
        for m in msgs:
            self.log(m)

        # self.log('INFO: successfully cloned app_name to %s' % self.app_home)

        # for move
        for f in fds:
            self.log("INFO: %s moved to %s" % (f["name"], f["path"]))

        # for own and permissions
        own_and_perm_msgs = [
            "changed ownership of %s to %s:%s" % (self.static_path, user, user),
            "changed permissions of %s files to 440 and directories to 550" % self.static_path,
        ]
        for o in own_and_perm_msgs:
            self.log("INFO: %s" % o)

        # for successful exit
        self.log("INFO: serve static exited with code 0")