@@ -31,53 +31,28 @@ def setUp(self):
31
31
"""
32
32
Set up the test environment by loading real example data for both Android and users.
33
33
"""
34
- # Configure logging for the test
35
- etc .configLogging ()
36
-
37
- # Retrieve a test user UUID from the database
38
- get_example = pd .DataFrame (list (edb .get_uuid_db ().find ({}, {"user_email" :1 , "uuid" : 1 , "_id" : 0 })))
39
- if get_example .empty :
40
- self .fail ("No users found in the database to perform tests." )
41
- test_user_id = get_example .iloc [0 ].uuid
42
- self .testUUID = test_user_id
43
- self .UUID = test_user_id
44
- # Load example entries from a JSON file
45
- with open ("emission/tests/data/real_examples/shankari_2015-aug-27" ) as fp :
46
- self .entries = json .load (fp , object_hook = esj .wrapped_object_hook )
47
-
48
34
# Set up the real example data with entries
49
- etc .setupRealExampleWithEntries (self )
35
+ etc .setupRealExample (self , "emission/tests/data/real_examples/shankari_2015-aug-27" )
50
36
51
37
# Retrieve the user profile
52
- profile = edb .get_profile_db ().find_one ({"user_id" : self .UUID })
38
+ profile = edb .get_profile_db ().find_one ({"user_id" : self .testUUID })
53
39
if profile is None :
54
40
# Initialize the profile if it does not exist
55
- edb .get_profile_db ().insert_one ({"user_id" : self .UUID })
41
+ edb .get_profile_db ().insert_one ({"user_id" : self .testUUID })
56
42
57
- etc .runIntakePipeline (self .UUID )
43
+ etc .runIntakePipeline (self .testUUID )
58
44
59
- logging .debug ("UUID = %s" % (self .UUID ))
45
+ logging .debug ("UUID = %s" % (self .testUUID ))
60
46
61
47
def tearDown (self ):
62
48
"""
63
49
Clean up the test environment by removing analysis configuration and deleting test data from databases.
64
50
"""
65
51
66
- # Delete all time series entries for users
67
- tsdb = edb .get_timeseries_db ()
68
- tsdb .delete_many ({"user_id" : self .UUID })
69
-
70
- # Delete all pipeline state entries for users
71
- pipeline_db = edb .get_pipeline_state_db ()
72
- pipeline_db .delete_many ({"user_id" : self .UUID })
73
-
74
- # Delete all analysis time series entries for users
75
- analysis_ts_db = edb .get_analysis_timeseries_db ()
76
- analysis_ts_db .delete_many ({"user_id" : self .UUID })
77
-
78
- # Delete user profiles
79
- profile_db = edb .get_profile_db ()
80
- profile_db .delete_one ({"user_id" : self .UUID })
52
+ edb .get_timeseries_db ().delete_many ({"user_id" : self .testUUID })
53
+ edb .get_pipeline_state_db ().delete_many ({"user_id" : self .testUUID })
54
+ edb .get_analysis_timeseries_db ().delete_many ({"user_id" : self .testUUID })
55
+ edb .get_profile_db ().delete_one ({"user_id" : self .testUUID })
81
56
82
57
def testGetAndStoreUserStats (self ):
83
58
"""
@@ -86,7 +61,7 @@ def testGetAndStoreUserStats(self):
86
61
"""
87
62
88
63
# Retrieve the updated user profile from the database
89
- profile = edb .get_profile_db ().find_one ({"user_id" : self .UUID })
64
+ profile = edb .get_profile_db ().find_one ({"user_id" : self .testUUID })
90
65
91
66
# Ensure that the profile exists
92
67
self .assertIsNotNone (profile , "User profile should exist after storing stats." )
@@ -120,15 +95,15 @@ def testGetAndStoreUserStats(self):
120
95
121
96
def testLastCall (self ):
122
97
# Call the function with all required arguments
123
- enac . store_server_api_time ( self . UUID , "test_call" , 1440729142.709 , 69 )
124
-
125
- etc .runIntakePipeline (self .UUID )
98
+ test_call_ts = time . time ( )
99
+ enac . store_server_api_time ( self . testUUID , "test_call_ts" , test_call_ts , 69420 )
100
+ etc .runIntakePipeline (self .testUUID )
126
101
127
102
# Retrieve the profile from the database
128
- profile = edb .get_profile_db ().find_one ({"user_id" : self .UUID })
103
+ profile = edb .get_profile_db ().find_one ({"user_id" : self .testUUID })
129
104
130
105
# Verify that last_call_ts is updated correctly
131
- expected_last_call_ts = 1440729142.709
106
+ expected_last_call_ts = test_call_ts
132
107
actual_last_call_ts = profile .get ("last_call_ts" )
133
108
134
109
self .assertEqual (
@@ -138,4 +113,6 @@ def testLastCall(self):
138
113
)
139
114
140
115
if __name__ == '__main__' :
141
- unittest .main ()
116
+ # Configure logging for the test
117
+ etc .configLogging ()
118
+ unittest .main ()
0 commit comments