# Path: doorman/manage/forms.py
# class CreateQueryForm(QueryForm):
# 
#     def validate(self):
#         from doorman.models import Query
#         initial_validation = super(CreateQueryForm, self).validate()
#         if not initial_validation:
#             return False
# 
#         query = Query.query.filter(Query.name == self.name.data).first()
#         if query:
#             self.name.errors.append(
#                 u"Query with the name {0} already exists!".format(
#                 self.name.data)
#             )
#             return False
# 
#         # TODO could do some validation of the sql query
#         return True
# 
# class UpdateQueryForm(QueryForm):
# 
#     def __init__(self, *args, **kwargs):
#         super(UpdateQueryForm, self).__init__(*args, **kwargs)
#         self.set_choices()
#         query = kwargs.pop('obj', None)
#         if query:
#             self.packs.process_data([p.name for p in query.packs])
#             self.tags.process_data('\n'.join(t.value for t in query.tags))
# 
# class UploadPackForm(Form):
# 
#     pack = FileField(u'Pack configuration', validators=[FileRequired()])
# 
# class CreateTagForm(Form):
#     value = TextAreaField('Tag', validators=[DataRequired()])
# 
# Path: tests/factories.py
# class QueryFactory(BaseFactory):
# 
#     class Meta:
#         model = Query


from doorman.manage.forms import (
    CreateQueryForm,
    UpdateQueryForm,
    UploadPackForm,
    CreateTagForm,
)
from .factories import QueryFactory
# -*- coding: utf-8 -*-




class TestCreateTagForm:

    def test_tag_validate_failure(self, testapp):
        form = CreateTagForm()
        assert form.validate() is False

    def test_tag_validate_success(self, testapp):

# Path: doorman/manage/forms.py
# class CreateQueryForm(QueryForm):
# 
#     def validate(self):
#         from doorman.models import Query
#         initial_validation = super(CreateQueryForm, self).validate()
#         if not initial_validation:
#             return False
# 
#         query = Query.query.filter(Query.name == self.name.data).first()
#         if query:
#             self.name.errors.append(
#                 u"Query with the name {0} already exists!".format(
#                 self.name.data)
#             )
#             return False
# 
#         # TODO could do some validation of the sql query
#         return True
# 
# class UpdateQueryForm(QueryForm):
# 
#     def __init__(self, *args, **kwargs):
#         super(UpdateQueryForm, self).__init__(*args, **kwargs)
#         self.set_choices()
#         query = kwargs.pop('obj', None)
#         if query:
#             self.packs.process_data([p.name for p in query.packs])
#             self.tags.process_data('\n'.join(t.value for t in query.tags))
# 
# class UploadPackForm(Form):
# 
#     pack = FileField(u'Pack configuration', validators=[FileRequired()])
# 
# class CreateTagForm(Form):
#     value = TextAreaField('Tag', validators=[DataRequired()])
# 
# Path: tests/factories.py
# class QueryFactory(BaseFactory):
# 
#     class Meta:
#         model = Query


# Path: tests/test_forms.py
from doorman.manage.forms import (
    CreateQueryForm,
    UpdateQueryForm,
    UploadPackForm,
    CreateTagForm,
)
from .factories import QueryFactory

# -*- coding: utf-8 -*-




class TestCreateTagForm:

    def test_tag_validate_failure(self, testapp):
        form = CreateTagForm()
        assert form.validate() is False

    def test_tag_validate_success(self, testapp):

        form = CreateTagForm(value='foo')