def delete(name='', clear_all=False, batch=False): """ :param name: :type name: unicode :param clear_all: :type clear_all: bool :param batch: :type batch: bool :return: """ # action delete # just delete subscribed bangumi or clear all the subscribed bangumi result = {} if clear_all: if Followed.delete_followed(batch=batch): result['status'] = "warning" result['message'] = 'all subscriptions have been deleted' else: print_error('user canceled') elif name: followed = Followed(bangumi_name=name) if followed.select(): followed.delete() result['status'] = 'warning' result['message'] = 'Bangumi {} has been deleted'.format(name) else: result['status'] = 'error' result['message'] = 'Bangumi %s does not exist' % name else: result['status'] = 'warning' result['message'] = 'Nothing has been done.' return result
def delete(ret): # action delete # just delete subscribed bangumi or clear all the subscribed bangumi if ret.action.delete.clear_all: if Followed.delete_followed(batch=ret.action.delete.batch): print_success('all subscriptions have been deleted') else: print_error('user canceled') elif ret.action.delete.name: for name in ret.action.delete.name: followed = Followed(bangumi_name=name) if followed.select(): followed.delete() print_warning('Bangumi %s has been deleted' % name) else: print_error('Bangumi %s does not exist' % name, exit_=False) else: print_warning('Nothing has been done.')
def test_add_and_remove_followed(self): f = Followed(bangumi_name='test_add_and_remove_followed', status=STATUS_FOLLOWED, episode=6) f.save() b = Bangumi(name='test_add_and_remove_followed') b.save() bangumi_data = b.select( one=True, join='LEFT JOIN %s ON %s.bangumi_name=%s.name' % (Followed.table, Followed.table, Bangumi.table)) self.assertEqual(bangumi_data['status'], STATUS_FOLLOWED) f.delete() bangumi_data = b.select( one=True, join='LEFT JOIN %s ON %s.bangumi_name=%s.name' % (Followed.table, Followed.table, Bangumi.table)) self.assertEqual(bangumi_data['status'], STATUS_NORMAL)