11'''This module contains the test cases for the opensense module.'''
22import sys
33import re
4+ import os
45import requests
6+ import vcr
7+
8+ API_HOST = os .environ .get ('API_HOST' , 'http://127.0.0.1:5000' )
9+
10+ my_vcr = vcr .VCR (
11+ cassette_library_dir = 'fixtures/vcr_cassettes' ,
12+ record_mode = 'once' ,
13+ match_on = ['uri' , 'method' ],
14+ )
515
616def make_request (url , expected_pattern ):
717 '''Reusable function to make requests and assert responses.'''
@@ -25,9 +35,10 @@ def make_request(url, expected_pattern):
2535 print (f"❌ TEST FAILED: { str (e )} " )
2636 return False , None
2737
38+ @my_vcr .use_cassette ('version.yaml' )
2839def test_get_version ():
2940 '''Function to test the get_version function from the opensense module.'''
30- url = "http://127.0.0.1:5000 /version"
41+ url = f" { API_HOST } /version"
3142 pattern = r"Current app version: (\d+\.\d+\.\d+)"
3243 version_success , match = make_request (url , pattern )
3344
@@ -37,9 +48,10 @@ def test_get_version():
3748
3849 return version_success
3950
51+ @my_vcr .use_cassette ('temperature.yaml' )
4052def test_get_temperature ():
4153 '''Function to test the get_temperature function from the opensense module.'''
42- url = "http://127.0.0.1:5000 /temperature"
54+ url = f" { API_HOST } /temperature"
4355 pattern = r"Average temperature: (\d+\.\d+) °C"
4456 temperature_success , match = make_request (url , pattern )
4557
0 commit comments