/ components / paddock / telemetry / tests / test_debug_app.py
test_debug_app.py
 1  from pprint import pprint  # noqa
 2  
 3  from django.test import TransactionTestCase
 4  
 5  from telemetry.models import Coach, Driver
 6  from telemetry.pitcrew.coach_app import CoachApp
 7  from telemetry.pitcrew.history import History
 8  
 9  from .utils import get_session_df, read_responses, save_responses  # noqa
10  
11  
12  class TestDebugApp(TransactionTestCase):
13      fixtures = [
14          "game.json",
15          "track.json",
16          "car.json",
17          "session.json",
18          "sessiontype.json",
19          "lap.json",
20          "fastlap.json",
21          "fastlapsegment.json",
22          "driver.json",
23          "coach.json",
24          "trackguide.json",
25          "trackguidenote.json",
26          "landmark.json",
27      ]
28      maxDiff = None
29  
30      do_save_responses = False
31  
32      def test_debug(self):
33          # iRacing / Mazda MX-5 Cup / okayama short
34  
35          session_id = "1694266648"
36          driver = Driver.objects.get(name="durandom")
37          coach = driver.coach
38          coach.mode = Coach.MODE_DEBUG_APP
39          coach.save()
40  
41          history = History()
42  
43          coach = CoachApp(history, coach)
44  
45          session_df = get_session_df(session_id, measurement="laps_cc", bucket="racing")
46  
47          row = session_df.iloc[0].to_dict()
48          topic = row["topic"].replace("Jim", "durandom")
49          coach.notify(topic, row)
50          history.init()
51          history._do_init = False
52  
53          captured_responses = []
54          try:
55              for index, row in session_df.iterrows():
56                  row = row.to_dict()
57                  response = coach.notify(topic, row, row["_time"])
58                  if response:
59                      captured_responses.append(response)
60          except Exception as e:
61              raise e
62          finally:
63              print("stopping history thread")
64              history.disconnect()
65  
66          responses_file = "test_debug_app"
67          expected_responses = read_responses(responses_file)
68          if self.do_save_responses:
69              save_responses(captured_responses, responses_file)
70  
71          # pprint(captured_responses, width=200)
72          self.assertEqual(captured_responses, expected_responses)