# Path: mass_flask_core/models/sample.py
# class IPSample(Sample):
#     ip_address = StringField(required=True)
# 
#     @property
#     def title(self):
#         return self.ip_address
# 
#     def _initialize(self, **kwargs):
#         self.ip_address = kwargs['ip_address']
#         self.tags.append('sample-type:ipsample')
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         if 'ip_address' not in kwargs:
#             raise ValidationError('Parameter ip_address is missing')
#         else:
#             try:
#                 sample = cls.objects.get(ip_address=kwargs['ip_address'])
#             except DoesNotExist:
#                 sample = IPSample()
#                 sample._initialize(**kwargs)
# 
#             sample._update(**kwargs)
#             sample.save()
#             return sample
# 
# class URISample(Sample):
#     uri = StringField(required=True)
# 
#     @property
#     def title(self):
#         return self.uri
# 
#     def _initialize(self, **kwargs):
#         self.uri = kwargs['uri']
#         self.tags.append('sample-type:urisample')
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         if 'uri' not in kwargs:
#             raise ValidationError('Parameter uri is missing')
#         else:
#             try:
#                 sample = cls.objects.get(uri=kwargs['uri'])
#             except DoesNotExist:
#                 sample = URISample()
#                 sample._initialize(**kwargs)
# 
#             sample._update(**kwargs)
#             sample.save()
#             return sample
# 
# Path: mass_flask_core/models/analysis_system.py
# class AnalysisSystem(db.Document):
#     identifier_name = StringField(min_length=3, max_length=50, unique=True, required=True)
#     verbose_name = StringField(max_length=200, required=True)
#     information_text = StringField()
#     tag_filter_expression = StringField(max_length=400, required=True, default='')
# 
#     meta = {
#         'ordering': ['identifier_name'],
#         'indexes': ['identifier_name']
#     }
# 
#     def __repr__(self):
#         return '[AnalysisSystem] {}'.format(self.identifier_name)
# 
#     def __str__(self):
#         return self.__repr__()
# 
# Path: mass_flask_core/models/analysis_request.py
# class AnalysisRequest(db.Document):
#     analysis_system = ReferenceField(AnalysisSystem, required=True)
#     sample = ReferenceField(Sample, required=True)
#     analysis_requested = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     priority = IntField(default=0, required=True)
# 
#     meta = {
#         'ordering': ['-analysis_requested'],
#         'indexes': ['analysis_requested']
#     }
# 
#     def __repr__(self):
#         return '[AnalysisRequest] {} on {}'.format(self.sample.id, self.analysis_system.identifier_name)
# 
#     def __str__(self):
#         return self.__repr__()
# 
# Path: mass_flask_core/tests/flask_test_case.py
# class FlaskTestCase(TestCase):
#     @staticmethod
#     def _clean_test_database():
#         conn = connection.get_connection()
#         db = connection.get_db()
#         conn.drop_database(db)
# 
#     def __call__(self, result=None):
#         self._pre_setup()
#         super(FlaskTestCase, self).__call__(result)
#         self._post_tearDown()
# 
#     def _pre_setup(self):
#         bootstrap_mass_flask()
#         if not 'MASS_TESTING' in app.config or app.config['MASS_TESTING'] is False:
#             raise RuntimeError('Running unit test without TESTING=True in configuration. Aborting.')
#         self.app = app
#         self.client = app.test_client()
#         self._ctx = self.app.test_request_context()
#         self._ctx.push()
# 
#     def _post_tearDown(self):
#         self._ctx.pop()
#         self._clean_test_database()


from mixer.backend.mongoengine import mixer
from mongoengine import DoesNotExist
from mass_flask_core.models import AnalysisSystem, AnalysisRequest, IPSample, URISample
from mass_flask_core.tests import FlaskTestCase



class RequestDispatchTestCase(FlaskTestCase):
    def test_are_requests_correct_after_sample_creation(self):
        system = mixer.blend(AnalysisSystem, tag_filter_expression='sample-type:ipsample')

