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

from __future__ import absolute_import

import os
from sentry.testutils import CliTestCase
from sentry.runner.commands.init import init


class InitTest(CliTestCase):
    def test_simple(self):
        with self.runner.isolated_filesystem():
            rv = self.runner.invoke(init, ['config'], obj={})
            assert rv.exit_code == 0, rv.output
            contents = os.listdir('config')
            assert set(contents) == {'sentry.conf.py', 'config.yml'}

            # Make sure the python file is valid
            ctx = {'__file__': 'sentry.conf.py'}
            execfile('config/sentry.conf.py', ctx)
            assert 'DEBUG' in ctx

            # Make sure the yaml file is valid
            from sentry.utils.yaml import safe_load
            with open('config/config.yml', 'rb') as fp:
                ctx = safe_load(fp)
            assert 'system.secret-key' in ctx

Add tests for init command