# Path: mass_flask_core/models/sample.py
# class Sample(db.Document, CommentsMixin):
#     delivery_date = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     first_seen = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     tags = ListField(StringField(regex=r'^[\w:\-\_\/\+\.]+$'))
#     dispatched_to = ListField(ReferenceField(AnalysisSystem))
#     created_by = GenericReferenceField()
#     tlp_level = TLPLevelField(verbose_name='TLP Level', help_text='Privacy level of this sample', required=True)
# 
#     meta = {
#         'allow_inheritance': True,
#         'ordering': ['-delivery_date'],
#         'indexes': ['delivery_date'],
#         'queryset_class': SampleQuerySet
#     }
# 
#     def __repr__(self):
#         return '[{}] {}'.format(str(self.__class__.__name__), str(self.id))
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     @property
#     def title(self):
#         return self.id
# 
#     def add_tags(self, tags):
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
#         self.save()
# 
#     def _update(self, **kwargs):
#         if 'first_seen' in kwargs and kwargs['first_seen'] < self.first_seen:
#             self.first_seen = kwargs['first_seen']
#         if 'tlp_level' in kwargs and not self.tlp_level:
#             self.tlp_level = kwargs['tlp_level']
#         if current_authenticated_entity.is_authenticated and not self.created_by:
#             self.created_by = current_authenticated_entity._get_current_object()
#         if 'tags' in kwargs:
#             tags = kwargs['tags']
#         else:
#             tags = []
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         raise ValidationError('Samples of the base type Sample should not be instantiated directly.')
# 
# 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/report.py
# class Report(db.Document):
# 
#     REPORT_STATUS_CODE_OK = 0
#     REPORT_STATUS_CODE_FAILURE = 1
# 
#     REPORT_STATUS_CODES = (
#         (REPORT_STATUS_CODE_OK, 'OK'),
#         (REPORT_STATUS_CODE_FAILURE, 'FAIL'),
#     )
# 
#     analysis_system = ReferenceField(AnalysisSystem, required=True)
#     sample = ReferenceField(Sample, required=True)
#     analysis_date = DateTimeField()
#     upload_date = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     status = IntField(choices=REPORT_STATUS_CODES, default=REPORT_STATUS_CODE_OK, required=True)
#     error_message = StringField(null=True, required=False)
#     tags = ListField(StringField())
#     additional_metadata = DictField()
#     json_report_objects = MapField(field=FileField())
#     raw_report_objects = MapField(field=FileField())
# 
#     meta = {
#         'ordering': ['-upload_date'],
#         'indexes': ['upload_date']
#     }
# 
#     def __repr__(self):
#         return '[Report] {} on {}'.format(self.sample.id, self.analysis_system.identifier_name)
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def _add_report_object(self, file, target):
#         proxy = GridFSProxy()
#         proxy.put(file)
#         target[file.name] = proxy
# 
#     def add_json_report_object(self, file):
#         self._add_report_object(file, self.json_report_objects)
# 
#     def add_raw_report_object(self, file):
#         self._add_report_object(file, self.raw_report_objects)
# 
# 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 mass_flask_core.models import AnalysisSystem, Report, Sample
from mixer.backend.mongoengine import mixer
from mass_flask_core.tests import FlaskTestCase


class ReportTestCase(FlaskTestCase):

    def test_is_repr_and_str_correct(self):
        system = mixer.blend(AnalysisSystem, identifier_name='ReportTestSystem')

# Path: mass_flask_core/models/sample.py
# class Sample(db.Document, CommentsMixin):
#     delivery_date = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     first_seen = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     tags = ListField(StringField(regex=r'^[\w:\-\_\/\+\.]+$'))
#     dispatched_to = ListField(ReferenceField(AnalysisSystem))
#     created_by = GenericReferenceField()
#     tlp_level = TLPLevelField(verbose_name='TLP Level', help_text='Privacy level of this sample', required=True)
# 
#     meta = {
#         'allow_inheritance': True,
#         'ordering': ['-delivery_date'],
#         'indexes': ['delivery_date'],
#         'queryset_class': SampleQuerySet
#     }
# 
#     def __repr__(self):
#         return '[{}] {}'.format(str(self.__class__.__name__), str(self.id))
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     @property
#     def title(self):
#         return self.id
# 
#     def add_tags(self, tags):
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
#         self.save()
# 
#     def _update(self, **kwargs):
#         if 'first_seen' in kwargs and kwargs['first_seen'] < self.first_seen:
#             self.first_seen = kwargs['first_seen']
#         if 'tlp_level' in kwargs and not self.tlp_level:
#             self.tlp_level = kwargs['tlp_level']
#         if current_authenticated_entity.is_authenticated and not self.created_by:
#             self.created_by = current_authenticated_entity._get_current_object()
#         if 'tags' in kwargs:
#             tags = kwargs['tags']
#         else:
#             tags = []
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         raise ValidationError('Samples of the base type Sample should not be instantiated directly.')
# 
# 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/report.py
# class Report(db.Document):
# 
#     REPORT_STATUS_CODE_OK = 0
#     REPORT_STATUS_CODE_FAILURE = 1
# 
#     REPORT_STATUS_CODES = (
#         (REPORT_STATUS_CODE_OK, 'OK'),
#         (REPORT_STATUS_CODE_FAILURE, 'FAIL'),
#     )
# 
#     analysis_system = ReferenceField(AnalysisSystem, required=True)
#     sample = ReferenceField(Sample, required=True)
#     analysis_date = DateTimeField()
#     upload_date = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     status = IntField(choices=REPORT_STATUS_CODES, default=REPORT_STATUS_CODE_OK, required=True)
#     error_message = StringField(null=True, required=False)
#     tags = ListField(StringField())
#     additional_metadata = DictField()
#     json_report_objects = MapField(field=FileField())
#     raw_report_objects = MapField(field=FileField())
# 
#     meta = {
#         'ordering': ['-upload_date'],
#         'indexes': ['upload_date']
#     }
# 
#     def __repr__(self):
#         return '[Report] {} on {}'.format(self.sample.id, self.analysis_system.identifier_name)
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def _add_report_object(self, file, target):
#         proxy = GridFSProxy()
#         proxy.put(file)
#         target[file.name] = proxy
# 
#     def add_json_report_object(self, file):
#         self._add_report_object(file, self.json_report_objects)
# 
#     def add_raw_report_object(self, file):
#         self._add_report_object(file, self.raw_report_objects)
# 
# 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_report.py
from mass_flask_core.models import AnalysisSystem, Report, Sample
from mixer.backend.mongoengine import mixer
from mass_flask_core.tests import FlaskTestCase



class ReportTestCase(FlaskTestCase):

    def test_is_repr_and_str_correct(self):
        system = mixer.blend(AnalysisSystem, identifier_name='ReportTestSystem')

        sample = mixer.blend(Sample, id='55cdd8e89b65211708b7da46')