1010import pytest
1111
1212from flask_monitoringdashboard .core .date_interval import DateInterval
13- from flask_monitoringdashboard .database import session_scope
1413from flask_monitoringdashboard .database .count import count_requests
1514from flask_monitoringdashboard .database .endpoint import get_avg_duration , get_endpoints
1615from flask_monitoringdashboard .database .request import add_request , get_date_of_first_request , get_latencies_sample
@@ -23,25 +22,21 @@ def test_get_latencies_sample(session, request_1, endpoint):
2322 assert data == [request_1 .duration ]
2423
2524
26- def test_add_request (endpoint ):
27- """Test whether the function returns the right values."""
28- # For some reason, using the session-fixture here doesn't work.
25+ def test_add_request (endpoint , session ):
2926 num_requests = len (endpoint .requests )
30- with session_scope () as session :
31- add_request (
32- session ,
33- duration = 200 ,
34- endpoint_id = endpoint .id ,
35- ip = '127.0.0.1' ,
36- group_by = None ,
37- status_code = 200 ,
38- )
39- assert count_requests (session , endpoint .id ) == num_requests + 1
27+ add_request (
28+ session ,
29+ duration = 200 ,
30+ endpoint_id = endpoint .id ,
31+ ip = '127.0.0.1' ,
32+ group_by = None ,
33+ status_code = 200 ,
34+ )
35+ assert count_requests (session , endpoint .id ) == num_requests + 1
4036
4137
4238@pytest .mark .parametrize ('request_1__time_requested' , [datetime (2020 , 2 , 3 )])
4339def test_get_versions (session , request_1 ):
44- """Test whether the function returns the right values."""
4540 for version , first_request in get_versions (session ):
4641 if version == request_1 .version_requested :
4742 assert first_request == request_1 .time_requested
@@ -50,14 +45,12 @@ def test_get_versions(session, request_1):
5045
5146
5247def test_get_endpoints (session , endpoint ):
53- """Test whether the function returns the right values."""
5448 endpoints = get_endpoints (session )
5549 assert endpoint .name in [endpoint .name for endpoint in endpoints ]
5650
5751
5852@pytest .mark .parametrize ('request_1__time_requested' , [datetime (1970 , 1 , 1 )])
5953def test_get_date_of_first_request (session , request_1 ):
60- """Test whether the function returns the right values."""
6154 total_seconds = int (time .mktime (request_1 .time_requested .timetuple ()))
6255 assert get_date_of_first_request (session ) == total_seconds
6356
0 commit comments