def test_dummy(self): servicer = DummyServiceServicer() server = server_grpc.start_grpc_server(override_servicer=servicer, verbose=True) sleep(1) # create the gRPC stub channel = grpc.insecure_channel('127.0.0.1:' + str(constants.GRPC_SERVER_PORT)) stub = protobufs_pb2_grpc.GaiaServiceStub(channel) # send message status = dummy_status_message() response = stub.Ping(status) self.assertEqual(response.action, protobufs_pb2.Response.DO_NOTHING) self.assertEqual(response.config.feeding_module_activated, True) self.assertEqual(response.config.watering_module_activated, True) self.assertEqual(response.config.feeding_module_cronstring, "12h *") self.assertEqual(response.config.watering_module_cronstring, "13h 1,3,5") self.assertEqual(response.config.watering_pump_1_duration, 10) self.assertEqual(response.config.watering_pump_2_duration, 20) self.assertEqual(response.config.watering_pump_3_duration, 30) self.assertEqual(response.config.watering_pump_4_duration, 40) server.stop(0)
def test_real_in_memory_valid_auth(self): servicer = server_grpc.GaiaServiceServicer(real_database=False, verbose=True) server = server_grpc.start_grpc_server(override_servicer=servicer, verbose=True) sleep(1) # create the gRPC stub channel = grpc.insecure_channel('127.0.0.1:' + str(constants.GRPC_SERVER_PORT)) stub = protobufs_pb2_grpc.GaiaServiceStub(channel) # send message status = dummy_status_message() status.authentication_token = constants.AUTHENTICATION_TOKEN response = stub.Ping(status) # this should be the default self.assertEqual(response.action, protobufs_pb2.Response.DO_NOTHING) self.assertEqual(response.HasField('config'), False) # send message report = dummy_action_report() report.authentication_token = constants.AUTHENTICATION_TOKEN response = stub.ActionDone(report) # this should be the default self.assertEqual(response.action, protobufs_pb2.Response.DO_NOTHING) self.assertEqual(response.HasField('config'), False) server.stop(0)
def test_real_file_wrong_auth_auth(self): db = database.Database(in_memory=False) db.recreate_database() # add a dummy command to the server config = database_test.dummy_config() db.save_command("REBOOT", config) server = server_grpc.start_grpc_server(verbose=True) sleep(1) # create the gRPC stub channel = grpc.insecure_channel('127.0.0.1:' + str(constants.GRPC_SERVER_PORT)) stub = protobufs_pb2_grpc.GaiaServiceStub(channel) with pytest.raises(Exception): response = stub.Ping(dummy_status_message()) assert response is None with pytest.raises(Exception): response = stub.ActionDone(dummy_action_report()) assert response is None server.stop(0)
def test_real_file_valid_auth(self): db = database.Database(in_memory=False) db.recreate_database() # add a dummy command to the server config = database_test.dummy_config() db.save_command("REBOOT", config) server = server_grpc.start_grpc_server(verbose=True) sleep(1) # create the gRPC stub channel = grpc.insecure_channel('127.0.0.1:' + str(constants.GRPC_SERVER_PORT)) stub = protobufs_pb2_grpc.GaiaServiceStub(channel) # send message status = dummy_status_message() status.authentication_token = constants.AUTHENTICATION_TOKEN response = stub.Ping(status) # this should be the default self.assertEqual(response.action, protobufs_pb2.Response.REBOOT) self.assertEqual(response.HasField('config'), True) self.assertEqual(response.config.feeding_module_activated, config.feeding_module_activated) self.assertEqual(response.config.watering_module_activated, config.feeding_module_activated) self.assertEqual(response.config.feeding_module_cronstring, config.feeding_module_cronstring) self.assertEqual(response.config.watering_module_cronstring, config.watering_module_cronstring) self.assertEqual(response.config.watering_pump_1_duration, config.watering_pump_1_duration) self.assertEqual(response.config.watering_pump_2_duration, config.watering_pump_2_duration) self.assertEqual(response.config.watering_pump_3_duration, config.watering_pump_3_duration) self.assertEqual(response.config.watering_pump_4_duration, config.watering_pump_4_duration) # send message report = dummy_action_report() report.authentication_token = constants.AUTHENTICATION_TOKEN response = stub.ActionDone(report) # this should be the default self.assertEqual(response.action, protobufs_pb2.Response.DO_NOTHING) self.assertEqual(response.HasField('config'), False) server.stop(0)
def test_real_in_memory_wrong_auth(self): servicer = server_grpc.GaiaServiceServicer(real_database=False, verbose=True) server = server_grpc.start_grpc_server(override_servicer=servicer, verbose=True) sleep(1) # create the gRPC stub channel = grpc.insecure_channel('127.0.0.1:' + str(constants.GRPC_SERVER_PORT)) stub = protobufs_pb2_grpc.GaiaServiceStub(channel) # send message with pytest.raises(Exception): response = stub.Ping(dummy_status_message()) assert response is None with pytest.raises(Exception): response = stub.ActionDone(dummy_action_report()) assert response is None server.stop(0)