Beispiel #1
0
    def test_getting_data(self):
        robot = Robot("13329.12900.12213", "123", name="HappyBot")
        robot.set_energy(124)
        robot.set_honor(7)
        robot.set_life(3)
        robot.set_has_water(True)

        plant = Plant()
        plant.set_age(64)
        plant.set_water_level(98)

        database = MemcachedDatabase()
        database.add_robot(robot, (6, 11))
        square = database.get_square((5, 11), for_update=True)
        square.set_plant(plant)
        database.commit()

        expected_result = {
            "5,11": {
                "surface_type": MapSquareTypes.SOIL,
                "plant": {
                    "water_level": 98,
                    "matured": True,
                    "age": 64
                },
                "robot": None
            },
            "6,11": {
                "surface_type": MapSquareTypes.SOIL,
                "plant": None,
                "robot": {
                    "name": "HappyBot",
                    "has_water": True,
                    "energy": 124,
                    "life": 3,
                    "honor": 7
                }
            },
            "6,2": {
                "surface_type": MapSquareTypes.ROCK,
                "robot": None,
                "plant": None
            }
        }

        communicator = Communicator()
        result = communicator.execute_command("NhdEr32Qcmp0Iue3", "map_data",
                                              expected_result.keys())

        self.assertCountEqual(result, expected_result)
        for expected_key, expected_value in expected_result.items():
            self.assertDictEqual(result[expected_key], expected_value)
Beispiel #2
0
def handle_request(request):
    try:
        validate_request(request)

        # Communicator is a singleton class.
        communicator = Communicator()

        communicator_result = communicator.execute_command(
            request["password"], request["command"], request["args"])
    except BinarySkyException as error:
        return make_error_response(error)
    except Exception as error:
        # Logging exceptions that are not one of ours.
        Logger().error("System error: {0}\n{1}".format(error,
                                                       traceback.format_exc()))
        return make_error_response(error)

    result = {'status': 200, 'result': communicator_result}

    return result
def handle_request(request):
    try:
        validate_request(request)

        # Communicator is a singleton class.
        communicator = Communicator()

        communicator_result = communicator.execute_command(request["password"],
                                                           request["command"],
                                                           request["args"])
    except BinarySkyException as error:
        return make_error_response(error)
    except Exception as error:
        # Logging exceptions that are not one of ours.
        Logger().error("System error: {0}\n{1}".format(error, traceback.format_exc()))
        return make_error_response(error)

    result = {'status': 200,
              'result': communicator_result}

    return result