Exemple #1
0
def given_project_js_versioned_file_exists(project, filename="maths.js"):
    utils.get_config(True)

    versioned_file_path = os.path.join(utils.get_projects_dir(), project,
                                       filename)
    if not os.path.exists(os.path.dirname(versioned_file_path)):
        os.makedirs(os.path.dirname(versioned_file_path))

    versioned_file = open(versioned_file_path, "w")
    versioned_file.write("""/**
 * Copyright (c) 2017 Helium Edu.
 *
 * Some functions and stuff.
 *
 * @author Alex Laird
 * @version 1.2.2
 */
    
function sum(a, b) {
    return a + b
}
""")
    versioned_file.close()

    return versioned_file_path
Exemple #2
0
    def test_default_config_created(self):
        # GIVEN
        self.assertFalse(
            os.path.exists(os.environ.get("HELIUMCLI_CONFIG_PATH")))

        # WHEN
        utils.get_config(True)

        # THEN
        self.assertTrue(os.path.exists(
            os.environ.get("HELIUMCLI_CONFIG_PATH")))
Exemple #3
0
def given_hosts_file_exists():
    utils.get_config(True)

    if not os.path.exists(os.path.join(utils.get_ansible_dir(), 'hosts')):
        os.makedirs(os.path.join(utils.get_ansible_dir(), 'hosts'))

    hosts_file = open(os.path.join(utils.get_ansible_dir(), 'hosts', 'devbox'),
                      "w")
    hosts_file.write(
        "[devbox]\nheliumedu.test ansible_user=vagrant ip_address=10.1.0.10")
    hosts_file.close()
Exemple #4
0
    def test_config_already_exists(self, mock_path_exists):
        # GIVEN
        utils._save_config(os.environ.get("HELIUMCLI_CONFIG_PATH"),
                           settings.get_default_settings())
        utils.get_config(True)
        mock_path_exists.reset_mock()

        # WHEN
        utils.get_config(True)

        # THEN
        mock_path_exists.assert_not_called()
Exemple #5
0
    def test_custom_config_created(self):
        # GIVEN
        self.assertFalse(
            os.path.exists(os.environ.get("HELIUMCLI_CONFIG_PATH")))
        os.environ["HELIUMCLI_GIT_PROJECT"] = "[email protected]:SomeProject"
        os.environ["HELIUMCLI_PROJECTS"] = '["proj1", "proj2", "project3"]'
        os.environ["HELIUMCLI_PROJECTS_RELATIVE_DIR"] = "some/dir/projects"
        os.environ["HELIUMCLI_SERVER_BIN_FILENAME"] = "some/bin/server"
        os.environ["HELIUMCLI_ANSIBLE_RELATIVE_DIR"] = "some/dir/ansible"
        os.environ["HELIUMCLI_ANSIBLE_HOSTS_FILENAME"] = "myhosts"
        os.environ["HELIUMCLI_ANSIBLE_COPYRIGHT_NAME_VAR"] = "my_dev_name"
        os.environ["HELIUMCLI_VERSION_INFO_PROJECT"] = "proj2"
        os.environ["HELIUMCLI_VERSION_INFO_PATH"] = "some/path/project/version"
        os.environ[
            "HELIUMCLI_HOST_PROVISION_COMMAND"] = "sudo yum install python"

        # WHEN
        config = utils.get_config(True)

        # THEN
        self.assertTrue(os.environ.get("HELIUMCLI_CONFIG_PATH"))
        self.assertEqual(
            config, {
                "ansibleCopyrightNameVar": "my_dev_name",
                "ansibleRelativeDir": "some/dir/ansible",
                "gitProject": "[email protected]:SomeProject",
                "hostProvisionCommand": "sudo yum install python",
                "projects": ["proj1", "proj2", "project3"],
                "projectsRelativeDir": "some/dir/projects",
                "serverBinFilename": "some/bin/server",
                "versionInfo": {
                    "path": "some/path/project/version",
                    "project": "proj2"
                }
            })
