def test_projects_option(self, RuntimeMock): projects = [ Stubs.project(True), Stubs.project(True), ] RuntimeMock.return_value.installed_projects = [ projects[0], projects[1], Stubs.project(True), ] with patch.object( RuntimeMock.return_value, 'activate_project', wraps=self.stub_activate_project ) as activate_project_mock: result = Cli.run('up', '--projects=' + ','.join([projects[0].name, projects[1].name])) assert activate_project_mock.call_count == 2 assert activate_project_mock.call_args_list[0][0][0] == projects[0] assert activate_project_mock.call_args_list[1][0][0] == projects[1] assert result.exit_code == 0 assert result.output == \ 'Starting [%s]...\n' % projects[0].name + \ 'Starting [%s]...\n' % projects[1].name + \ '[%s] running @ %s\n' % (projects[0].name, 'http://%s.test' % projects[0].name) + \ '[%s] running @ %s\n' % (projects[1].name, 'http://%s.test' % projects[1].name)
def test_without_projects(self, RuntimeMock): RuntimeMock.return_value.installed_projects = [] result = Cli.run('ls') assert result.exit_code == 0 assert result.output == 'There are no projects installed, run metal install to install new projects\n'
def test_stopped_projects(self, RuntimeMock): project = Stubs.project() RuntimeMock.return_value.installed_projects = [project] result = Cli.run('ls') assert result.exit_code == 0 assert result.output == '[%s] stopped\n' % project.name
def test_exec(self, RuntimeMock): dir_name = os.path.basename(os.getcwd()) command = 'foo bar' result = Cli.run('exec', command) assert result.exit_code == 0 RuntimeMock.return_value.execute_command.assert_called_with( dir_name, command)
def test_ongoing_projects(self, RuntimeMock): project = Stubs.project(True, True) RuntimeMock.return_value.installed_projects = [project] result = Cli.run('ls') assert result.exit_code == 0 assert result.output == '[%s] running @ http://%s.test\n' % ( project.name, project.name)
def test_installed_project(self, RuntimeMock): project = Stubs.project() RuntimeMock.return_value.get_project.return_value = project result = Cli.run('build', '--project=' + project.name) RuntimeMock.return_value.build_project.assert_called_once_with(project) assert result.exit_code == 0 assert result.output == 'Building [%s]...\n' % project.name
def test_existing_project(self, RuntimeMock): project = Stubs.project(True) RuntimeMock.return_value.get_project.return_value = project result = Cli.run('uninstall', '--project=' + project.name) RuntimeMock.return_value.uninstall_project.assert_called_once_with( project) assert result.exit_code == 0 assert result.output == 'Uninstalling [%s]...\n' % project.name
def test_default_project(self, RuntimeMock): dir_name = os.path.basename(os.getcwd()) RuntimeMock.return_value.get_project.return_value = None result = Cli.run('build') RuntimeMock.return_value.get_project.assert_called_once_with(dir_name) assert result.exit_code != 0 assert isinstance(result.exception, ValueError) assert result.exception.message == 'Project [%s] is not installed' % dir_name
def test_uninstalled_project(self, RuntimeMock): project = Stubs.project() RuntimeMock.return_value.get_project.return_value = None result = Cli.run('build', '--project=' + project.name) RuntimeMock.return_value.get_project.assert_called_once_with( project.name) assert result.exit_code != 0 assert isinstance(result.exception, ValueError) assert result.exception.message == 'Project [%s] is not installed' % project.name
def test_mixed_projects(self, RuntimeMock): projects = [ Stubs.project(True, True), Stubs.project(), ] RuntimeMock.return_value.installed_projects = projects result = Cli.run('ls') assert result.exit_code == 0 assert result.output == '[%s] running @ http://%s.test\n[%s] stopped\n' % ( projects[0].name, projects[0].name, projects[1].name)
def test_new_project(self, RuntimeMock): path = os.getcwd() project_name = 'foobar' RuntimeMock.return_value.get_project.return_value = None result = Cli.run('new', project_name, '--framework=laravel') RuntimeMock.return_value.get_project.assert_called_once_with( project_name) RuntimeMock.return_value.create_project.assert_called_once_with( project_name, path, 'laravel') assert result.exit_code == 0 assert result.output == 'Creating [%s]...\n' % project_name
def test_new_project(self, RuntimeMock): dir_name = os.path.basename(os.getcwd()) RuntimeMock.return_value.get_project.return_value = None result = Cli.run('install', '--framework=laravel') RuntimeMock.return_value.get_project.assert_called_once_with(dir_name) RuntimeMock.return_value.install_project.assert_called_once() RuntimeMock.return_value.build_project.assert_called_once() project = RuntimeMock.return_value.install_project.call_args[0][0] isinstance(project, Project) assert project.name == dir_name assert project.framework == 'laravel' project = RuntimeMock.return_value.build_project.call_args[0][0] isinstance(project, Project) assert project.name == dir_name assert project.framework == 'laravel' assert result.exit_code == 0 assert result.output == 'Installing [%s]...\n' % dir_name
def test_only_flag(self, RuntimeMock): dir_name = os.path.basename(os.getcwd()) project = Stubs.project(True, name=dir_name) RuntimeMock.return_value.installed_projects = [ project, Stubs.project(True), ] with patch.object( RuntimeMock.return_value, 'activate_project', wraps=self.stub_activate_project ) as activate_project_mock: result = Cli.run('up', '--only') activate_project_mock.assert_called_once_with(project) assert result.exit_code == 0 assert result.output == \ 'Starting [%s]...\n' % project.name + \ '[%s] running @ %s\n' % (project.name, 'http://%s.test' % project.name)
def test_project_name_slugify(self, RuntimeMock): RuntimeMock.return_value.get_project.return_value = None name = 'Foobar and sons' slug = 'foobar-and-sons' result = Cli.run('install', '--name=' + name, '--framework=rails') RuntimeMock.return_value.get_project.assert_called_once_with( 'foobar-and-sons') RuntimeMock.return_value.install_project.assert_called_once() RuntimeMock.return_value.build_project.assert_called_once() project = RuntimeMock.return_value.install_project.call_args[0][0] isinstance(project, Project) assert project.name == slug assert project.framework == 'rails' project = RuntimeMock.return_value.build_project.call_args[0][0] isinstance(project, Project) assert project.name == slug assert project.framework == 'rails' assert result.exit_code == 0 assert result.output == 'Installing [%s]...\n' % slug