From 1d4c5c068e1f45b606665614bab09cd4eb74f228 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 14 Feb 2014 17:50:01 +0000 Subject: The basis for our trove tests Once this is finished it can be integrated with the test suite. --- test.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 test.py diff --git a/test.py b/test.py new file mode 100755 index 0000000..9ee74ee --- /dev/null +++ b/test.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +import os +import shutil +import subprocess +import string +import tempfile + +#TROVE_ADMIN_USER = 'testuser' +TROVE_ADMIN_USER = 'richardipsum' + +def remote_runcmd(url, command): + print 'Running: ' + string.join(command) + subprocess.check_output(['ssh', url] + command) + + # Err find out why this doesn't work when i'm less frazzled + #subprocess.Popen(['ssh', url] + command, shell=True) + +def run_git(args, working_dir): + #return cliapp.runcmd(['git'] + args, **kwargs) + print 'args', args + print 'Running: ', ['git'] + args + p = subprocess.Popen(['git'] + args, cwd=working_dir) + p.wait() + +def create_test_project(url, project): + def t(s): + return project + '-' + s + + remote_runcmd(url, ['group', 'add', t('managers'), + 'Managers for ' + project]) + remote_runcmd(url, ['group', 'adduser', t('managers'), TROVE_ADMIN_USER]) + + remote_runcmd(url, ['group', 'add', t('admins'), 'Admins for ' + project]) + remote_runcmd(url, ['group', 'addgroup', t('admins'), t('managers')]) + + remote_runcmd(url, ['group', 'add', t('writers'), + 'Users with write access to ' + project]) + remote_runcmd(url, ['group', 'addgroup', t('writers'), t('admins')]) + + remote_runcmd(url, ['group', 'add', t('readers'), + 'Users with read access to ' + project]) + remote_runcmd(url, ['group', 'addgroup', t('readers'), t('writers')]) + +def create_test_repo(remote_url, project, repo): + trove_id = 'ct-ri-4' #self.vm_nhame + + remote_runcmd(remote_url, + ['create', "%s/%s/%s" % (trove_id, project, repo)]) + +vm_name = 'ct-ri-4' +workspace_dir = tempfile.mkdtemp() + +print 'Created temporary workspace in', workspace_dir + +project = 'test-proj' +repo = 'test-repo' +filename = 'test-file' +repodir = os.path.join(workspace_dir, repo) + +remote_url = 'git@' + vm_name + +create_test_project(remote_url, project) +create_test_repo(remote_url, project, repo) + +# We should be able to clone +#run_git(['clone', 'git@%s:%s/%s' % (self.vm_name, project, repo)], +# cwd=workspace_dir) + +#run_git(['--version'], workspace_dir) + +run_git(['clone', 'git@%s:%s/%s/%s' % (vm_name, vm_name, project, repo)], + workspace_dir) + +with open(os.path.join(workspace_dir, repo, filename), 'w') as f: + f.write('A test file') + +run_git(['add', filename], repodir) +run_git(['commit', '-m', 'Add a test file'], repodir) +run_git(['push', 'origin', 'master'], repodir) +#run_git(['push', 'origin', '%s/%s/%s/%s' +# % (vm_name, project, TROVE_ADMIN_USER, 'test')], repodir) + +shutil.rmtree(workspace_dir) -- cgit v1.2.1