Skip to content

Commit 3ef0517

Browse files
committed
Updated Based on requested changes
1 parent 179594b commit 3ef0517

File tree

1 file changed

+18
-41
lines changed

1 file changed

+18
-41
lines changed

emission/tests/analysisTests/intakeTests/TestUserStat.py

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,53 +31,28 @@ def setUp(self):
3131
"""
3232
Set up the test environment by loading real example data for both Android and users.
3333
"""
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-
4834
# 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")
5036

5137
# 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})
5339
if profile is None:
5440
# 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})
5642

57-
etc.runIntakePipeline(self.UUID)
43+
etc.runIntakePipeline(self.testUUID)
5844

59-
logging.debug("UUID = %s" % (self.UUID))
45+
logging.debug("UUID = %s" % (self.testUUID))
6046

6147
def tearDown(self):
6248
"""
6349
Clean up the test environment by removing analysis configuration and deleting test data from databases.
6450
"""
6551

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})
8156

8257
def testGetAndStoreUserStats(self):
8358
"""
@@ -86,7 +61,7 @@ def testGetAndStoreUserStats(self):
8661
"""
8762

8863
# 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})
9065

9166
# Ensure that the profile exists
9267
self.assertIsNotNone(profile, "User profile should exist after storing stats.")
@@ -120,15 +95,15 @@ def testGetAndStoreUserStats(self):
12095

12196
def testLastCall(self):
12297
# 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)
126101

127102
# 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})
129104

130105
# Verify that last_call_ts is updated correctly
131-
expected_last_call_ts = 1440729142.709
106+
expected_last_call_ts = test_call_ts
132107
actual_last_call_ts = profile.get("last_call_ts")
133108

134109
self.assertEqual(
@@ -138,4 +113,6 @@ def testLastCall(self):
138113
)
139114

140115
if __name__ == '__main__':
141-
unittest.main()
116+
# Configure logging for the test
117+
etc.configLogging()
118+
unittest.main()

0 commit comments

Comments
 (0)