Skip to content

Commit 9169256

Browse files
pyhedgehogguyzmo
authored andcommitted
Fix of build_url method and update of the gogs test init env
Signed-off-by: Guyzmo <[email protected]>
1 parent 9e0101d commit 9169256

File tree

6 files changed

+90
-76
lines changed

6 files changed

+90
-76
lines changed

git_repo/services/ext/gogs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def set_default_private(self, p):
3232
def setup_session(self, ssl_config, proxy=dict()):
3333
self.session.verify = ssl_config
3434
self.session.proxies.update(proxy)
35+
# this is required to detect fresh GoGS server that redirects everything to /install
36+
self.session.max_redirects = 0
3537

3638
@property
3739
def username(self):
@@ -102,7 +104,7 @@ def connect(self):
102104
def get_auth_token(cls, login, password, prompt=None):
103105
import platform
104106
name = 'git-repo token used on {}'.format(platform.node())
105-
gg = GogsApi(cls.build_url())
107+
gg = GogsApi(cls.build_url(cls))
106108
auth = UsernamePassword(login, password)
107109
tokens = gg.get_tokens(auth, login)
108110
tokens = dict((token.name, token.token) for token in tokens)

git_repo/services/service.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,23 @@ def __init__(self, r=None, c=None, hc=[]):
203203
'''name of the git user to use for SSH remotes'''
204204
git_user = 'git'
205205

206-
@classmethod
207-
def build_url(cls):
208-
netloc = cls.fqdn if not getattr(cls, 'port', None) else '{}:{}'.format(cls.fqdn, cls.port)
209-
if not getattr(cls, 'scheme', None):
210-
cls.scheme = 'https'
211-
return ParseResult(cls.scheme, netloc, *['']*4).geturl()
206+
@staticmethod
207+
def build_url(obj):
208+
scheme = getattr(obj, 'scheme', 'https')
209+
port = getattr(obj, 'port', None)
210+
# skip useless port specification
211+
if (not port
212+
or scheme == 'https' and str(port) == '443'
213+
or scheme == 'http' and str(port) == '80'):
214+
netloc = obj.fqdn
215+
else:
216+
netloc = '{}:{}'.format(obj.fqdn, port)
217+
return ParseResult(scheme, netloc, *['']*4).geturl()
212218

213219
@property
214220
def url_ro(self):
215221
'''Property that returns the HTTP URL of the service'''
216-
return self.build_url()
222+
return self.build_url(self)
217223

218224
@property
219225
def url_rw(self):
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
## Steps to re-create test environment
2-
3-
* `cd <path to git-repo>/tests/integration/local/gogs`
4-
* `./init_conf.sh` # this will change `custom/conf/app.ini` as repository/ROOT must be full path
5-
* `<path to gogs>/gogs web --config custom/conf/app.ini` # run with local config. Gitea also supported
6-
* `./init.sh` # this will create users, organizations and repositories required for testing. Server must be completely started (listeninig)
7-
8-
Under Windows cygwin bash required for scripts (mingw/msys not tested).
1+
## Steps to re-create test environment
2+
3+
* `cd <path to git-repo>/tests/integration/local/gogs`
4+
* `./init_conf.sh` # this will change `custom/conf/app.ini` as repository/ROOT must be full path
5+
* `<path to gogs>/gogs web --config custom/conf/app.ini` # run with local config. Gitea also supported
6+
* `./init.sh` # this will create users, organizations and repositories required for testing. Server must be completely started (listeninig)
7+
8+
Under Windows cygwin bash required for scripts (mingw/msys not tested).
9+
10+
## Steps to setup test parameters
11+
12+
* `export PRIVATE_KEY_GOGS=...` # value printed by `init.sh` script
13+
* `GOGS_NAMESPACE=git-repo-test`
14+
* `GOGS_URL=http://127.0.0.1:3000`
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
APP_NAME = git-repo gogs test
2-
RUN_USER = git
3-
RUN_MODE = prod
4-
5-
[repository]
6-
ROOT = gogs-repositories
7-
8-
[database]
9-
DB_TYPE = sqlite3
10-
HOST = 127.0.0.1:3306
11-
NAME = gogs
12-
USER = root
13-
PASSWD =
14-
SSL_MODE = true
15-
PATH = data/gogs.db
16-
17-
[server]
18-
DOMAIN = 127.0.0.1
19-
PROTOCOL = http
20-
HTTP_ADDR = 127.0.0.1
21-
HTTP_PORT = 3000
22-
ROOT_URL = http://127.0.0.1:3000/
23-
DISABLE_SSH = false
24-
START_SSH_SERVER = true
25-
SSH_PORT = 3022
26-
OFFLINE_MODE = true
27-
28-
[mailer]
29-
ENABLED = false
30-
31-
[service]
32-
REGISTER_EMAIL_CONFIRM = false
33-
ENABLE_NOTIFY_MAIL = false
34-
DISABLE_REGISTRATION = true
35-
ENABLE_CAPTCHA = false
36-
REQUIRE_SIGNIN_VIEW = false
37-
38-
[picture]
39-
DISABLE_GRAVATAR = false
40-
ENABLE_FEDERATED_AVATAR = false
41-
42-
[session]
43-
PROVIDER = file
44-
45-
[log]
46-
MODE = file
47-
LEVEL = Info
48-
ROOT_PATH = log
49-
50-
[security]
51-
INSTALL_LOCK = true
52-
53-
[attachment]
54-
ENABLED = true
55-
PATH = private
56-
ALLOWED_TYPES = */*
1+
APP_NAME = git-repo gogs test
2+
RUN_USER = git
3+
RUN_MODE = prod
4+
5+
[repository]
6+
ROOT = gogs-repositories
7+
8+
[database]
9+
DB_TYPE = sqlite3
10+
HOST = 127.0.0.1:3306
11+
NAME = gogs
12+
USER = root
13+
PASSWD =
14+
SSL_MODE = true
15+
PATH = data/gogs.db
16+
17+
[server]
18+
DOMAIN = 127.0.0.1
19+
PROTOCOL = http
20+
HTTP_ADDR = 127.0.0.1
21+
HTTP_PORT = 3000
22+
ROOT_URL = http://127.0.0.1:3000/
23+
DISABLE_SSH = false
24+
START_SSH_SERVER = true
25+
SSH_PORT = 3022
26+
OFFLINE_MODE = true
27+
28+
[mailer]
29+
ENABLED = false
30+
31+
[service]
32+
REGISTER_EMAIL_CONFIRM = false
33+
ENABLE_NOTIFY_MAIL = false
34+
DISABLE_REGISTRATION = true
35+
ENABLE_CAPTCHA = false
36+
REQUIRE_SIGNIN_VIEW = false
37+
38+
[picture]
39+
DISABLE_GRAVATAR = false
40+
ENABLE_FEDERATED_AVATAR = false
41+
42+
[session]
43+
PROVIDER = file
44+
45+
[log]
46+
MODE = file
47+
LEVEL = Info
48+
ROOT_PATH = log
49+
50+
[security]
51+
INSTALL_LOCK = true
52+
53+
[attachment]
54+
ENABLED = true
55+
PATH = private
56+
ALLOWED_TYPES = */*

