def test_users(self): """Test if a set of users is returned""" http_requests = setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') _ = client.users("PHID-USER-2uk52xorcqb6sjvp467y", "PHID-USER-bjxhrstz5fb5gkrojmev", "PHID-USER-pr5fcxy4xk5ofqsfqcfc", "PHID-USER-ojtcpympsmwenszuef7p") expected = [{ '__conduit__' : ['True'], 'output' : ['json'], 'params' : { '__conduit__' : {'token': 'aaaa'}, 'phids' : ["PHID-USER-2uk52xorcqb6sjvp467y", "PHID-USER-bjxhrstz5fb5gkrojmev", "PHID-USER-pr5fcxy4xk5ofqsfqcfc", "PHID-USER-ojtcpympsmwenszuef7p"] } }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): rparams = http_requests[i].parsed_body rparams['params'] = json.loads(rparams['params'][0]) self.assertDictEqual(rparams, expected[i])
def test_phids(self): """Test if a set of PHIDs is returned""" http_requests = setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') _ = client.phids("PHID-APPS-PhabricatorHeraldApplication", "PHID-APPS-PhabricatorMockApplication") expected = [{ '__conduit__': ['True'], 'output': ['json'], 'params': { '__conduit__': { 'token': 'aaaa' }, 'phids': [ "PHID-APPS-PhabricatorHeraldApplication", "PHID-APPS-PhabricatorMockApplication" ] } }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): rparams = http_requests[i].parsed_body rparams['params'] = json.loads(rparams['params'][0]) self.assertDictEqual(rparams, expected[i])
def test_transactions(self): """Test if a set of transactions is returned""" http_requests = setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') _ = client.transactions(69, 73, 78) expected = [{ '__conduit__': ['True'], 'output': ['json'], 'params': { '__conduit__': { 'token': 'aaaa' }, 'ids': [69, 73, 78] } }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): rparams = http_requests[i].parsed_body rparams['params'] = json.loads(rparams['params'][0]) self.assertDictEqual(rparams, expected[i])
def test_phabricator_error(self): """Test if an exception is raised when an error is returned by the server""" setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') with self.assertRaises(ConduitError): _ = client._call('error', {})
def test_tasks(self): """Test if a set of tasks is returned""" http_requests = setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') dt = datetime.datetime(2016, 5, 3, 0, 0, 0) result = client.tasks(from_date=dt) result = [r for r in result] self.assertEqual(len(result), 2) expected = [{ '__conduit__': ['True'], 'output': ['json'], 'params': { '__conduit__': { 'token': 'aaaa' }, 'attachments': { 'projects': True }, 'constraints': { 'modifiedStart': 1462233600 }, 'order': 'outdated' } }, { '__conduit__': ['True'], 'output': ['json'], 'params': { '__conduit__': { 'token': 'aaaa' }, 'after': '335', 'attachments': { 'projects': True }, 'constraints': { 'modifiedStart': 1462233600 }, 'order': 'outdated' } }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): rparams = http_requests[i].parsed_body rparams['params'] = json.loads(rparams['params'][0]) self.assertDictEqual(rparams, expected[i])
def test_tasks(self): """Test if a set of tasks is returned""" http_requests = setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') dt = datetime.datetime(2016, 5, 3, 0, 0, 0) result = client.tasks(from_date=dt) result = [r for r in result] self.assertEqual(len(result), 2) expected = [{ '__conduit__' : ['True'], 'output' : ['json'], 'params' : { '__conduit__' : {'token': 'aaaa'}, 'attachments' : {'projects' : True}, 'constraints' : {'modifiedStart' : 1462233600}, 'order' : 'outdated' } }, { '__conduit__' : ['True'], 'output' : ['json'], 'params' : { '__conduit__' : {'token': 'aaaa'}, 'after' : '335', 'attachments' : {'projects' : True}, 'constraints' : {'modifiedStart' : 1462233600}, 'order' : 'outdated' } }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): rparams = http_requests[i].parsed_body rparams['params'] = json.loads(rparams['params'][0]) self.assertDictEqual(rparams, expected[i])
def test_transactions(self): """Test if a set of transactions is returned""" http_requests = setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') _ = client.transactions(69, 73, 78) expected = [{ '__conduit__' : ['True'], 'output' : ['json'], 'params' : { '__conduit__' : {'token': 'aaaa'}, 'ids' : [69, 73, 78] } }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): rparams = http_requests[i].parsed_body rparams['params'] = json.loads(rparams['params'][0]) self.assertDictEqual(rparams, expected[i])
def test_phids(self): """Test if a set of PHIDs is returned""" http_requests = setup_http_server() client = ConduitClient(PHABRICATOR_URL, 'aaaa') _ = client.phids("PHID-APPS-PhabricatorHeraldApplication", "PHID-APPS-PhabricatorMockApplication") expected = [{ '__conduit__' : ['True'], 'output' : ['json'], 'params' : { '__conduit__' : {'token': 'aaaa'}, 'phids' : ["PHID-APPS-PhabricatorHeraldApplication", "PHID-APPS-PhabricatorMockApplication"] } }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): rparams = http_requests[i].parsed_body rparams['params'] = json.loads(rparams['params'][0]) self.assertDictEqual(rparams, expected[i])
def test_init(self): """Test initialization parameters""" client = ConduitClient(PHABRICATOR_URL, 'aaaa') self.assertEqual(client.base_url, PHABRICATOR_URL) self.assertEqual(client.api_token, 'aaaa')