예제 #1
0
    def _request(self, url_path, query_params, json, expected_codes,
                 json_response):
        # Construct the URL using url_path, query_params and the api key
        url = url_path
        if FLAGS.api_key:
            if query_params:
                url = '%s?key=%s&%s' % (url_path, FLAGS.api_key, query_params)
            else:
                url = '%s?key=%s' % (url_path, FLAGS.api_key)
        elif query_params:
            url = '%s?%s' % (url_path, query_params)

        # Prepare headers
        headers = {'Content-Type': 'application/json'}
        if FLAGS.auth_token:
            headers['Authorization'] = 'Bearer ' + FLAGS.auth_token

        self._conn.request('POST', url, json, headers)
        response = esp_utils.Response(self._conn.getresponse())

        # Make sure that the response status code is in 200s, 300s or 400s
        # and that the response payload is valid JSON
        if not response.status_code in expected_codes:
            print esp_utils.red('Invalid status code %d: url=%s, json=%s' %
                                (response.status_code, url, json))
            self._unexpected_errors += 1
        elif json_response and not response.is_json():
            print esp_utils.red('Response is not json: url=%s, json=%s' %
                                (url, json))
            self._unexpected_errors += 1

        self._total_requests += 1
예제 #2
0
 def run_all_tests(self):
     for i in range(FLAGS.runs):
         self._run_fuzz_tests()
     if self._unexpected_errors > 0:
         sys.exit(esp_utils.red('Fuzz test failed.'))
     else:
         print esp_utils.green('Fuzz test passed.')
예제 #3
0
 def _get_status(self):
     self._status_conn.request('GET', '/endpoints_status')
     response = esp_utils.Response(self._status_conn.getresponse())
     status = response.json()
     if len(status['processes']) == 0:
         sys.exit(esp_utils.red('Cloud not get ESP status'))
     return status
예제 #4
0
    def run_all_tests(self):

        self.verify_key_restriction();

        if self._failed_tests:
            sys.exit(esp_utils.red('%d tests passed, %d tests failed.' % (
                self._passed_tests, self._failed_tests)))
        else:
            print esp_utils.green('All %d tests passed' % self._passed_tests)
예제 #5
0
    def run_all_tests(self):

        self.verify_quota_control()

        if self._failed_tests:
            sys.exit(esp_utils.red('%d tests passed, %d tests failed.' % (
                self._passed_tests, self._failed_tests)))
        else:
            print esp_utils.green('All %d tests passed' % self._passed_tests)
예제 #6
0
    def run_all_tests(self):
        self.clear()
        self.verify_list_shelves([])

        shelf1 = {'name': 'shelves/100', 'theme': 'Text books'}
        shelf1 = self.create_shelf(shelf1)
        self.verify_list_shelves([shelf1])

        shelf2 = {'name': 'shelves/200', 'theme': 'Fiction'}
        shelf2 = self.create_shelf(shelf2)
        self.verify_list_shelves([shelf1, shelf2])

        self.verify_shelf(shelf1)
        self.verify_shelf(shelf2)

        book11 = {
            'name': 'books/1000',
            'author': 'Graham Doggett',
            'title': 'Maths for Chemist'
        }
        book11 = self.create_book(shelf1['name'], book11)
        self.verify_list_books(shelf1['name'], [book11])

        book12 = {
            'name': 'books/2000',
            'author': 'George C. Comstock',
            'title': 'A Text-Book of Astronomy'
        }
        book12 = self.create_book(shelf1['name'], book12)
        self.verify_list_books(shelf1['name'], [book11, book12])

        self.verify_book(book11)
        self.verify_book(book12)

        # shelf2 is empty
        self.verify_list_books(shelf2['name'], [])

        self.delete_book(book12['name'])
        self.verify_list_books(shelf1['name'], [book11])

        self.delete_book(book11['name'])
        self.verify_list_books(shelf1['name'], [])

        self.delete_shelf(shelf2['name'])
        self.delete_shelf(shelf1['name'])
        self.verify_list_shelves([])
        if self._failed_tests:
            sys.exit(
                esp_utils.red('%d tests passed, %d tests failed.' %
                              (self._passed_tests, self._failed_tests)))
        else:
            print esp_utils.green('All %d tests passed' % self._passed_tests)
예제 #7
0
 def _check_for_crash(self):
     print "Checking for crashes..."
     current_status = self._get_status()
     initial_processes = self._initial_status['processes']
     current_processes = current_status['processes']
     if len(initial_processes) != len(current_processes):
         sys.exit(
             esp_utils.red(
                 'ESP crashed. Initial & current process numbers do not match.'
             ))
         return
     for i in range(len(initial_processes)):
         if initial_processes[i]['processId'] != current_processes[i][
                 'processId']:
             sys.exit(
                 esp_utils.red(
                     'ESP crashed. Initial & current pids do not match.'))
         if initial_processes[i]['startedAt'] != current_processes[i][
                 'startedAt']:
             sys.exit(
                 esp_utils.red(
                     'ESP crashed. Initial & current start times do not match.'
                 ))
     print esp_utils.green('No crashes detected.')
예제 #8
0
                        testcase['status_code'])

    def run_all_tests(self):

        self.verify_key_restriction();

        if self._failed_tests:
            sys.exit(esp_utils.red('%d tests passed, %d tests failed.' % (
                self._passed_tests, self._failed_tests)))
        else:
            print esp_utils.green('All %d tests passed' % self._passed_tests)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--verbose', type=bool, help='Turn on/off verbosity.')
    parser.add_argument('--host', help='Deployed application host name.')
    parser.add_argument('--allow_unverified_cert', type=bool,
            default=False, help='used for testing self-signed ssl cert.')
    parser.add_argument('--key_restriction_tests',
                        help='Test suites for api key restriction.')
    parser.add_argument('--key_restriction_keys_file',
                        help='File contains API keys with restrictions ')
    flags = parser.parse_args(namespace=FLAGS)

    esp_test = EspBookstoreTest()
    try:
        esp_test.run_all_tests()
    except KeyError as e:
        sys.exit(esp_utils.red('Test failed.'))
예제 #9
0
 def fail(self, msg):
     print '%s: %s' % (esp_utils.red('FAILED'), msg if msg else '')
     self._failed_tests += 1