def test_parse_tags_with_empty_tags(self): taglist = ['tag1', '', '', 'tag2'] tags = Tag.parse_tags(' '.join(taglist)) self.assertIs(len(tags),2) for tagname in taglist: if tagname == '': continue self.assertIn(Tag.get_tag(tagname),tags)
def test_parse_tags_with_empty_tags(self): taglist = ['tag1', '', '', 'tag2'] tags = Tag.parse_tags(' '.join(taglist)) self.assertIs(len(tags), 2) for tagname in taglist: if tagname == '': continue self.assertIn(Tag.get_tag(tagname), tags)
def init_show(user): """Initializes a show it either takes a planned show or an unplanned show if it's still running if non of them is found a new unplanned show is added and initialized if a new show was initialized the old one will be ended and the streamer status will be resetted """ show = Show.get_current_show(user) if show is None: show = Show() if user.get_setting(code='use_icy'): show.add_tags( Tag.parse_tags(user.get_setting(code='icy_show_genre') or '')) show.description = user.get_setting( code='icy_show_description') or '' show.name = user.get_setting(code='icy_show_name') or '' else: show.add_tags( Tag.parse_tags(user.get_setting(code='show_def_tags') or '')) show.description = user.get_setting(code='show_def_desc') or '' show.name = user.get_setting(code='show_def_name') or '' show.logo = user.get_setting(code='show_def_logo') or None show.flags = Show.FLAGS.UNPLANNED show.add_user(user) elif show.flags == Show.FLAGS.UNPLANNED: # just check if there is a planned show to transition to s = Show.get_current_show(user, only_planned=True) if s is not None: show = s us = show.get_usershow(user) us.status = UserShow.STATUS.STREAMING rfk.database.session.commit() unfinished_shows = UserShow.query.filter( UserShow.status == UserShow.STATUS.STREAMING, UserShow.show != show).all() for us in unfinished_shows: if us.show.flags & Show.FLAGS.UNPLANNED: us.show.end_show() if us.status == UserShow.STATUS.STREAMING: us.status = UserShow.STATUS.STREAMED rfk.database.session.commit() return show
def init_show(user): """inititalizes a show it either takes a planned show or an unplanned show if it's still running if non of them is found a new unplanned show is added and initialized if a new show was initialized the old one will be ended and the streamer staus will be resettet """ logger.info("init_show: entering") logger.info("init_show: user {}".format(str(user))) show = Show.get_current_show(user) if show is None: logger.info("init_show: None") show = Show() if user.get_setting(code='use_icy'): show.add_tags(Tag.parse_tags(user.get_setting(code='icy_show_genre') or '')) show.description = user.get_setting(code='icy_show_description') or '' show.name = user.get_setting(code='icy_show_name') or '' else: show.add_tags(Tag.parse_tags(user.get_setting(code='show_def_tags') or '')) show.description = user.get_setting(code='show_def_desc') or '' show.name = user.get_setting(code='show_def_name') or '' show.flags = Show.FLAGS.UNPLANNED show.add_user(user) elif show.flags == Show.FLAGS.UNPLANNED: logger.info("init_show: UNPLANNED") #just check if there is a planned show to transition to s = Show.get_current_show(user, only_planned=True) if s is not None: logger.info("init_show: found planned") show = s us = show.get_usershow(user) us.status = UserShow.STATUS.STREAMING rfk.database.session.flush() unfinished_shows = UserShow.query.filter(UserShow.status == UserShow.STATUS.STREAMING, UserShow.show != show).all() for us in unfinished_shows: if us.show.flags & Show.FLAGS.UNPLANNED: us.show.end_show() if us.status == UserShow.STATUS.STREAMING: us.status = UserShow.STATUS.STREAMED rfk.database.session.flush() return show
def _set_show_info(show, form): show.name = form.get('title') show.description = form.get('description') #series if 'series' in form and \ len(form['series']) and \ int(form['series']) > 0: series = Series.query.get(int(form['series'])) if series and (series.public == True or series.user == current_user): show.series = series else: show.series = None #tags if 'tags[]' in form: tags_str = ' '.join(form.getlist('tags[]')) else: tags_str = '' tags = Tag.parse_tags(tags_str) show.sync_tags(tags) #logo if 'logo' in form and \ len(form['logo']) > 0: show.logo = form['logo']
def test_parse_tags_with_empty_string(self): tags = Tag.parse_tags('') self.assertIs(len(tags), 0)
def test_parse_tags_with_dupplicate(self): taglist = ['tag1', 'tag2', 'tag3', 'tag1'] tags = Tag.parse_tags(' '.join(taglist)) self.assertIs(len(tags), 3) for tagname in taglist: self.assertIn(Tag.get_tag(tagname), tags)
def test_parse_tags(self): taglist = ['tag1', 'tag2', 'tag3', 'tag4'] tags = Tag.parse_tags(' '.join(taglist)) self.assertIs(len(tags), 4) for tagname in taglist: self.assertIn(Tag.get_tag(tagname), tags)
def test_tag_entry(self): tag_ref = Tag.get_tag('tag2') tag_ref2 = Tag.get_tag('tag3') self.assertIsNot(tag_ref, tag_ref2)
def test_tag_dupplicate(self): tag_ref = Tag.get_tag('tag') tag_ref2 = Tag.get_tag('tag') self.assertIs(tag_ref, tag_ref2)
def test_parse_tags_with_empty_string(self): tags = Tag.parse_tags('') self.assertIs(len(tags),0)
def test_parse_tags_with_dupplicate(self): taglist = ['tag1', 'tag2', 'tag3', 'tag1'] tags = Tag.parse_tags(' '.join(taglist)) self.assertIs(len(tags),3) for tagname in taglist: self.assertIn(Tag.get_tag(tagname),tags)
def test_parse_tags(self): taglist = ['tag1', 'tag2', 'tag3', 'tag4'] tags = Tag.parse_tags(' '.join(taglist)) self.assertIs(len(tags),4) for tagname in taglist: self.assertIn(Tag.get_tag(tagname),tags)