Beispiel #1
0
 def upload_point(self, point, name, id_list):
     """Upload a point to the FarmBot Web App."""
     payload = self.prepare_point_data(point, name)
     if USE_FARMWARE_TOOLS:
         app.post('points', payload)
         return
     # API Request
     api = self._api_info('app')
     response = requests.post(api['url'] + 'points',
                              json=payload,
                              headers=api['headers'])
     point_id = None
     if response.status_code == 200:
         point_id = response.json()['id']
         id_list.append(point_id)
     self.api_response_error_collector(response)
     return id_list
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()
Beispiel #3
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)
Beispiel #4
0
    def add_plant(self, x: float, y: float, **kwargs) -> Plant:
        """Add a plant to the garden map.

        Args:
            x (int): X Coordinate.
            y (int): Y Coordinate.
            **kwargs: name, openfarm_slug, radius, z, planted_at, plant_stage
        """
        payload = {
            'pointer_type': 'Plant',
            'x': x,
            'y': y
        }
        for key, value in kwargs.items():
            if value is not None:
                payload[key] = value
        return deserialize(Plant, app.post('points', payload))
Beispiel #5
0
 def _get_points(self):
     points = app.post("points/search", payload={"pointer_type": "Plant"})
     return points if type(points) is list else FakePlants.get_fake_plants()
def run_tests(TEST, app_login):
    'Run device tests.'
    COORDINATE = device.assemble_coordinate(1, 0, 1)
    OFFSET = device.assemble_coordinate(0, 0, 0)
    URL = 'https://raw.githubusercontent.com/FarmBot-Labs/farmware_manifests/' \
        'master/packages/take-photo/manifest.json'
    app.post('sequences', {'name': 'test', 'body': []}, get_info=app_login)
    SEQUENCE = app.find_sequence_by_name(name='test', get_info=app_login)
    TESTS = [
        {'command': device.log, 'kwargs': {'message': 'hi'}},
        {'command': device.log,
         'kwargs': {'message': 'hi', 'channels': ['toast']}},
        {'command': device.log,
         'kwargs': {'message': 'hi', 'rpc_id': 'abcd'}},
        {'command': device.check_updates,
         'kwargs': {'package': 'farmbot_os'}},
        {'command': device.emergency_lock, 'kwargs': {},
         'expected': {'status': [{
             'keys': ['informational_settings', 'locked'],
             'value': True}]}},
        {'command': device.emergency_unlock, 'kwargs': {},
         'expected': {'log': ['F09'], 'status': [{
             'keys': ['informational_settings', 'locked'],
             'value': False}]}},
        {'command': device.execute, 'kwargs': {'sequence_id': SEQUENCE}},
        {'command': device.execute_script,
         'kwargs': {
             'label': 'take-photo',
             'inputs': {'input_1': 1, 'take_photo_input_2': 'two'}}},
        {'command': device.run_farmware, 'kwargs': {'label': 'take-photo'}},
        {'command': device.find_home, 'kwargs': {'axis': 'y'},
         'expected': {'log': ['F12']}},
        {'command': device.home, 'kwargs': {'axis': 'z'},
         'expected': {'log': ['G00 Z0']}},
        {'command': device.install_farmware, 'kwargs': {'url': URL}},
        {'command': device.install_first_party_farmware, 'kwargs': {}},
        {'command': device.move_absolute,
         'kwargs': {'location': COORDINATE, 'speed': 100, 'offset': OFFSET},
         'expected': {'log': ['G00 X1.0 Y0.0 Z1.0']}},
        {'command': device.move_relative,
         'kwargs': {'x': -1, 'y': 0, 'z': -1, 'speed': 100},
         'expected': {'log': ['G00 X0.0 Y0.0 Z0.0']}},
        {'command': device.read_pin,
         'kwargs': {'pin_number': 1, 'label': 'label', 'pin_mode': 0},
         'expected': {'log': ['F42 P1 M0']}},
        {'command': device.read_status, 'kwargs': {}},
        {'command': device.remove_farmware,
         'kwargs': {'package': 'farmware'}},
        {'command': device.set_pin_io_mode,
         'kwargs': {'pin_io_mode': 0, 'pin_number': 47},
         'expected': {'log': ['F43 P47 M0']}},
        {'command': device.set_servo_angle,
         'kwargs': {'pin_number': 4, 'pin_value': 1},
         'expected': {'log': ['F61 P4 V1']}},
        {'command': device.set_user_env,
         'kwargs': {'key': 'test_key', 'value': 1}},
        {'command': device.sync, 'kwargs': {},
         'expected': {'status': [{
             'keys': ['informational_settings', 'sync_status'],
             'value': 'synced'}]}},
        {'command': device.take_photo, 'kwargs': {}},
        {'command': device.toggle_pin, 'kwargs': {'pin_number': 1},
         'expected': {'log': ['F41 P1 V']}},
        {'command': device.update_farmware,
         'kwargs': {'package': 'take-photo'}},
        {'command': device.wait, 'kwargs': {'milliseconds': 100}},
        {'command': device.write_pin,
         'kwargs': {'pin_number': 1, 'pin_value': 1, 'pin_mode': 0},
         'expected': {'log': ['F41 P1 V1 M0'], 'status': [{
             'keys': ['pins', '1', 'value'],
             'value': 1}]}},
        {'command': device.zero, 'kwargs': {'axis': 'y'},
         'expected': {'log': ['F84 Y1'], 'status': [
             {'keys': ['location_data', 'position', 'y'], 'value': 0},
             {'keys': ['location_data', 'scaled_encoders', 'y'], 'value': 0}
             ]}},
    ]
    TEST.setup()
    for test in TESTS:
        try:
            _rpc_id = test['kwargs'].pop('rpc_id')
        except KeyError:
            _rpc_id = None
        print()
        time.sleep(3)
        TEST.test(test['command'](**test['kwargs'])['command'],
                  rpc_id=_rpc_id, expected=test.get('expected'))
    print('=' * 20)
    TEST.print_elapsed_time()
    print()
    TEST.teardown()
    TEST.print_summary()