Skip to content

Commit 4356dc3

Browse files
author
Burak Yigit Kaya
committed
Better test structure
1 parent 1cbfaa1 commit 4356dc3

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ python:
55
- "3.4"
66
- "3.5"
77
install: "pip install ."
8-
script: "python phabricator/tests.py"
8+
script: "python -m phabricator.tests.test_phabricator"

phabricator/tests/__init__.py

Whitespace-only changes.

phabricator/tests/resources/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fdhcq3zsyijnm4h6gmh43zue5umsmng5t4dlwodvmiz4cnc6fl6fzrvjbfg2ftktrcddan7b3xtgmfge2afbrh4uwam6pfxpq5dbkhbl6mgaijdzpq5efw2ynlnjhoeqyh6dakl4yg346gbhabzkcxreu7hcjhw6vo6wwa7ky2sjdk742khlgsakwtme6sr2dfkhlxxkcqw3jngyrq5zj7m6m7hnscuzlzsviawnvg47pe7l4hxiexpbb5k456r
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"conduit.connect": "{\"result\":{\"connectionID\":1759,\"sessionKey\":\"lwvyv7f6hlzb2vawac6reix7ejvjty72svnir6zy\",\"userPHID\":\"PHID-USER-6ij4rnamb2gsfpdkgmny\"},\"error_code\":null,\"error_info\":null}",
3+
"user.whoami": "{\"result\":{\"phid\":\"PHID-USER-6ij4rnamz2gxfpbkamny\",\"userName\":\"testaccount\",\"realName\":\"Test Account\"},\"error_code\":null,\"error_info\":null}",
4+
"maniphest.find": "{\"result\":{\"PHID-TASK-4cgpskv6zzys6rp5rvrc\":{\"id\":\"722\",\"phid\":\"PHID-TASK-4cgpskv6zzys6rp5rvrc\",\"authorPHID\":\"PHID-USER-5022a9389121884ab9db\",\"ownerPHID\":\"PHID-USER-5022a9389121884ab9db\",\"ccPHIDs\":[\"PHID-USER-5022a9389121884ab9db\",\"PHID-USER-ba8aeea1b3fe2853d6bb\"],\"status\":\"3\",\"priority\":\"Needs Triage\",\"title\":\"Relations should be two-way\",\"description\":\"When adding a differential revision you can specify Maniphest Tickets to add the relation. However, this doesnt add the relation from the ticket -> the differently.(This was added via the commit message)\",\"projectPHIDs\":[\"PHID-PROJ-358dbc2e601f7e619232\",\"PHID-PROJ-f58a9ac58c333f106a69\"],\"uri\":\"https://secure.phabricator.com/T722\",\"auxiliary\":[],\"objectName\":\"T722\",\"dateCreated\":\"1325553508\",\"dateModified\":\"1325618490\"}},\"error_code\":null,\"error_info\":null}"
5+
}

phabricator/tests.py renamed to phabricator/tests/test_phabricator.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
except ImportError:
1414
import mock
1515

16+
from pkg_resources import resource_string
17+
import json
1618

1719
import phabricator
1820

1921