tests/integration/local/gogs/init.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/bin/bash
22
echo "Checking user test-admin in Gogs on http://127.0.0.1:3000"
3-
if python3 -c "import sys,gogs_client;up=gogs_client.UsernamePassword('test-admin','test-admin');s=gogs_client.GogsApi('http://127.0.0.1:3000');sys.exit(s.valid_authentication(up))" ; then
3+
if ! python3 -c "import sys,gogs_client;up=gogs_client.UsernamePassword('test-admin','test-admin');s=gogs_client.GogsApi('http://127.0.0.1:3000');sys.exit(s.authenticated_user(up).user_id<1)" 2>/dev/null ; then
44
echo "Creating admin user test-admin"
55
gogs admin create-user --config custom/conf/app.ini --name=test-admin --password=test-admin [email protected] --admin=true
66
fi
77
echo "Checking user other in Gogs on http://127.0.0.1:3000"
8-
if python3 -c "import sys,gogs_client;up=gogs_client.UsernamePassword('other','other');s=gogs_client.GogsApi('http://127.0.0.1:3000');sys.exit(s.valid_authentication(up))" ; then
8+
if ! python3 -c "import sys,gogs_client;up=gogs_client.UsernamePassword('other','other');s=gogs_client.GogsApi('http://127.0.0.1:3000');sys.exit(s.authenticated_user(up).user_id<1)" 2>/dev/null ; then
99
echo "Creating user other"
1010
gogs admin create-user --config custom/conf/app.ini --name=other --password=other [email protected]
1111
python3 -c "import os,gogs_client,functools;up=gogs_client.UsernamePassword('other','other');s=gogs_client.GogsApi('http://127.0.0.1:3000');r=s.create_repo(up,'git-repo',readme_template='Default',license_template='MIT License',auto_init=True);print('\t'.join(map(str,(r.repo_id,r.full_name,r.urls.ssh_url))))"
1212
fi
1313
echo "Checking user git-repo-test in Gogs on http://127.0.0.1:3000"
14-
if python3 -c "import sys,gogs_client;up=gogs_client.UsernamePassword('git-repo-test','git-repo-test');s=gogs_client.GogsApi('http://127.0.0.1:3000');sys.exit(s.valid_authentication(up))" ; then
14+
if ! python3 -c "import sys,gogs_client;up=gogs_client.UsernamePassword('git-repo-test','git-repo-test');s=gogs_client.GogsApi('http://127.0.0.1:3000');sys.exit(s.authenticated_user(up).user_id<1)" 2>/dev/null ; then
1515
echo "Creating user git-repo-test"
1616
gogs admin create-user --config custom/conf/app.ini --name=git-repo-test --password=git-repo-test [email protected]
1717
fi

tests/integration/local/gogs/init_conf.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ if [[ `uname -o` == Cygwin ]] ; then
44
else
55
GOGS_ROOT=$(pwd)'/gogs-repositories'
66
fi
7-
python3 -c "import sys;from six.moves.configparser import ConfigParser;from six.moves import cStringIO;c=ConfigParser();c.read_string('[APP]\n'+open('custom/conf/app.ini').read());gogsroot=sys.argv[1].replace('\\\\','/');[lambda:0,sys.exit][c.get('repository','ROOT')==gogsroot]();f=cStringIO();c.set('repository','ROOT',gogsroot);print(c.get('repository','ROOT'));c.write(f);open('custom/conf/app.ini','w').write(f.getvalue().replace('[APP]\n',''))" "$GOGS_ROOT"
7+
python3 -c "import sys;from configparser import RawConfigParser;from six.moves import cStringIO;C=type('C',(RawConfigParser,),dict(optionxform=lambda s,o:o));c=C();c.read_string('[APP]\n'+open('custom/conf/app.ini').read());gogsroot=sys.argv[1].replace('\\\\','/');[lambda:0,sys.exit][c.get('repository','ROOT')==gogsroot]();f=cStringIO();c.set('repository','ROOT',gogsroot);print(c.get('repository','ROOT'));c.write(f);open('custom/conf/app.ini','w').write(f.getvalue().replace('[APP]\n',''))" "$GOGS_ROOT"

0 commit comments

Comments
 (0)