Esempio n. 1
0
 def test_submit_None_for_algorithm(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         sr.submit(algorithm=None)
         self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertEqual('Algorithm is empty string or None', str(ce))
Esempio n. 2
0
 def test_wait_for_task_to_complete_none_for_taskid(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         sr.wait_for_task_to_complete(None)
         self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertEqual('Task id is empty string or None', str(ce))
Esempio n. 3
0
    def test_wait_for_task_to_complete_consecutive_error_exceeded(self):
        sr = ServiceRunner(service_endpoint='http://foo')

        with requests_mock.Mocker() as m:
            m.get('http://foo/taskid/status',
                  [{
                      'status_code': 500
                  }, {
                      'status_code': 200,
                      'json': {
                          'foo': None
                      }
                  }, {
                      'status_code': 200,
                      'json': {
                          'progress': 50
                      }
                  }, {
                      'status_code': 500
                  }, {
                      'status_code': 410
                  }, {
                      'exc': requests.exceptions.HTTPError('error')
                  }])
            try:
                sr.wait_for_task_to_complete('taskid',
                                             poll_interval=0,
                                             consecutive_fail_retry=2)
                self.fail('Expected CommunityDetectionError')
            except CommunityDetectionError as ce:
                self.assertEqual('Received 3 consecutive errors', str(ce))
Esempio n. 4
0
 def test_get_algorithms_no_json(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         with requests_mock.Mocker() as m:
             m.get('http://foo/algorithms', status_code=200)
             sr.get_algorithms()
             self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertTrue('Error result not in JSON format : ' in str(ce))
Esempio n. 5
0
    def test_get_algorithms_success(self):
        sr = ServiceRunner(service_endpoint='http://foo')

        with requests_mock.Mocker() as m:
            m.get('http://foo/algorithms',
                  status_code=200,
                  json={'hi': 'there'})
            res = sr.get_algorithms()
            self.assertEqual({'hi': 'there'}, res)
Esempio n. 6
0
    def test_wait_for_task_to_complete_immediately_done(self):
        sr = ServiceRunner(service_endpoint='http://foo')

        with requests_mock.Mocker() as m:
            m.get('http://foo/taskid/status',
                  status_code=200,
                  json={'progress': 100})
            res = sr.wait_for_task_to_complete('taskid', poll_interval=0)
            self.assertEqual({'progress': 100}, res)
Esempio n. 7
0
 def test_submit_nojson(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         with requests_mock.Mocker() as m:
             m.post('http://foo', status_code=202)
             sr.submit(algorithm='myalgo', data={'hi': 'there'})
             self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertTrue('Unable to parse result from submit: '
                         'Expecting' in str(ce))
Esempio n. 8
0
 def test_get_result_error_html_code_no_json_or_text(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     with requests_mock.Mocker() as m:
         m.get('http://foo/taskid', status_code=500)
         try:
             sr.get_result('taskid')
             self.fail('Expected CommunityDetectionError')
         except CommunityDetectionError as ce:
             self.assertEqual('Received 500 HTTP response status code : ',
                              str(ce))
Esempio n. 9
0
 def test_get_algorithms_server_error(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         with requests_mock.Mocker() as m:
             m.get('http://foo/algorithms', status_code=500, text='error')
             sr.get_algorithms()
             self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertEqual('Received 500 HTTP response status code : error',
                          str(ce))
Esempio n. 10
0
 def test_submit_raises_invalidstatuscode(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         with requests_mock.Mocker() as m:
             m.post('http://foo', status_code=500)
             sr.submit(algorithm='myalgo', data={'hi': 'there'})
             self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertEqual(
             'Received unexpected HTTP response status code: '
             '500 from request: ', str(ce))
Esempio n. 11
0
 def test_get_algorithms_http_error(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         with requests_mock.Mocker() as m:
             m.get('http://foo/algorithms',
                   exc=requests.exceptions.HTTPError('anerror'))
             sr.get_algorithms()
             self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertEqual(
             'Received HTTPError getting '
             'algorithms : anerror', str(ce))
Esempio n. 12
0
 def test_submit_raises_httperror(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     try:
         with requests_mock.Mocker() as m:
             m.post('http://foo',
                    exc=requests.exceptions.HTTPError('some error'))
             sr.submit(algorithm='myalgo', data={'hi': 'there'})
             self.fail('Expected CommunityDetectionError')
     except CommunityDetectionError as ce:
         self.assertEqual(
             'Received HTTPError submitting myalgo with '
             'parameters None : some error', str(ce))
Esempio n. 13
0
    def __init__(self, runner=ServiceRunner()):
        """
        Constructor. See class description for usage

        """
        if runner is None:
            raise CommunityDetectionError('runner is None')
        self._runner = runner
Esempio n. 14
0
    def test_wait_for_task_to_complete_retry_count_exceeded(self):
        sr = ServiceRunner(service_endpoint='http://foo')

        with requests_mock.Mocker() as m:
            m.get('http://foo/taskid/status',
                  [{
                      'status_code': 500
                  }, {
                      'status_code': 200,
                      'json': {
                          'foo': None
                      }
                  }, {
                      'exc': requests.exceptions.HTTPError('error')
                  }])
            try:
                sr.wait_for_task_to_complete('taskid',
                                             poll_interval=0,
                                             max_retries=3)
                self.fail('Expected CommunityDetectionError')
            except CommunityDetectionError as ce:
                self.assertEqual('Max retry count 3 exceeded', str(ce))
Esempio n. 15
0
 def test_submit_success(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     with requests_mock.Mocker() as m:
         m.post('http://foo', status_code=202, json={'id': 'taskid'})
         res = sr.submit(algorithm='myalgo', data={'hi': 'there'})
         self.assertEqual({'id': 'taskid'}, res)
Esempio n. 16
0
 def test_get_result_success(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     with requests_mock.Mocker() as m:
         m.get('http://foo/taskid', status_code=200, json={'progress': 100})
         res = sr.get_result('taskid')
         self.assertEqual({'progress': 100}, res)
Esempio n. 17
0
 def test_get_user_agent_header(self):
     sr = ServiceRunner(service_endpoint='http://foo')
     self.assertEqual(
         {'UserAgent': 'cdapsutil/' + str(cdapsutil.__version__)},
         sr._get_user_agent_header())
Esempio n. 18
0
 def test_get_algorithm_name(self):
     sr = ServiceRunner()
     self.assertEqual('', sr.get_algorithm_name())
Esempio n. 19
0
 def test_get_docker_image(self):
     sr = ServiceRunner()
     self.assertEqual('', sr.get_docker_image())