def get(self, uid): ''' The uid of the file_object in question has to be given in the url The return format will be {"binary": b64_encoded_binary, "file_name": file_name} ''' with ConnectTo(FrontEndDbInterface, self.config) as db_service: existence = db_service.existence_quick_check(uid) if not existence: return error_message( 'No firmware with UID {} found in database'.format(uid), self.URL, request_data={'uid': uid}, return_code=404) try: tar_flag = get_tar_flag(request.args) except ValueError as value_error: return error_message(str(value_error), self.URL, request_data=dict( uid=uid, tar=request.args.get('tar'))) with ConnectTo(InterComFrontEndBinding, self.config) as intercom: if not tar_flag: binary, file_name = intercom.get_binary_and_filename(uid) else: binary, file_name = intercom.get_repacked_binary_and_file_name( uid) response = { 'binary': standard_b64encode(binary).decode(), 'file_name': file_name, 'SHA256': get_sha256(binary) } return success_message(response, self.URL, request_data={ 'uid': uid, 'tar': tar_flag })
def test_get_tar_flag_raises(parameter): with pytest.raises(ValueError): get_tar_flag(dict(tar=parameter))
def test_get_tar_flag_success(): assert get_tar_flag(dict()) is False assert get_tar_flag(dict(tar='false')) is False assert get_tar_flag(dict(tar='true')) is True