# Path: mass_flask_core/models/sample.py
# class IPSample(Sample):
#     ip_address = StringField(required=True)
# 
#     @property
#     def title(self):
#         return self.ip_address
# 
#     def _initialize(self, **kwargs):
#         self.ip_address = kwargs['ip_address']
#         self.tags.append('sample-type:ipsample')
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         if 'ip_address' not in kwargs:
#             raise ValidationError('Parameter ip_address is missing')
#         else:
#             try:
#                 sample = cls.objects.get(ip_address=kwargs['ip_address'])
#             except DoesNotExist:
#                 sample = IPSample()
#                 sample._initialize(**kwargs)
# 
#             sample._update(**kwargs)
#             sample.save()
#             return sample
# 
# class URISample(Sample):
#     uri = StringField(required=True)
# 
#     @property
#     def title(self):
#         return self.uri
# 
#     def _initialize(self, **kwargs):
#         self.uri = kwargs['uri']
#         self.tags.append('sample-type:urisample')
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         if 'uri' not in kwargs:
#             raise ValidationError('Parameter uri is missing')
#         else:
#             try:
#                 sample = cls.objects.get(uri=kwargs['uri'])
#             except DoesNotExist:
#                 sample = URISample()
#                 sample._initialize(**kwargs)
# 
#             sample._update(**kwargs)
#             sample.save()
#             return sample
# 
# Path: mass_flask_core/models/analysis_system.py
# class AnalysisSystem(db.Document):
#     identifier_name = StringField(min_length=3, max_length=50, unique=True, required=True)
#     verbose_name = StringField(max_length=200, required=True)
#     information_text = StringField()
#     tag_filter_expression = StringField(max_length=400, required=True, default='')
# 
#     meta = {
#         'ordering': ['identifier_name'],
#         'indexes': ['identifier_name']
#     }
# 
#     def __repr__(self):
#         return '[AnalysisSystem] {}'.format(self.identifier_name)
# 
#     def __str__(self):
#         return self.__repr__()
# 
# Path: mass_flask_core/models/analysis_request.py
# class AnalysisRequest(db.Document):
#     analysis_system = ReferenceField(AnalysisSystem, required=True)
#     sample = ReferenceField(Sample, required=True)
#     analysis_requested = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     priority = IntField(default=0, required=True)
# 
#     meta = {
#         'ordering': ['-analysis_requested'],
#         'indexes': ['analysis_requested']
#     }
# 
#     def __repr__(self):
#         return '[AnalysisRequest] {} on {}'.format(self.sample.id, self.analysis_system.identifier_name)
# 
#     def __str__(self):
#         return self.__repr__()
# 
# Path: mass_flask_core/tests/flask_test_case.py
# class FlaskTestCase(TestCase):
#     @staticmethod
#     def _clean_test_database():
#         conn = connection.get_connection()
#         db = connection.get_db()
#         conn.drop_database(db)
# 
#     def __call__(self, result=None):
#         self._pre_setup()
#         super(FlaskTestCase, self).__call__(result)
#         self._post_tearDown()
# 
#     def _pre_setup(self):
#         bootstrap_mass_flask()
#         if not 'MASS_TESTING' in app.config or app.config['MASS_TESTING'] is False:
#             raise RuntimeError('Running unit test without TESTING=True in configuration. Aborting.')
#         self.app = app
#         self.client = app.test_client()
#         self._ctx = self.app.test_request_context()
#         self._ctx.push()
# 
#     def _post_tearDown(self):
#         self._ctx.pop()
#         self._clean_test_database()


# Path: mass_flask_core/tests/test_request_dispatch.py
from mixer.backend.mongoengine import mixer
from mongoengine import DoesNotExist
from mass_flask_core.models import AnalysisSystem, AnalysisRequest, IPSample, URISample
from mass_flask_core.tests import FlaskTestCase




class RequestDispatchTestCase(FlaskTestCase):
    def test_are_requests_correct_after_sample_creation(self):
        system = mixer.blend(AnalysisSystem, tag_filter_expression='sample-type:ipsample')

        ipsample = mixer.blend(IPSample, tags=['sample-type:ipsample'])