Skip to content

Commit

Permalink
Tests fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
popovaan committed Jan 13, 2025
1 parent 32cbd3d commit 7f4b616
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/backend/backend_ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def generate_new_cid_file(self):
def cid_file_initialized(self):
return self.cid is not None

def set_stats(self, data: dict):
pass


def is_valid_cid(cid: str):
try:
Expand Down
3 changes: 2 additions & 1 deletion src/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def make_message(self, client_id, app_name, app_version, category, action, label
'event_count': value,
'session_id': session_id,
'app_name': app_name,
'app_version': app_version}
'app_version': app_version,
'usage_count': 1}
}
]}

Expand Down
26 changes: 13 additions & 13 deletions src/utils/stats_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,36 @@ def test_stats_usage(self):

# Test first creation of statistics file
self.stats_processor.update_stats(test_data1)
assert os.path.exists(stats_filename)
self.assertTrue(os.path.exists(stats_filename))
with open(stats_filename, 'r') as file:
assert file.readlines() == ['{\n', ' "value1": 12,\n', ' "value2": 7,\n', ' "value3": 8\n', '}']
self.assertTrue(file.readlines() == ['{\n', ' "value1": 12,\n', ' "value2": 7,\n', ' "value3": 8\n', '}'])

status, res = self.stats_processor.get_stats()
assert status
assert res == test_data1
self.assertTrue(status)
self.assertTrue(res == test_data1)

# Test updating of statistics file
test_data2 = {"value1": 15, "a": "abs"}
self.stats_processor.update_stats(test_data2)
assert os.path.exists(stats_filename)
self.assertTrue(os.path.exists(stats_filename))
with open(stats_filename, 'r') as file:
assert file.readlines() == ['{\n', ' "value1": 15,\n', ' "a": "abs"\n', '}']
self.assertTrue(file.readlines() == ['{\n', ' "value1": 15,\n', ' "a": "abs"\n', '}'])

status, res = self.stats_processor.get_stats()
assert status
assert res == test_data2
self.assertTrue(status)
self.assertTrue(res == test_data2)

# Test removing of statistics file
self.stats_processor.remove_stats_file()
assert not os.path.exists(stats_filename)
self.assertFalse(os.path.exists(stats_filename))

status, res = self.stats_processor.get_stats()
assert not status
assert res == {}
self.assertFalse(status)
self.assertTrue(res == {})

# Test attempt to read incorrect statistics file
with open(stats_filename, 'w') as file:
file.write("{ abc")
status, res = self.stats_processor.get_stats()
assert not status
assert res == {}
self.assertFalse(status)
self.assertTrue(res == {})

0 comments on commit 7f4b616

Please sign in to comment.