| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bbcccaa commit 7e4e1a3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + #!/bin/bash | ||
| 2 | + # Copyright (C) 2015 Gauvain Pocentek <gauvain@pocentek.net> | ||
| 3 | + # | ||
| 4 | + # This program is free software: you can redistribute it and/or modify | ||
| 5 | + # it under the terms of the GNU Lesser General Public License as published by | ||
| 6 | + # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | + # (at your option) any later version. | ||
| 8 | + # | ||
| 9 | + # This program is distributed in the hope that it will be useful, | ||
| 10 | + # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | + # GNU Lesser General Public License for more details. | ||
| 13 | + # | ||
| 14 | + # You should have received a copy of the GNU Lesser General Public License | ||
| 15 | + # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | + | ||
| 17 | + cleanup() { | ||
| 18 | + rm -f /tmp/python-gitlab.cfg | ||
| 19 | + docker kill gitlab-test >/dev/null 2>&1 | ||
| 20 | + docker rm gitlab-test >/dev/null 2>&1 | ||
| 21 | + deactivate || true | ||
| 22 | + rm -rf $VENV | ||
| 23 | + } | ||
| 24 | + trap cleanup EXIT | ||
| 25 | + | ||
| 26 | + setenv_script=$(dirname $0)/build_test_env.sh | ||
| 27 | + | ||
| 28 | + . $setenv_script "$@" | ||
| 29 | + | ||
| 30 | + VENV=$(pwd)/.venv | ||
| 31 | + | ||
| 32 | + $VENV_CMD $VENV | ||
| 33 | + . $VENV/bin/activate | ||
| 34 | + pip install -rrequirements.txt | ||
| 35 | + pip install -e . | ||
| 36 | + | ||
| 37 | + python $(dirname $0)/python_test.py | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,131 @@ | |||
| 1 | + import base64 | ||
| 2 | + | ||
| 3 | + import gitlab | ||
| 4 | + | ||
| 5 | + LOGIN = 'root' | ||
| 6 | + PASSWORD = '5iveL!fe' | ||
| 7 | + | ||
| 8 | + SSH_KEY = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZAjAX8vTiHD7Yi3/EzuVaDChtih" | ||
| 9 | + "79HyJZ6H9dEqxFfmGA1YnncE0xujQ64TCebhkYJKzmTJCImSVkOu9C4hZgsw6eE76n" | ||
| 10 | + "+Cg3VwEeDUFy+GXlEJWlHaEyc3HWioxgOALbUp3rOezNh+d8BDwwqvENGoePEBsz5l" | ||
| 11 | + "a6WP5lTi/HJIjAl6Hu+zHgdj1XVExeH+S52EwpZf/ylTJub0Bl5gHwf/siVE48mLMI" | ||
| 12 | + "sqrukXTZ6Zg+8EHAIvIQwJ1dKcXe8P5IoLT7VKrbkgAnolS0I8J+uH7KtErZJb5oZh" | ||
| 13 | + "S4OEwsNpaXMAr+6/wWSpircV2/e7sFLlhlKBC4Iq1MpqlZ7G3p foo@bar") | ||
| 14 | + | ||
| 15 | + # login/password authentication | ||
| 16 | + gl = gitlab.Gitlab('http://localhost:8080', email=LOGIN, password=PASSWORD) | ||
| 17 | + gl.auth() | ||
| 18 | + token_from_auth = gl.private_token | ||
| 19 | + | ||
| 20 | + # token authentication from config file | ||
| 21 | + gl = gitlab.Gitlab.from_config(config_files=['/tmp/python-gitlab.cfg']) | ||
| 22 | + assert(token_from_auth == gl.private_token) | ||
| 23 | + gl.auth() | ||
| 24 | + assert(isinstance(gl.user, gitlab.objects.CurrentUser)) | ||
| 25 | + | ||
| 26 | + # user manipulations | ||
| 27 | + new_user = gl.users.create({'email': 'foo@bar.com', 'username': 'foo', | ||
| 28 | + 'name': 'foo', 'password': 'foo_password'}) | ||
| 29 | + users_list = gl.users.list() | ||
| 30 | + for user in users_list: | ||
| 31 | + if user.username == 'foo': | ||
| 32 | + break | ||
| 33 | + assert(new_user.username == user.username) | ||
| 34 | + assert(new_user.email == user.email) | ||
| 35 | + | ||
| 36 | + # SSH keys | ||
| 37 | + key = new_user.keys.create({'title': 'testkey', 'key': SSH_KEY}) | ||
| 38 | + assert(len(new_user.keys.list()) == 1) | ||
| 39 | + key.delete() | ||
| 40 | + | ||
| 41 | + new_user.delete() | ||
| 42 | + assert(len(gl.users.list()) == 1) | ||
| 43 | + | ||
| 44 | + # current user key | ||
| 45 | + key = gl.user.keys.create({'title': 'testkey', 'key': SSH_KEY}) | ||
| 46 | + assert(len(gl.user.keys.list()) == 1) | ||
| 47 | + key.delete() | ||
| 48 | + | ||
| 49 | + # groups | ||
| 50 | + user1 = gl.users.create({'email': 'user1@test.com', 'username': 'user1', | ||
| 51 | + 'name': 'user1', 'password': 'user1_pass'}) | ||
| 52 | + user2 = gl.users.create({'email': 'user2@test.com', 'username': 'user2', | ||
| 53 | + 'name': 'user2', 'password': 'user2_pass'}) | ||
| 54 | + group1 = gl.groups.create({'name': 'group1', 'path': 'group1'}) | ||
| 55 | + group2 = gl.groups.create({'name': 'group2', 'path': 'group2'}) | ||
| 56 | + | ||
| 57 | + assert(len(gl.groups.list()) == 2) | ||
| 58 | + assert(len(gl.groups.search("1")) == 1) | ||
| 59 | + | ||
| 60 | + group1.members.create({'access_level': gitlab.Group.OWNER_ACCESS, | ||
| 61 | + 'user_id': user1.id}) | ||
| 62 | + group1.members.create({'access_level': gitlab.Group.GUEST_ACCESS, | ||
| 63 | + 'user_id': user2.id}) | ||
| 64 | + | ||
| 65 | + group2.members.create({'access_level': gitlab.Group.OWNER_ACCESS, | ||
| 66 | + 'user_id': user2.id}) | ||
| 67 | + | ||
| 68 | + # Administrator belongs to the groups | ||
| 69 | + assert(len(group1.members.list()) == 3) | ||
| 70 | + assert(len(group2.members.list()) == 2) | ||
| 71 | + | ||
| 72 | + group1.members.delete(user1.id) | ||
| 73 | + assert(len(group1.members.list()) == 2) | ||
| 74 | + member = group1.members.get(user2.id) | ||
| 75 | + member.access_level = gitlab.Group.OWNER_ACCESS | ||
| 76 | + member.save() | ||
| 77 | + member = group1.members.get(user2.id) | ||
| 78 | + assert(member.access_level == gitlab.Group.OWNER_ACCESS) | ||
| 79 | + | ||
| 80 | + group2.members.delete(gl.user.id) | ||
| 81 | + | ||
| 82 | + # hooks | ||
| 83 | + hook = gl.hooks.create({'url': 'http://whatever.com'}) | ||
| 84 | + assert(len(gl.hooks.list()) == 1) | ||
| 85 | + hook.delete() | ||
| 86 | + assert(len(gl.hooks.list()) == 0) | ||
| 87 | + | ||
| 88 | + # projects | ||
| 89 | + admin_project = gl.projects.create({'name': 'admin_project'}) | ||
| 90 | + gr1_project = gl.projects.create({'name': 'gr1_project', | ||
| 91 | + 'namespace_id': group1.id}) | ||
| 92 | + gr2_project = gl.projects.create({'name': 'gr2_project', | ||
| 93 | + 'namespace_id': group2.id}) | ||
| 94 | + | ||
| 95 | + assert(len(gl.projects.all()) == 3) | ||
| 96 | + assert(len(gl.projects.owned()) == 2) | ||
| 97 | + assert(len(gl.projects.search("admin")) == 1) | ||
| 98 | + | ||
| 99 | + # project content (files) | ||
| 100 | + admin_project.files.create({'file_path': 'README', | ||
| 101 | + 'branch_name': 'master', | ||
| 102 | + 'content': 'Initial content', | ||
| 103 | + 'commit_message': 'Initial commit'}) | ||
| 104 | + readme = admin_project.files.get(file_path='README', ref='master') | ||
| 105 | + readme.content = base64.b64encode("Improved README") | ||
| 106 | + readme.save(branch_name="master", commit_message="new commit") | ||
| 107 | + readme.delete(commit_message="Removing README") | ||
| 108 | + | ||
| 109 | + readme = admin_project.files.create({'file_path': 'README.rst', | ||
| 110 | + 'branch_name': 'master', | ||
| 111 | + 'content': 'Initial content', | ||
| 112 | + 'commit_message': 'New commit'}) | ||
| 113 | + | ||
| 114 | + # labels | ||
| 115 | + label1 = admin_project.labels.create({'name': 'label1', 'color': '#778899'}) | ||
| 116 | + assert(len(admin_project.labels.list()) == 1) | ||
| 117 | + label1.new_name = 'label1updated' | ||
| 118 | + label1.save() | ||
| 119 | + assert(label1.name == 'label1updated') | ||
| 120 | + # FIXME(gpocentek): broken | ||
| 121 | + # label1.delete() | ||
| 122 | + | ||
| 123 | + # milestones | ||
| 124 | + m1 = admin_project.milestones.create({'title': 'milestone1'}) | ||
| 125 | + assert(len(admin_project.milestones.list()) == 1) | ||
| 126 | + m1.due_date = '2020-01-01T00:00:00Z' | ||
| 127 | + m1.save() | ||
| 128 | + m1.state_event = 'close' | ||
| 129 | + m1.save() | ||
| 130 | + m1 = admin_project.milestones.get(1) | ||
| 131 | + assert(m1.state == 'closed') | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments