Example #1
0
 def test_asr(self):
     config = models.Config.load()
     config.location = "75005"
     config.unit = NabWeatherd.UNIT_CELSIUS
     config.weather_animation_type = "weather"
     config.save()
     service = NabWeatherd()
     writer = MockWriter()
     service.writer = writer
     packet = {
         "type": "asr_event",
         "nlu": {
             "intent": "nabweatherd/forecast"
         }
     }
     async_to_sync(service.process_nabd_packet)(packet)
     self.assertEqual(len(writer.written), 3)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "info")
     self.assertEqual(packet_json["info_id"], "nabweatherd_rain")
     packet = writer.written[1]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "info")
     self.assertEqual(packet_json["info_id"], "nabweatherd")
     self.assertTrue("animation" in packet_json)
     packet = writer.written[2]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertTrue("signature" in packet_json)
     self.assertTrue("body" in packet_json)
Example #2
0
 def test_asr(self):
     config = models.Config.load()
     config.index_airquality = "aqi"
     config.visual_airquality = "always"
     config.localisation = None
     config.save()
     service = NabAirqualityd()
     writer = MockWriter()
     service.writer = writer
     packet = {
         "type": "asr_event",
         "nlu": {
             "intent": "nabairqualityd/forecast"
         },
     }
     async_to_sync(service.process_nabd_packet)(packet)
     self.assertEqual(len(writer.written), 2)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "info")
     self.assertEqual(packet_json["info_id"], "nabairqualityd")
     self.assertTrue("animation" in packet_json)
     packet = writer.written[1]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertTrue("signature" in packet_json)
     self.assertTrue("body" in packet_json)
Example #3
0
 def test_perform_rain(self):
     service = NabWeatherd()
     writer = MockWriter()
     service.writer = writer
     config_t = (
         TestNabWeatherdDB.RENNES_LOCATION_JSON,
         NabWeatherd.UNIT_CELSIUS,
         "rain_only",
         3,
         None,
         False,
     )
     expiration = datetime.datetime(2019, 4, 22, 0, 0, 0)
     async_to_sync(service.perform)(expiration, "today", config_t)
     self.assertEqual(len(writer.written), 3)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "info")
     self.assertEqual(packet_json["info_id"], "nabweatherd_rain")
     packet = writer.written[1]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "info")
     self.assertEqual(packet_json["info_id"], "nabweatherd")
     self.assertFalse("animation" in packet_json)
     packet = writer.written[2]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertTrue("signature" in packet_json)
     self.assertTrue("body" in packet_json)
Example #4
0
 def test_detect_surprise(self):
     service = NabSurprised()
     writer = MockWriter()
     service.writer = writer
     expiration = datetime.datetime(2018, 11, 1, 0, 0, 0)
     nabd_packet = {
         "type": "rfid_event",
         "uid": "d0:02:1a:01:02:03:04:05",
         "event": "detected",
         "support": "formatted",
         "picture": 21,
         "app": "nabsurprised",
         "data": "\x00\x01",
     }
     async_to_sync(service.process_nabd_packet)(nabd_packet)
     self.assertEqual(len(writer.written), 1)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertTrue("signature" in packet_json)
     self.assertTrue("body" in packet_json)
     self.assertEqual(len(packet_json["body"]), 1)
     self.assertTrue("audio" in packet_json["body"][0])
     self.assertEqual(len(packet_json["body"][0]["audio"]), 1)
     self.assertEqual(
         packet_json["body"][0]["audio"][0], "nabsurprised/carrot/*.mp3"
     )
Example #5
0
 def test_perform(self):
     service = Nab8Balld()
     writer = MockWriter()
     service.writer = writer
     async_to_sync(service.perform)()
     self.assertEqual(len(writer.written), 1)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertFalse("signature" in packet_json)
     self.assertTrue("body" in packet_json)
Example #6
0
 def test_perform(self):
     service = NabSurprised()
     writer = MockWriter()
     service.writer = writer
     expiration = datetime.datetime(2018, 11, 1, 0, 0, 0)
     async_to_sync(service.perform)(expiration, None, None)
     self.assertEqual(len(writer.written), 1)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertTrue("signature" in packet_json)
     self.assertTrue("body" in packet_json)
Example #7
0
 def test_perform(self):
     service = NabWeatherd()
     writer = MockWriter()
     service.writer = writer
     config_t = ("75005", NabWeatherd.UNIT_CELSIUS, "rain")
     expiration = datetime.datetime(2019, 4, 22, 0, 0, 0)
     async_to_sync(service.perform)(expiration, "today", config_t)
     self.assertEqual(len(writer.written), 2)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "info")
     self.assertEqual(packet_json["info_id"], "nabweatherd")
     self.assertTrue("animation" in packet_json)
     packet = writer.written[1]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertTrue("signature" in packet_json)
     self.assertTrue("body" in packet_json)
Example #8
0
 def test_perform(self):
     config = models.Config.load()
     config.index_airquality = "aqi"
     config.localisation = None
     config.save()
     service = NabAirqualityd()
     writer = MockWriter()
     service.writer = writer
     config_t = "aqi"
     expiration = datetime.datetime(2019, 4, 22, 0, 0, 0)
     async_to_sync(service.perform)(expiration, "today", config_t)
     self.assertEqual(len(writer.written), 2)
     packet = writer.written[0]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "info")
     self.assertEqual(packet_json["info_id"], "nabairqualityd")
     self.assertTrue("animation" in packet_json)
     packet = writer.written[1]
     packet_json = json.loads(packet.decode("utf8"))
     self.assertEqual(packet_json["type"], "message")
     self.assertTrue("signature" in packet_json)
     self.assertTrue("body" in packet_json)