def test_urls(self): test_result = TestResult() test_result.add_hit(**self._get_data()) test_result.add_hit(**self._get_data(url='http://another-one')) urls = set(['http://notmyidea.org', 'http://another-one']) self.assertEquals(test_result.urls, urls)
def test_nb_hits(self): test_result = TestResult() test_result.add_hit(**self._get_data()) test_result.add_hit(**self._get_data()) test_result.add_hit(**self._get_data()) self.assertEquals(test_result.nb_hits, 3) self.assertEquals(len(test_result.hits), 3)
def test_hits_success_rate(self): test_result = TestResult() for x in range(4): test_result.add_hit(**self._get_data(status=200)) test_result.add_hit(**self._get_data(status=400, series=2)) self.assertEquals(test_result.hits_success_rate(), 0.8) self.assertEquals(test_result.hits_success_rate(series=1), 1)
def test_requests_per_second(self): test_result = TestResult() for x in range(20): test_result.add_hit(**self._get_data(status=200)) test_result.start_time = TIME1 test_result.stop_time = TIME2 self.assertTrue(0.16 < test_result.requests_per_second() < 0.17)
def test_get_url_metrics(self): test_result = TestResult() test_result.average_request_time = Mock(return_value=0.5) test_result.hits_success_rate = Mock(return_value=0.9) test_result.add_hit(**self._get_data('http://notmyidea.org')) test_result.add_hit(**self._get_data('http://lolnet.org')) metrics = test_result.get_url_metrics() self.assertEquals(metrics['http://notmyidea.org'], { 'average_request_time': 0.5, 'hits_success_rate': 0.9}) self.assertEquals(metrics['http://lolnet.org'], { 'average_request_time': 0.5, 'hits_success_rate': 0.9})
def test_get_url_metrics(self): test_result = TestResult() test_result.average_request_time = Mock(return_value=0.5) test_result.hits_success_rate = Mock(return_value=0.9) test_result.add_hit(**self._get_data('http://notmyidea.org')) test_result.add_hit(**self._get_data('http://lolnet.org')) metrics = test_result.get_url_metrics() self.assertEquals(metrics['http://notmyidea.org'], { 'average_request_time': 0.5, 'hits_success_rate': 0.9 }) self.assertEquals(metrics['http://lolnet.org'], { 'average_request_time': 0.5, 'hits_success_rate': 0.9 })
def test_average_request_time_without_filter(self): test_result = TestResult() test_result.add_hit(**self._get_data(elapsed=_1)) test_result.add_hit(**self._get_data(elapsed=_3)) test_result.add_hit(**self._get_data(elapsed=_2)) test_result.add_hit(**self._get_data(url='http://another-one', elapsed=_3)) self.assertEquals(test_result.average_request_time(), 2.25)
def test_average_request_time_without_filter(self): test_result = TestResult() test_result.add_hit(**self._get_data(elapsed=_1)) test_result.add_hit(**self._get_data(elapsed=_3)) test_result.add_hit(**self._get_data(elapsed=_2)) test_result.add_hit( **self._get_data(url='http://another-one', elapsed=_3)) self.assertEquals(test_result.average_request_time(), 2.25)
def test_average_request_time_with_url_filtering(self): test_result = TestResult() test_result.add_hit(**self._get_data(elapsed=_1)) test_result.add_hit(**self._get_data(elapsed=_3)) test_result.add_hit(**self._get_data(elapsed=_2)) test_result.add_hit(**self._get_data(url='http://another-one', elapsed=_3)) # We want to filter out some URLs avg = test_result.average_request_time('http://notmyidea.org') self.assertEquals(avg, 2.0) avg = test_result.average_request_time('http://another-one') self.assertEquals(avg, 3.0)
def test_average_request_time_with_url_filtering(self): test_result = TestResult() test_result.add_hit(**self._get_data(elapsed=_1)) test_result.add_hit(**self._get_data(elapsed=_3)) test_result.add_hit(**self._get_data(elapsed=_2)) test_result.add_hit( **self._get_data(url='http://another-one', elapsed=_3)) # We want to filter out some URLs avg = test_result.average_request_time('http://notmyidea.org') self.assertEquals(avg, 2.0) avg = test_result.average_request_time('http://another-one') self.assertEquals(avg, 3.0)
def test_average_request_time_with_series_filtering(self): test_result = TestResult() test_result.add_hit(**self._get_data(elapsed=_1, series=1)) test_result.add_hit(**self._get_data(elapsed=_3, series=2)) test_result.add_hit(**self._get_data(elapsed=_2, series=3)) test_result.add_hit(**self._get_data(elapsed=_3, series=3)) avg = test_result.average_request_time(series=3) self.assertEquals(avg, 2.5) # try adding another filter on the URL test_result.add_hit(**self._get_data(elapsed=_3, series=3, url='http://another-one')) avg = test_result.average_request_time(series=3, url='http://notmyidea.org') self.assertEquals(avg, 2.5) self.assertEquals(test_result.average_request_time(series=3), 2.6666666666666665)
def test_average_request_time_with_series_filtering(self): test_result = TestResult() test_result.add_hit(**self._get_data(elapsed=_1, series=1)) test_result.add_hit(**self._get_data(elapsed=_3, series=2)) test_result.add_hit(**self._get_data(elapsed=_2, series=3)) test_result.add_hit(**self._get_data(elapsed=_3, series=3)) avg = test_result.average_request_time(series=3) self.assertEquals(avg, 2.5) # try adding another filter on the URL test_result.add_hit( **self._get_data(elapsed=_3, series=3, url='http://another-one')) avg = test_result.average_request_time(series=3, url='http://notmyidea.org') self.assertEquals(avg, 2.5) self.assertEquals(test_result.average_request_time(series=3), 2.6666666666666665)