def test_should_create_one_tag_with_same_text(self): tag_name = "tag name" tag1 = Tag(text=tag_name) tag1.save() tags_with_name = Tag.query.filter_by(text=tag_name).all() self.assertEqual(len(tags_with_name), 1) tag2 = Tag.create_unique(tag_name) tags_with_name = Tag.query.filter_by(text=tag_name).all() self.assertEqual(len(tags_with_name), 1) self.assertEqual(tag2, tag1)
def upload(): """ Отвечает за вывод страницы загрузки и загрузку файлов :return: Страница загрузки """ form = UploadVideoForm() if form.validate_on_submit(): file = request.files['video'] video = save_video(file, form.title.data) if not video: form.video.errors.append( ValidationError('Ошибка при загрузке видео')) return render_template('upload_video.html', form=form, user=cur_user(), formats=app.config['ALLOWED_EXTENSIONS']) data = JSONDecoder().decode(form.geotag_data.data) if data['needed']: for coords in data['coords']: geo_tag = Geotag(*coords) video.geotags.append(geo_tag) if form.tags.data: tags = form.tags.data.split(',') for tag_name in tags: video_tag = Tag.create_unique(text=tag_name) video.tags.append(video_tag) db.session.commit() return redirect(url_for("main")) if not form.geotag_data.data: form.geotag_data.data = dumps({'needed': False, 'coords': []}) return render_template('upload_video.html', form=form, user=cur_user(), formats=app.config['ALLOWED_EXTENSIONS'])