Skip to content

Commit 69492bc

Browse files
authored
use TESTSPACE_TOKEN in push env (#3)
* use TESTSPACE_TOKEN in push env
1 parent 7f106b8 commit 69492bc

File tree

4 files changed

+17
-45
lines changed

4 files changed

+17
-45
lines changed

tests/test_testspace.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
11
from testspace import testspace as ts
22

33

4-
def test_url_token():
4+
def test_url():
55
token = "abcxyzfortesting"
66
url = "abccorp.testspace.com"
77
project = "abccorp:application"
88
space = "master"
99
protocol = "https"
1010

11-
client_url = "{}:@{}".format(token, url)
12-
api_url = "{}://{}/api".format(protocol, url)
13-
1411
testspace = ts.Testspace(token, url, project, space)
15-
assert testspace.client_url == client_url
16-
assert testspace.api_url == api_url
17-
18-
19-
def test_url_password():
20-
token = "absmith:passfortesting"
21-
url = "abccorp.testspace.com"
22-
project = "abccorp:application"
23-
space = "master"
24-
protocol = "https"
25-
26-
client_url = "{}@{}".format(token, url)
27-
api_url = "{}://{}/api".format(protocol, url)
28-
29-
testspace = ts.Testspace(token, url, project, space)
30-
assert testspace.client_url == client_url
31-
assert testspace.api_url == api_url
12+
assert testspace.url == "{}://{}".format(protocol, url)
3213

3314

3415
def test_http():
@@ -38,10 +19,6 @@ def test_http():
3819
space = "master"
3920
protocol = "http"
4021

41-
client_url = "{}://{}:@{}".format(protocol, token, url)
42-
api_url = "{}://{}/api".format(protocol, url)
43-
4422
testspace_url = "{}://{}".format(protocol, url)
4523
testspace = ts.Testspace(token, testspace_url, project, space)
46-
assert testspace.client_url == client_url
47-
assert testspace.api_url == api_url
24+
assert testspace.url == "{}://{}".format(protocol, url)

tests/test_testspace_api.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ def test_get_api_endpoints(load_json, testspace_api, requests_mock):
3131

3232
@pytest.mark.parametrize("load_json", ["api_endpoints.json"], indirect=True)
3333
def test_get_api_endpoints_url_https(load_json, testspace_api, requests_mock):
34-
url = "{}://{}".format("https", testspace_api.url)
35-
testspace_url = "/".join([url, "api"])
36-
37-
testspace_api = ts.Testspace(testspace_api.token, url)
34+
testspace_url = "/".join([testspace_api.url, "api"])
3835

3936
requests_mock.get(testspace_url, json=load_json)
4037
response_json = testspace_api.get_api_endpoints()
@@ -68,8 +65,7 @@ def test_get_projects(load_json, testspace_api, requests_mock):
6865

6966
@pytest.mark.parametrize("load_json", ["projects.json"], indirect=True)
7067
def test_get_projects_paginated(load_json, testspace_api, requests_mock):
71-
url = testspace_api.url
72-
testspace_url = "https://{}/api/projects".format(url)
68+
testspace_url = "{}/api/projects".format(testspace_api.url)
7369

7470
links_string_first = '<{}?page={}>; rel="{}"'.format(testspace_url, 1, "first")
7571
links_string_next = '<{}?page={}>; rel="{}"'.format(testspace_url, 2, "next")

tests/test_testspace_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def test_push(mocker, testspace_client):
3333
message=message,
3434
)
3535

36-
url = "{}@{}/{}/{}?{}#{}".format(
37-
testspace_client.token,
36+
url = "{}/{}/{}?{}#{}".format(
3837
testspace_client.url,
3938
testspace_client.project,
4039
testspace_client.space,

testspace/testspace.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import os
12
import requests
23
import subprocess
34

45

56
class Testspace:
67
def __init__(self, token, url, project=None, space=None, verify=True):
7-
self.url = url
88
self.project = project
99
self.space = space
1010
self.verify = verify
@@ -13,15 +13,11 @@ def __init__(self, token, url, project=None, space=None, verify=True):
1313
if ":" not in token:
1414
self.token = "{}:".format(token)
1515

16-
split_url = self.url.split("://")
16+
split_url = url.split("://")
1717
if len(split_url) > 1 and split_url[0] in ["http", "https"]:
18-
self.client_url = "{}://{}@{}".format(
19-
split_url[0], self.token, split_url[1]
20-
)
21-
self.api_url = "/".join([self.url, "api"])
18+
self.url = url
2219
else:
23-
self.client_url = "{}@{}".format(self.token, self.url)
24-
self.api_url = "/".join(["{}://{}".format("https", self.url), "api"])
20+
self.url = "{}://{}".format("https", url)
2521

2622
def push(
2723
self,
@@ -49,7 +45,7 @@ def push(
4945
if file is not None:
5046
command_args_list.append(file)
5147

52-
full_client_url = "/".join([self.client_url, project, space])
48+
full_client_url = "/".join([self.url, project, space])
5349

5450
if how is not None:
5551
if how not in ["full", "start", "add", "finish"]:
@@ -68,7 +64,11 @@ def push(
6864
if message is not None:
6965
command_args_list.append("--message={}".format(message))
7066

71-
subprocess.run(command_args_list, check=True)
67+
subprocess.run(
68+
command_args_list,
69+
check=True,
70+
env=dict(os.environ, TESTSPACE_TOKEN=self.token),
71+
)
7272

7373
def get_api_endpoints(self):
7474
return self.get_request_json()
@@ -205,7 +205,7 @@ def delete_request(self, path=None):
205205
return response
206206

207207
def get_api_url(self):
208-
return self.api_url
208+
return "/".join([self.url, "api"])
209209

210210
def get_projects_path(self):
211211
return "projects"

0 commit comments

Comments
 (0)