Skip to content

Commit

Permalink
Use bare asserts over assertion methods
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Dec 6, 2023
1 parent 830d936 commit 8156db6
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions tests/test_sessiontracker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
import logging
import platform

Expand All @@ -20,9 +19,11 @@ def test_session_tracker_adds_session_object_to_queue(self):
tracker = SessionTracker(self.config)
tracker.auto_sessions = True
tracker.start_session()
self.assertEqual(len(tracker.session_counts), 1)

assert len(tracker.session_counts) == 1

for key, value in tracker.session_counts.items():
self.assertEqual(value, 1)
assert value == 1

def test_session_tracker_send_sessions_sends_sessions(self):
client = Client(
Expand All @@ -32,15 +33,19 @@ def test_session_tracker_send_sessions_sends_sessions(self):
asynchronous=False
)
client.session_tracker.start_session()
self.assertEqual(len(client.session_tracker.session_counts), 1)

assert len(client.session_tracker.session_counts) == 1

client.session_tracker.send_sessions()
self.assertEqual(len(client.session_tracker.session_counts), 0)

assert len(client.session_tracker.session_counts) == 0

json_body = self.server.received[0]['json_body']
self.assertTrue('app' in json_body)
self.assertTrue('notifier' in json_body)
self.assertTrue('device' in json_body)
self.assertTrue('sessionCounts' in json_body)
self.assertEqual(len(json_body['sessionCounts']), 1)

assert 'app' in json_body
assert 'notifier' in json_body
assert 'device' in json_body
assert len(json_body['sessionCounts']) == 1

def test_session_tracker_sets_details_from_config(self):
client = Client(
Expand All @@ -49,6 +54,7 @@ def test_session_tracker_sets_details_from_config(self):
session_endpoint=self.server.url,
asynchronous=False
)

client.session_tracker.start_session()
client.session_tracker.send_sessions()
json_body = self.server.received[0]['json_body']
Expand All @@ -58,20 +64,13 @@ def test_session_tracker_sets_details_from_config(self):

# App properties
app = json_body['app']
self.assertTrue('releaseStage' in app)
self.assertEqual(app['releaseStage'],
client.configuration.release_stage)
self.assertTrue('version' in app)
self.assertEqual(app['version'],
client.configuration.app_version)
assert app['releaseStage'] == client.configuration.release_stage
assert app['version'] == client.configuration.app_version

# Device properties
device = json_body['device']
self.assertTrue('hostname' in device)
self.assertEqual(device['hostname'],
client.configuration.hostname)
self.assertTrue('runtimeVersions' in device)
self.assertEqual(device['runtimeVersions']['python'],
platform.python_version())
assert device['hostname'] == client.configuration.hostname
assert device['runtimeVersions']['python'] == platform.python_version()

def test_session_middleware_attaches_session_to_event(self):
client = Client(
Expand All @@ -80,22 +79,21 @@ def test_session_middleware_attaches_session_to_event(self):
endpoint=self.server.url,
asynchronous=False
)

client.session_tracker.start_session()
client.notify(Exception("Test"))
while len(self.server.received) == 0:
time.sleep(0.5)

assert len(self.server.received) == 1

json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertTrue('session' in event)
session = event['session']
self.assertTrue('id' in session)
self.assertTrue('startedAt' in session)
self.assertTrue('events' in session)
sesevents = session['events']
self.assertTrue('unhandled' in sesevents)
self.assertEqual(sesevents['unhandled'], 0)
self.assertTrue('handled' in sesevents)
self.assertEqual(sesevents['handled'], 1)
session = json_body['events'][0]['session']

assert 'id' in session
assert 'startedAt' in session
assert session['events'] == {
'unhandled': 0,
'handled': 1,
}

def test_session_tracker_does_not_send_when_nothing_to_send(self):
logger = Mock(logging.Logger)
Expand Down

0 comments on commit 8156db6

Please sign in to comment.