# 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_system_instance.py
# class AnalysisSystemInstance(db.Document, AbstractAuthEntity):
#     @property
#     def is_authenticated(self):
#         return True
# 
#     def get_roles(self):
#         return ['analysis_system_instance']
# 
#     @property
#     def max_tlp_level(self):
#         return TLPLevelField.TLP_LEVEL_WHITE
# 
#     analysis_system = ReferenceField(AnalysisSystem, required=True)
#     uuid = StringField(max_length=36, required=True, unique=True, default=_gen_uuid)
#     last_seen = DateTimeField()
# 
#     meta = {
#         'ordering': ['analysis_system', 'uuid'],
#         'indexes': [('analysis_system', 'uuid')]
#     }
# 
#     def __repr__(self):
#         return '[AnalysisSystemInstance] {} {}'.format(self.analysis_system.identifier_name, self.uuid)
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def update_last_seen(self):
#         self.last_seen = TimeFunctions.get_timestamp()
#         self.save()
# 
#     @property
#     def is_online(self):
#         if self.last_seen is None:
#             return False
# 
#         difference = TimeFunctions.get_timestamp() - self.last_seen
#         return difference < datetime.timedelta(minutes=10)
# 
# 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/utils/time_functions.py
# class TimeFunctions:
#     @staticmethod
#     def get_timestamp():
#         # We remove the microsecond part of the timestamp here since mongoengine can not handle it correctly and test cases fail due to the lost precision
#         return datetime.now(utc).replace(microsecond=0)


import datetime
from mixer.backend.mongoengine import mixer
from mongoengine import NotUniqueError, ValidationError
from mass_flask_core.models import AnalysisSystem, AnalysisSystemInstance
from mass_flask_core.tests import FlaskTestCase
from mass_flask_core.utils import TimeFunctions


class AnalysisSystemInstanceTestCase(FlaskTestCase):
    def test_is_repr_and_str_correct(self):
        system = mixer.blend(AnalysisSystem, identifier_name='InstanceTestSystem')

# 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_system_instance.py
# class AnalysisSystemInstance(db.Document, AbstractAuthEntity):
#     @property
#     def is_authenticated(self):
#         return True
# 
#     def get_roles(self):
#         return ['analysis_system_instance']
# 
#     @property
#     def max_tlp_level(self):
#         return TLPLevelField.TLP_LEVEL_WHITE
# 
#     analysis_system = ReferenceField(AnalysisSystem, required=True)
#     uuid = StringField(max_length=36, required=True, unique=True, default=_gen_uuid)
#     last_seen = DateTimeField()
# 
#     meta = {
#         'ordering': ['analysis_system', 'uuid'],
#         'indexes': [('analysis_system', 'uuid')]
#     }
# 
#     def __repr__(self):
#         return '[AnalysisSystemInstance] {} {}'.format(self.analysis_system.identifier_name, self.uuid)
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def update_last_seen(self):
#         self.last_seen = TimeFunctions.get_timestamp()
#         self.save()
# 
#     @property
#     def is_online(self):
#         if self.last_seen is None:
#             return False
# 
#         difference = TimeFunctions.get_timestamp() - self.last_seen
#         return difference < datetime.timedelta(minutes=10)
# 
# 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/utils/time_functions.py
# class TimeFunctions:
#     @staticmethod
#     def get_timestamp():
#         # We remove the microsecond part of the timestamp here since mongoengine can not handle it correctly and test cases fail due to the lost precision
#         return datetime.now(utc).replace(microsecond=0)


# Path: mass_flask_core/tests/test_analysis_system_instance.py
import datetime
from mixer.backend.mongoengine import mixer
from mongoengine import NotUniqueError, ValidationError
from mass_flask_core.models import AnalysisSystem, AnalysisSystemInstance
from mass_flask_core.tests import FlaskTestCase
from mass_flask_core.utils import TimeFunctions



class AnalysisSystemInstanceTestCase(FlaskTestCase):
    def test_is_repr_and_str_correct(self):
        system = mixer.blend(AnalysisSystem, identifier_name='InstanceTestSystem')

        instance = mixer.blend(AnalysisSystemInstance, uuid='e25b2339-23d4-4544-8c99-f2968a935319', analysis_system=system)