20-
RESPONSES = {
21-
'conduit.connect': '{"result":{"connectionID":1759,"sessionKey":"lwvyv7f6hlzb2vawac6reix7ejvjty72svnir6zy","userPHID":"PHID-USER-6ij4rnamb2gsfpdkgmny"},"error_code":null,"error_info":null}',
22-
'user.whoami': '{"result":{"phid":"PHID-USER-6ij4rnamz2gxfpbkamny","userName":"testaccount","realName":"Test Account"},"error_code":null,"error_info":null}',
23-
'maniphest.find': '{"result":{"PHID-TASK-4cgpskv6zzys6rp5rvrc":{"id":"722","phid":"PHID-TASK-4cgpskv6zzys6rp5rvrc","authorPHID":"PHID-USER-5022a9389121884ab9db","ownerPHID":"PHID-USER-5022a9389121884ab9db","ccPHIDs":["PHID-USER-5022a9389121884ab9db","PHID-USER-ba8aeea1b3fe2853d6bb"],"status":"3","priority":"Needs Triage","title":"Relations should be two-way","description":"When adding a differential revision you can specify Maniphest Tickets to add the relation. However, this doesnt add the relation from the ticket -> the differently.(This was added via the commit message)","projectPHIDs":["PHID-PROJ-358dbc2e601f7e619232","PHID-PROJ-f58a9ac58c333f106a69"],"uri":"https:\/\/secure.phabricator.com\/T722","auxiliary":[],"objectName":"T722","dateCreated":"1325553508","dateModified":"1325618490"}},"error_code":null,"error_info":null}'
24-
}
25-
26-
CERTIFICATE = (
27-
'fdhcq3zsyijnm4h6gmh43zue5umsmng5t4dlwodvmiz4cnc6fl6f'
28-
'zrvjbfg2ftktrcddan7b3xtgmfge2afbrh4uwam6pfxpq5dbkhbl'
29-
'6mgaijdzpq5efw2ynlnjhoeqyh6dakl4yg346gbhabzkcxreu7hc'
30-
'jhw6vo6wwa7ky2sjdk742khlgsakwtme6sr2dfkhlxxkcqw3jngy'
31-
'rq5zj7m6m7hnscuzlzsviawnvg47pe7l4hxiexpbb5k456r'
22+
RESPONSES = json.loads(
23+
resource_string(
24+
'phabricator.tests.resources',
25+
'responses.json'
26+
).decode('utf8')
3227
)
28+
CERTIFICATE = resource_string(
29+
'phabricator.tests.resources',
30+
'certificate.txt'
31+
).decode('utf8').strip()
32+
3333

3434
# Protect against local user's .arcrc interference.
3535
phabricator.ARCRC = {}
@@ -52,7 +52,9 @@ def test_generate_hash(self):
5252
@mock.patch('phabricator.httplib.HTTPConnection')
5353
def test_connect(self, mock_connection):
5454
mock_obj = mock_connection.return_value = mock.Mock()
55-
mock_obj.getresponse.return_value = StringIO(RESPONSES['conduit.connect'])
55+
mock_obj.getresponse.return_value = StringIO(
56+
RESPONSES['conduit.connect']
57+
)
5658
mock_obj.getresponse.return_value.status = 200
5759

5860
api = phabricator.Phabricator(
@@ -97,24 +99,34 @@ def test_bad_status(self, mock_connection):
9799
with self.assertRaises(phabricator.httplib.HTTPException):
98100
api.user.whoami()
99101

100-
101102
@mock.patch('phabricator.httplib.HTTPConnection')
102103
def test_maniphest_find(self, mock_connection):
103104
mock_obj = mock_connection.return_value = mock.Mock()
104-
mock_obj.getresponse.return_value = StringIO(RESPONSES['maniphest.find'])
105+
mock_obj.getresponse.return_value = StringIO(
106+
RESPONSES['maniphest.find']
107+
)
105108
mock_obj.getresponse.return_value.status = 200
106109

107-
api = phabricator.Phabricator(username='test', certificate='test', host='http://localhost')
110+
api = phabricator.Phabricator(
111+
username='test',
112+
certificate='test',
113+
host='http://localhost'
114+
)
108115
api._conduit = True
109116

110-
result = api.maniphest.find(ownerphids=['PHID-USER-5022a9389121884ab9db'])
117+
result = api.maniphest.find(
118+
ownerphids=['PHID-USER-5022a9389121884ab9db']
119+
)
111120
self.assertEqual(len(result), 1)
112121

113122
# Test iteration
114123
self.assertIsInstance([x for x in result], list)
115124

116125
# Test getattr
117-
self.assertEqual(result['PHID-TASK-4cgpskv6zzys6rp5rvrc']['status'], '3')
126+
self.assertEqual(
127+
result['PHID-TASK-4cgpskv6zzys6rp5rvrc']['status'],
128+
'3'
129+
)
118130

119131
def test_validation(self):
120132
self.api._conduit = True

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
description='Phabricator API Bindings',
2222
packages=find_packages(),
2323
zip_safe=False,
24-
test_suite='nose.collector',
24+
test_suite='phabricator.tests.test_phabricator',
2525
tests_require=tests_requires,
2626
include_package_data=True,
2727
classifiers=[

0 commit comments

Comments
 (0)