# Path: app/gates.py
# def generate_info(config):
# def test_against_global_rules(rules, env, lt):
# def are_gates_open(config, env):
# def gate_is_closed(entry, config, env, ticket_id=None):
# def gate_is_manually_closed(entry, env):
# 
# Path: tests/helpers/database_helper.py
# class DatabaseHelper:
#     def __init__(self, environment):
#         config_loader = ConfigLoader(verify=False)
#         self.config = config_loader.load_config("resources/", environment)
#         self.mongo = MongoConnect(self.config)
#         state.mongo = self.mongo
# 
#     def decrease_ticket_expiration_date_by(self, ticket_id, delta):
#         self.mongo.update_ticket(ticket_id, {"expiration_date": self.mongo.get_expiration_date(delta)})
# 
#     def create_holiday(self, days_offset, reason, environments):
#         mongo = MongoConnect(self.config)
#         mongo.add_holiday({
#             'date': (datetime.now() + timedelta(days=days_offset)).strftime('%Y-%m-%d'),
#             'reason': reason,
#             'environments': environments
#         })
# 
#     def clear_database(self):
#         mongo = MongoConnect(self.config)
#         mongo.collection.drop()
#         mongo.tickets.drop()
#         mongo.holidays.drop()


import unittest
from app import gates
from tests.helpers.database_helper import DatabaseHelper
            "hours_range": [0, 24],
            "days_range": [0, 6]
        }
    },
    "develop": {
        "no_restriction": {
            "hours_range": [0, 24],
            "days_range": [0, 6]
        }
    }
}


class TestGates(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.maxDiff = None
        cls.database_helper = DatabaseHelper('test')
        cls.database_helper.clear_database()

    @classmethod
    def tearDown(cls):
        cls.database_helper.clear_database()

    def test_are_gates_open_when_there_is_no_holiday_today(self):
        self.database_helper.create_holiday(1, 'Holidays are always tomorrow', ['live'])
        self.assertEqual(True, gates.are_gates_open(test_rules, 'live'))

    def test_are_gates_closed_on_live_but_open_on_develop(self):
        self.database_helper.create_holiday(0, 'Party time today', ['live'])

# Path: app/gates.py
# def generate_info(config):
# def test_against_global_rules(rules, env, lt):
# def are_gates_open(config, env):
# def gate_is_closed(entry, config, env, ticket_id=None):
# def gate_is_manually_closed(entry, env):
# 
# Path: tests/helpers/database_helper.py
# class DatabaseHelper:
#     def __init__(self, environment):
#         config_loader = ConfigLoader(verify=False)
#         self.config = config_loader.load_config("resources/", environment)
#         self.mongo = MongoConnect(self.config)
#         state.mongo = self.mongo
# 
#     def decrease_ticket_expiration_date_by(self, ticket_id, delta):
#         self.mongo.update_ticket(ticket_id, {"expiration_date": self.mongo.get_expiration_date(delta)})
# 
#     def create_holiday(self, days_offset, reason, environments):
#         mongo = MongoConnect(self.config)
#         mongo.add_holiday({
#             'date': (datetime.now() + timedelta(days=days_offset)).strftime('%Y-%m-%d'),
#             'reason': reason,
#             'environments': environments
#         })
# 
#     def clear_database(self):
#         mongo = MongoConnect(self.config)
#         mongo.collection.drop()
#         mongo.tickets.drop()
#         mongo.holidays.drop()


# Path: tests/test_gates.py
import unittest
from app import gates
from tests.helpers.database_helper import DatabaseHelper

            "hours_range": [0, 24],
            "days_range": [0, 6]
        }
    },
    "develop": {
        "no_restriction": {
            "hours_range": [0, 24],
            "days_range": [0, 6]
        }
    }
}


class TestGates(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.maxDiff = None
        cls.database_helper = DatabaseHelper('test')
        cls.database_helper.clear_database()

    @classmethod
    def tearDown(cls):
        cls.database_helper.clear_database()

    def test_are_gates_open_when_there_is_no_holiday_today(self):
        self.database_helper.create_holiday(1, 'Holidays are always tomorrow', ['live'])
        self.assertEqual(True, gates.are_gates_open(test_rules, 'live'))

    def test_are_gates_closed_on_live_but_open_on_develop(self):
        self.database_helper.create_holiday(0, 'Party time today', ['live'])

        self.assertEqual(False, gates.are_gates_open(test_rules, 'live'))