diff --git a/.travis.yml b/.travis.yml index ebe4f9e..707b2ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ python: - "3.4" - "3.5" install: "pip install ." -script: "python phabricator/tests.py" +script: "python -m phabricator.tests.test_phabricator" diff --git a/phabricator/tests/__init__.py b/phabricator/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/phabricator/tests/resources/__init__.py b/phabricator/tests/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/phabricator/tests/resources/certificate.txt b/phabricator/tests/resources/certificate.txt new file mode 100644 index 0000000..a3589fd --- /dev/null +++ b/phabricator/tests/resources/certificate.txt @@ -0,0 +1 @@ +fdhcq3zsyijnm4h6gmh43zue5umsmng5t4dlwodvmiz4cnc6fl6fzrvjbfg2ftktrcddan7b3xtgmfge2afbrh4uwam6pfxpq5dbkhbl6mgaijdzpq5efw2ynlnjhoeqyh6dakl4yg346gbhabzkcxreu7hcjhw6vo6wwa7ky2sjdk742khlgsakwtme6sr2dfkhlxxkcqw3jngyrq5zj7m6m7hnscuzlzsviawnvg47pe7l4hxiexpbb5k456r diff --git a/phabricator/tests/resources/responses.json b/phabricator/tests/resources/responses.json new file mode 100644 index 0000000..2bb85e9 --- /dev/null +++ b/phabricator/tests/resources/responses.json @@ -0,0 +1,5 @@ +{ + "conduit.connect": "{\"result\":{\"connectionID\":1759,\"sessionKey\":\"lwvyv7f6hlzb2vawac6reix7ejvjty72svnir6zy\",\"userPHID\":\"PHID-USER-6ij4rnamb2gsfpdkgmny\"},\"error_code\":null,\"error_info\":null}", + "user.whoami": "{\"result\":{\"phid\":\"PHID-USER-6ij4rnamz2gxfpbkamny\",\"userName\":\"testaccount\",\"realName\":\"Test Account\"},\"error_code\":null,\"error_info\":null}", + "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}" +} diff --git a/phabricator/tests.py b/phabricator/tests/test_phabricator.py similarity index 62% rename from phabricator/tests.py rename to phabricator/tests/test_phabricator.py index aaf78ca..4c1a363 100644 --- a/phabricator/tests.py +++ b/phabricator/tests/test_phabricator.py @@ -13,23 +13,23 @@ except ImportError: import mock +from pkg_resources import resource_string +import json import phabricator -RESPONSES = { - 'conduit.connect': '{"result":{"connectionID":1759,"sessionKey":"lwvyv7f6hlzb2vawac6reix7ejvjty72svnir6zy","userPHID":"PHID-USER-6ij4rnamb2gsfpdkgmny"},"error_code":null,"error_info":null}', - 'user.whoami': '{"result":{"phid":"PHID-USER-6ij4rnamz2gxfpbkamny","userName":"testaccount","realName":"Test Account"},"error_code":null,"error_info":null}', - '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}' -} - -CERTIFICATE = ( - 'fdhcq3zsyijnm4h6gmh43zue5umsmng5t4dlwodvmiz4cnc6fl6f' - 'zrvjbfg2ftktrcddan7b3xtgmfge2afbrh4uwam6pfxpq5dbkhbl' - '6mgaijdzpq5efw2ynlnjhoeqyh6dakl4yg346gbhabzkcxreu7hc' - 'jhw6vo6wwa7ky2sjdk742khlgsakwtme6sr2dfkhlxxkcqw3jngy' - 'rq5zj7m6m7hnscuzlzsviawnvg47pe7l4hxiexpbb5k456r' +RESPONSES = json.loads( + resource_string( + 'phabricator.tests.resources', + 'responses.json' + ).decode('utf8') ) +CERTIFICATE = resource_string( + 'phabricator.tests.resources', + 'certificate.txt' +).decode('utf8').strip() + # Protect against local user's .arcrc interference. phabricator.ARCRC = {} @@ -52,7 +52,9 @@ def test_generate_hash(self): @mock.patch('phabricator.httplib.HTTPConnection') def test_connect(self, mock_connection): mock_obj = mock_connection.return_value = mock.Mock() - mock_obj.getresponse.return_value = StringIO(RESPONSES['conduit.connect']) + mock_obj.getresponse.return_value = StringIO( + RESPONSES['conduit.connect'] + ) mock_obj.getresponse.return_value.status = 200 api = phabricator.Phabricator( @@ -97,24 +99,34 @@ def test_bad_status(self, mock_connection): with self.assertRaises(phabricator.httplib.HTTPException): api.user.whoami() - @mock.patch('phabricator.httplib.HTTPConnection') def test_maniphest_find(self, mock_connection): mock_obj = mock_connection.return_value = mock.Mock() - mock_obj.getresponse.return_value = StringIO(RESPONSES['maniphest.find']) + mock_obj.getresponse.return_value = StringIO( + RESPONSES['maniphest.find'] + ) mock_obj.getresponse.return_value.status = 200 - api = phabricator.Phabricator(username='test', certificate='test', host='http://localhost') + api = phabricator.Phabricator( + username='test', + certificate='test', + host='http://localhost' + ) api._conduit = True - result = api.maniphest.find(ownerphids=['PHID-USER-5022a9389121884ab9db']) + result = api.maniphest.find( + ownerphids=['PHID-USER-5022a9389121884ab9db'] + ) self.assertEqual(len(result), 1) # Test iteration self.assertIsInstance([x for x in result], list) # Test getattr - self.assertEqual(result['PHID-TASK-4cgpskv6zzys6rp5rvrc']['status'], '3') + self.assertEqual( + result['PHID-TASK-4cgpskv6zzys6rp5rvrc']['status'], + '3' + ) def test_validation(self): self.api._conduit = True diff --git a/setup.py b/setup.py index a60df1f..1e3db6a 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ description='Phabricator API Bindings', packages=find_packages(), zip_safe=False, - test_suite='nose.collector', + test_suite='phabricator.tests.test_phabricator', tests_require=tests_requires, include_package_data=True, classifiers=[