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()
def sequence(PKG, input_name): seq_name = get_config_value(PKG, input_name, str) if ''.join(seq_name.split()).lower() == 'none': errors.append( 'Encountered "None" for required sequence {}" '.format(input_name)) return False elif len(''.join(seq_name.split())) > 0: try: sequence_id = app.find_sequence_by_name(name=seq_name) return sequence_id except: input_errors.append( 'Failed to find sequence ID for {}'.format(seq_name)) return None
# Initialise loop indexes, counts and flags xIndex = 0 yIndex = 0 moveCount = 0 canMove = False loopBreaked = False addToZHeightGrid1 = 0 addToZHeightGrid2 = 0 # Get sequence IDs if name given if sequenceAfter1stGridMove == "NULL" : sequenceAfter1stGridMoveId = 0 else : sequenceAfter1stGridMoveId = app.find_sequence_by_name(name=sequenceAfter1stGridMove) if sequenceAfter2ndGridMove == "NULL" : sequenceAfter2ndGridMoveId = 0 else : sequenceAfter2ndGridMoveId = app.find_sequence_by_name(name=sequenceAfter2ndGridMove) # Get the current position for x and y from the config with open(configFileName, 'r') as f: configContents = json.load(f) f.close() savedMoveIndex = int(configContents[evName]) device.log(message='savedMoveIndex: ' + str(savedMoveIndex), message_type='success') # If we are at the start then canMove if savedMoveIndex == 0 :
' Testing running sequences and Farmwares ''' import os import json import requests from farmware_tools import device, app from farmware_tools import get_config_value s_name = get_config_value('Run Sequence', 'sequence_name', str) f_name = get_config_value('Run Sequence', 'farmware_name', str) loops = get_config_value('Run Sequence', 'loop_farmware', int) if len(''.join(s_name.split())) > 0: try: sequence_id = app.find_sequence_by_name(name=s_name) except: device.log("Couldn't find a sequence with name: {}".format(s_name), 'error', ['toast']) else: device.log("No text was entered in sequence input.", 'error', ['toast']) if len(''.join(f_name.split())) > 0: for i in range(loops): device.execute_script(label=f_name) else: device.log("No text was entered in farmware input.", 'error', ['toast']) # device.execute(sequence_id)
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()