def teardown(self):
     'Post-test config.'
     print('-' * 50)
     print('TEST TEARDOWN:')
     app.put('fbos_config',
             payload={LOG_FW_CMD_CONFIG_KEY: False},
             get_info=app_login)
     self.wait_for_log(LOG_FW_CMD_CONFIG_KEY, count_time=False)
     print('-' * 50)
Exemplo n.º 2
0
    def save_plant(save_point):
        """ Execute the PUT points/{id} API call.

        Arguments:
            point {dict} -- Celeryscript Point JSON object to update

        Raises:
            e -- exception
        """
        try:
            if len(save_point) < 2:
                log("Nothing to save: {}".format(save_point),
                    title="save_plant")
                return

            if Logger.LOGGER_LEVEL < 3:
                if "meta" in save_point:
                    # to avoid replacing older point meta data, we load it and merge it
                    log(
                        "Loading plant data from API for ID: {}".format(
                            save_point["id"]),
                        title="save_plant",
                    )
                    plant_data_from_api = app.get("points/{}".format(
                        save_point["id"]))

                    if "meta" in plant_data_from_api:
                        # see https://stackoverflow.com/a/26853961
                        save_point["meta"] = {
                            **plant_data_from_api["meta"],
                            **save_point["meta"],
                        }

                log("Saving Point: {}".format(save_point), title="save_plant")

                endpoint = "points/{}".format(save_point["id"])
                app.put(endpoint, payload=save_point)
            else:
                log(
                    "FAKE Saving Point (debug level = 3): {}".format(
                        save_point),
                    title="save_plant",
                )

        except Exception as e:
            log("Exception thrown: {}".format(e), "error", title="save_plant")
            raise e
 def setup(self):
     'Pre-test config.'
     print('-' * 50)
     print('TEST SETUP:')
     fw_out_log_opt = app.get_property('fbos_config',
                                       LOG_FW_CMD_CONFIG_KEY,
                                       get_info=app_login)
     if fw_out_log_opt:
         print('{}`{}`{} option already enabled.'.format(
             COLOR.bold, LOG_FW_CMD_CONFIG_KEY, COLOR.reset))
     else:
         app.put('fbos_config',
                 payload={LOG_FW_CMD_CONFIG_KEY: True},
                 get_info=app_login)
         self.wait_for_log(LOG_FW_CMD_CONFIG_KEY, count_time=False)
     send(device.sync()['command'], self.login_info)
     print('-' * 50)
Exemplo n.º 4
0
 def put_point(self, point: TPoint) -> TPoint:
     """
     Store an existing or new point
     """
     device.log(f"Sending point {json.dumps(point)}", 'debug')
     if self.debug:
         return point
     result = app.put('points', point.id, point) if point.id is not None else app.post('points', cast(Any, point))
     return deserialize(Point, result)
Exemplo n.º 5
0
def run_tests(app_login):
    'Run app tests.'
    TIMESTAMP = str(int(time.time()))
    print(app.log('hi', get_info=app_login))
    print(app.request('GET', 'tools', get_info=app_login))
    print(app.get('sensors', get_info=app_login))
    TOOL = app.post('tools',
                    payload={'name': 'test_tool_' + TIMESTAMP},
                    get_info=app_login)
    print(TOOL)
    TOOL_ID = TOOL['id']
    print(
        app.put('tools',
                TOOL_ID,
                payload={'name': 'test_tool_edit_' + TIMESTAMP},
                get_info=app_login))
    print(app.delete('tools', TOOL_ID, get_info=app_login))
    print(app.search_points({'pointer_type': 'Plant'}, get_info=app_login))
    print(app.get_points(get_info=app_login))
    print(app.get_plants(get_info=app_login))
    print(app.get_toolslots(get_info=app_login))
    print(app.get_property('device', 'name', get_info=app_login))
    print(app.download_plants(get_info=app_login))
    PLANT = app.add_plant(x=100, y=100, get_info=app_login)
    print(PLANT)
    PLANT_ID = PLANT['id']
    print(app.delete('points', PLANT_ID, get_info=app_login))
    PLANT2 = app.add_plant(x=10,
                           y=20,
                           z=30,
                           radius=10,
                           openfarm_slug='mint',
                           name='test',
                           get_info=app_login)
    print(PLANT2)
    print(app.delete('points', PLANT2['id'], get_info=app_login))
    app.post('sequences', {'name': 'test', 'body': []}, get_info=app_login)
    app.post('sequences', {
        'name': u'test \u2713',
        'body': []
    },
             get_info=app_login)
    print(app.find_sequence_by_name(name=u'test \u2713', get_info=app_login))
    print(app.find_sequence_by_name(name='test', get_info=app_login))
    print()