def test_it_seeks_to_movie_time(self, schedule_run_mock, entangled: Entangled, plex_api_mock: PlexApi): entangled._on_play_cmd({ 'type': 'play', 'movieTime': '1:23:45', 'playAt': 1602516359362, }) plex_api_mock.seek_to.assert_called_once_with(1, 23, 45)
def test_it_schedules_a_play_call_at_correct_time(self, schedule_run_mock, entangled: Entangled, plex_api_mock: PlexApi): play_at_datetime = datetime.fromisoformat('2020-11-27T13:45:23') play_at_timestamp_ms = 1606484723000 entangled._on_play_cmd({ 'type': 'play', 'movieTime': '1:23:45', 'playAt': play_at_timestamp_ms, }) schedule_run_mock.assert_called_once_with(play_at_datetime, plex_api_mock.play)
def initialize_deps(): if env == 'prod': plex_api = PythonLibPlexApi() else: plex_api = MockPlexApi() app.config['PLEX_API'] = plex_api app.config['ENTANGLED'] = Entangled(plex_api) if env == 'prod' or env == 'e2e_tests': app.config['ENTANGLED'].connect_to_mqtt() if env == 'e2e_tests': # TODO: Find a better way to do this. Maybe by injecting the env in entangled and letting it decide of which delay to pick # TODO: But before that, transform the env into an enum start_delay_for_e2e_tests = seconds(30) config['entangled']['start_delay'] = start_delay_for_e2e_tests
def test_sends_mqtt_message(self, entangled: Entangled, mqtt_client_mock): entangled.send_play_cmd() mqtt_client_mock.send_message.assert_called_once()
def test_listens_for_play_message(self, entangled: Entangled, mqtt_client_mock): entangled.connect_to_mqtt() mqtt_client_mock.listen_for_message.assert_called_once_with( entangled._on_play_cmd, type='play')
def test_registers_disconnect_hook_on_connect(self, atexit_register, entangled: Entangled, mqtt_client_mock): entangled.connect_to_mqtt() atexit_register.assert_called_once_with(mqtt_client_mock.destroy)
def test_connects_to_mqtt_on_connect(self, entangled: Entangled, mqtt_client_mock): entangled.connect_to_mqtt() mqtt_client_mock.connect.assert_called_once()
def entangled(mqtt_client_mock, plex_api_mock): return Entangled(plex_api_mock)