def test_get_hash_stats_returns_updated_stats_4020(self):
        url = self.base_url + ':' + self.port + '/' + 'stats'
        response = get_hash_stats(url)
        self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
        # validate reponse against the json schema
        jsonschema.validate(response.json(), self.stats_schema)
        job_count, avgTime = response.json()['TotalRequests'], response.json(
        )['AverageTime']

        for i in range(3):
            password = gen_password()
            post_url = self.base_url + ':' + self.port + '/' + 'hash'
            payload = {'password': password}
            post_hash(post_url, self.headers, payload)

        time.sleep(5)
        response = get_hash_stats(url)
        self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
        # validate reponse against the json schema
        jsonschema.validate(response.json(), self.stats_schema)
        new_job_count, avgTime = response.json(
        )['TotalRequests'], response.json()['AverageTime']
        self.assertEqual(new_job_count, job_count + 3,
                         'Invalid TotalRequests Returned')
        self.assertTrue(avgTime > 0,
                        'BUG: Invalid AverageTime Returned in Stats')
Пример #2
0
    def test_new_post_rejected_during_pending_shutdown_6040(self):
        self._restart_app()
        url = self.base_url + ':' + self.port + '/' + 'hash'
        payload = {'password': '******'}
        for i in range(5):
            response = post_hash(url, self.headers, payload, 1)
        payload = 'shutdown'
        response = post_shutdown(url, None, payload)
        # verify it shuts down gracefully when there are in-flight hashing
        self.assertEqual(response.status_code, codes.OK,
                         'Bug: INVALID Status Code')

        # Verify new post hash is not accepted when shutdown is in progress
        url = self.base_url + ':' + self.port + '/' + 'hash'
        payload = {'password': '******'}
        response = post_hash(url, self.headers, payload, 1)
        print(response.text)
        self.assertEqual(response.status_code, codes.SERVICE_UNAVAILABLE,
                         'INVALID Status Code')
        self.assertEqual(response.text.strip(), 'Service Unavailable',
                         'Invalid Error Message')

        # verify stats reflects in-flight hashing before shutdown
        time.sleep(3)
        url = self.base_url + ':' + self.port + '/' + 'stats'
        response = get_hash_stats(url)
        job_count, avgTime = response.json()['TotalRequests'], response.json(
        )['AverageTime']
        self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
        self.assertTrue(job_count >= 4, 'Invalid TotalRequests')
 def test_post_stats_not_supported_5050(self):
     url = self.base_url + ':' + self.port + '/' + 'stats'
     # Get current stats
     response = get_hash_stats(url)
     self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
     job_count1, avgTime1 = response.json()['TotalRequests'], response.json(
     )['AverageTime']
     payload = {"TotalRequests": 999999999, "AverageTime": 100000000}
     # verify post stats is not supported
     response = post_hash_stats(url, self.headers, payload)
     self.assertEqual(response.status_code, codes.NOT_ALLOWED,
                      'INVALID Status Code')
     # verify stats are not changed
     response = get_hash_stats(url)
     self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
     job_count2, avgTime2 = response.json()['TotalRequests'], response.json(
     )['AverageTime']
Пример #4
0
    def test_post_shutdown_response_no_active_hashing_6000_6020(self):
        # make sure app is up
        url = self.base_url + ':' + self.port + '/' + 'stats'
        response = get_hash_stats(url)
        self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
        # shutdown app
        url = self.base_url + ':' + self.port + '/' + 'hash'
        payload = 'shutdown'
        response = post_shutdown(url, None, payload)

        # verify the app is down
        time.sleep(1)
        url = self.base_url + ':' + self.port + '/' + 'stats'
        response = get_hash_stats(url)
        self.assertIn(
            'No connection could be made because the target machine actively refused it',
            str(response), 'App might Not be down')
 def test_get_hash_stats_returns_properly_when_no_job_exists_4000(self):
     url = self.base_url + ':' + self.port + '/' + 'stats'
     response = get_hash_stats(url)
     self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
     # validate reponse against the json schema
     jsonschema.validate(response.json(), self.stats_schema)
     self.assertEqual(response.json()['TotalRequests'], 0,
                      'Invalid Initial Value for TotalRequests')
     self.assertEqual(response.json()['AverageTime'], 0,
                      'Invalid Initial Value for AverageTime')
 def test_get_hash_stats_returns_properly_4010(self):
     url = self.base_url + ':' + self.port + '/' + 'stats'
     response = get_hash_stats(url)
     self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
     # validate reponse against the json schema
     jsonschema.validate(response.json(), self.stats_schema)
     job_count, avgTime = response.json()['TotalRequests'], response.json(
     )['AverageTime']
     if job_count > 0:
         self.assertTrue(avgTime > 0,
                         'Invalid AverageTime Returned in Stats')
Пример #7
0
 def test_get_hash_with_non_existing_job_id_3060(self):
     url = self.base_url + ':' + self.port + '/' + 'stats'
     response = get_hash_stats(url)
     if response.status_code == codes.OK:
         current_jobs = json.loads(response.text)['TotalRequests']
         print(current_jobs)
         url = self.base_url + ':' + self.port + '/' + 'hash'
         response = get_hash_by_id(url, current_jobs + 1000)
         self.assertEqual(response.status_code, codes.BAD_REQUEST,
                          'INVALID Status Code')
         self.assertEqual(response.text.strip(), 'Hash not found',
                          'Invalid Error Message')
     else:
         self.fail('Failed to Get Hash Stats')
Пример #8
0
    def test_post_shutdown_stops_app_gracefully_6010_6030(self):
        self._restart_app()
        url = self.base_url + ':' + self.port + '/' + 'hash'
        payload = {'password': '******'}
        for i in range(5):
            response = post_hash(url, self.headers, payload, 1)
        payload = 'shutdown'
        response = post_shutdown(url, None, payload)
        # verify it shuts down gracefully when there are in-flight hashing
        self.assertEqual(response.status_code, codes.OK,
                         'Bug: INVALID Status Code')

        # verify stats reflects in-flight hashing before shutdown
        time.sleep(3)
        url = self.base_url + ':' + self.port + '/' + 'stats'
        response = get_hash_stats(url)
        job_count, avgTime = response.json()['TotalRequests'], response.json(
        )['AverageTime']
        self.assertEqual(response.status_code, codes.OK, 'INVALID Status Code')
        self.assertTrue(job_count >= 4, 'Invalid TotalRequests')