Exemple #6
0
def given_python_version_file_exists(version='1.2.2'):
    config = utils.get_config(True)

    version_file_path = os.path.join(utils.get_projects_dir(),
                                     config["versionInfo"]["project"],
                                     config["versionInfo"]["path"])
    if not os.path.exists(os.path.dirname(version_file_path)):
        os.makedirs(os.path.dirname(version_file_path))

    version_file = open(version_file_path, "w")
    version_file.write("""\"\"\"
Header comments and such.
\"\"\"

import os

__author__ = 'Alex Laird'
__copyright__ = 'Copyright 2017, Helium Edu'
__version__ = '{}'

# ############################
# Project configuration
# ############################
    
# Project information

PROJECT_NAME = os.environ.get('PROJECT_NAME')
MORE_SETTINGS = 'more_settings_after_this'
""".format(version))
    version_file.close()

    return version_file_path
Exemple #7
0
    def test_start_servers(self):
        # GIVEN
        commonhelper.given_runserver_exists("platform")

        # WHEN
        main(["main.py", "--init", "start-servers"])

        # THEN
        self.mock_subprocess_popen.assert_called_once_with(
            os.path.join(utils.get_projects_dir(), "platform",
                         utils.get_config(True)["serverBinFilename"]))
Exemple #8
0
def given_runserver_exists(project):
    config = utils.get_config(True)

    if not os.path.exists(os.path.join(utils.get_projects_dir(), project)):
        os.makedirs(os.path.join(utils.get_projects_dir(), project))

    os.mkdir(
        os.path.join(utils.get_projects_dir(), project,
                     os.path.dirname(config["serverBinFilename"])))
    open(
        os.path.join(utils.get_projects_dir(), project,
                     config["serverBinFilename"]), "wb").close()
Exemple #9
0
def given_project_package_json_exists(project, version='1.2.2'):
    utils.get_config(True)

    versioned_file_path = os.path.join(utils.get_projects_dir(), project,
                                       'package.json')
    if not os.path.exists(os.path.dirname(versioned_file_path)):
        os.makedirs(os.path.dirname(versioned_file_path))

    versioned_file = open(versioned_file_path, "w")
    versioned_file.write("""{
  "name": "my-project",
  "version": \"""" + version + """\",
  "author": "Alex Laird",
  "dependencies": {
    "npm": "^1.2.3",
    "some-dep": "^4.5.6"
  }
}
""")
    versioned_file.close()

    return versioned_file_path
Exemple #10
0
def given_project_python_versioned_file_exists(project, filename='maths.py'):
    utils.get_config(True)

    versioned_file_path = os.path.join(utils.get_projects_dir(), project,
                                       filename)
    if not os.path.exists(os.path.dirname(versioned_file_path)):
        os.makedirs(os.path.dirname(versioned_file_path))

    versioned_file = open(versioned_file_path, "w")
    versioned_file.write("""\"\"\"
Other header comments and such.
\"\"\"
    
__author__ = 'Alex Laird'
__copyright__ = 'Copyright 2017, Helium Edu'
__version__ = '1.2.2'
    
def sum(a, b):
    return a + b
""")
    versioned_file.close()

    return versioned_file_path
Exemple #11
0
    def test_deploy_build(self):
        self.subprocess_popen.stop()

        # GIVEN
        commonhelper.given_hosts_file_exists()

        # WHEN
        main(["main.py", "--init", "deploy-build", "1.2.3", "devbox"])

        # THEN
        self.assertEqual(self.mock_subprocess_call.call_count, 2)
        self.mock_subprocess_call.assert_any_call([
            "ssh", "-t", "*****@*****.**",
            utils.get_config(True)["hostProvisionCommand"]
        ])
        self.mock_subprocess_call.assert_any_call([
            "ansible-playbook",
            '--inventory-file={}/hosts/devbox'.format(utils.get_ansible_dir()),
            '-v', '--extra-vars', 'build_version=1.2.3',
            '{}/{}.yml'.format(utils.get_ansible_dir(), "devbox")
        ])

        self.subprocess_popen.start()