def test_command_tags_removed(self): """Test that the command tags are not left over in bmark object""" COMMANDLIST['!toread'] = CommandMock bm = BmarkMock() bm.tags['!toread'] = True commander = Commander(bm) updated = commander.process() ok_('!toread' not in updated.tags, "Our commander should find !toread command to run")
def test_toread_in_commandset(self): """Make sure we can process this command through the commander""" COMMANDLIST['!toread'] = ToRead bm = BmarkMock() bm.tags['!toread'] = True commander = Commander(bm) updated = commander.process() ok_('toread' in updated.tags, "Should have the toread tag in the updated bookmark") ok_('!toread' not in updated.tags, "Should not have the !toread tag in the updated bookmark")
def bmark_add(request): """Add a new bookmark to the system""" rdict = request.matchdict if 'url' in request.params or 'hash_id' in request.params: params = request.params elif 'url' in request.json_body or 'hash_id' in request.json_body: params = request.json_body else: request.response.status_int = 400 return { 'error': 'Bad Request: missing url', } user = request.user if 'url' not in params and 'hash_id' not in rdict: request.response.status_int = 400 return { 'error': 'Bad Request: missing url', } elif 'hash_id' in rdict: try: mark = BmarkMgr.get_by_hash(rdict['hash_id'], username=user.username) mark = _update_mark(mark, params) except NoResultFound: request.response.status_code = 404 return { 'error': 'Bookmark with hash id {0} not found.'.format( rdict['hash_id']) } else: # check if we already have this try: mark = BmarkMgr.get_by_url(params['url'], username=user.username) mark = _update_mark(mark, params) except NoResultFound: # then let's store this thing # if we have a dt param then set the date to be that manual # date if 'dt' in request.params: # date format by delapi specs: # CCYY-MM-DDThh:mm:ssZ fmt = "%Y-%m-%dT%H:%M:%SZ" stored_time = datetime.strptime(request.params['dt'], fmt) else: stored_time = None # check to see if we know where this is coming from inserted_by = params.get('inserted_by', 'unknown_api') mark = BmarkMgr.store(params['url'], user.username, params.get('description', ''), params.get('extended', ''), params.get('tags', ''), dt=stored_time, inserted_by=inserted_by, ) # we need to process any commands associated as well commander = Commander(mark) mark = commander.process() # if we have content, stick it on the object here if 'content' in params: content = StringIO(params['content']) content.seek(0) parsed = ReadContent.parse(content, content_type="text/html", url=mark.hashed.url) mark.readable = Readable() mark.readable.content = parsed.content mark.readable.content_type = parsed.content_type mark.readable.status_code = parsed.status mark.readable.status_message = parsed.status_message # we need to flush here for new tag ids, etc DBSession.flush() mark_data = dict(mark) mark_data['tags'] = [dict(mark.tags[tag]) for tag in mark.tags.keys()] return { 'bmark': mark_data, 'location': request.route_url('bmark_readable', hash_id=mark.hash_id, username=user.username), }
def bmark_add(request): """Add a new bookmark to the system""" rdict = request.matchdict if 'url' in request.params or 'hash_id' in request.params: params = request.params elif 'url' in request.json_body or 'hash_id' in request.json_body: params = request.json_body else: request.response.status_int = 400 return { 'error': 'Bad Request: missing url', } user = request.user if 'url' not in params and 'hash_id' not in rdict: request.response.status_int = 400 return { 'error': 'Bad Request: missing url', } elif 'hash_id' in rdict: try: mark = BmarkMgr.get_by_hash(rdict['hash_id'], username=user.username) mark = _update_mark(mark, params) except NoResultFound: request.response.status_code = 404 return { 'error': 'Bookmark with hash id {0} not found.'.format(rdict['hash_id']) } else: # check if we already have this try: mark = BmarkMgr.get_by_url(params['url'], username=user.username) mark = _update_mark(mark, params) except NoResultFound: # then let's store this thing # if we have a dt param then set the date to be that manual # date if 'dt' in request.params: # date format by delapi specs: # CCYY-MM-DDThh:mm:ssZ fmt = "%Y-%m-%dT%H:%M:%SZ" stored_time = datetime.strptime(request.params['dt'], fmt) else: stored_time = None # check to see if we know where this is coming from inserted_by = params.get('inserted_by', 'unknown_api') mark = BmarkMgr.store( params['url'], user.username, params.get('description', ''), params.get('extended', ''), params.get('tags', ''), dt=stored_time, inserted_by=inserted_by, ) # we need to process any commands associated as well commander = Commander(mark) mark = commander.process() # if we have content, stick it on the object here if 'content' in params: content = StringIO(params['content']) content.seek(0) parsed = ReadContent.parse(content, content_type="text/html", url=mark.hashed.url) mark.readable = Readable() mark.readable.content = parsed.content mark.readable.content_type = parsed.content_type mark.readable.status_code = parsed.status mark.readable.status_message = parsed.status_message # we need to flush here for new tag ids, etc DBSession.flush() mark_data = dict(mark) mark_data['tags'] = [dict(mark.tags[tag]) for tag in mark.tags.keys()] return { 'bmark': mark_data, 'location': request.route_url('bmark_readable', hash_id=mark.hash_id, username=user.username), }