Skip to content

Commit

Permalink
Added tests for bluekai.__init__ module
Browse files Browse the repository at this point in the history
  • Loading branch information
akameron committed Mar 11, 2016
1 parent 447db95 commit 718aa61
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
from unittest import TestCase
from mock import patch
from mock import Mock
import logging
from bluekai import create_app
from bluekai import logging_init

class create_app_test(TestCase):

def setUp(self):
self.config = {
'DEBUG': "",
}
self.model_mock = Mock()

def test_production(self):

app = create_app(self.config, self.model_mock)
self.assertIs(app.model, self.model_mock)
self.model_mock.exists.assert_not_called()
self.model_mock.create_table.assert_not_called()

def test_debug_when_table_does_not_exist(self):
self.config['DEBUG'] = True
self.model_mock.exists.return_value = False
app = create_app(self.config, self.model_mock)
self.model_mock.exists.assert_called_once_with()
self.model_mock.create_table.assert_called_once_with(
read_capacity_units=1, write_capacity_units=1)

def test_debug_when_table_exist(self):
self.config['DEBUG'] = True
self.model_mock.exists.return_value = True
app = create_app(self.config, self.model_mock)
self.model_mock.exists.assert_called_once_with()
self.model_mock.create_table.assert_not_called()


class logging_init_test(TestCase):

def setUp(self):

self.config = {
'DEBUG': "",
}
self.app = Mock()
self.app.config = {
'APP_LOG_FILE': 'test_app_log_file',
'APP_LOG_NUM_BACKUPS': 'test_app_log_backups',
'APP_LOG_FILESIZE': '1000',
'LOGGER_NAME': 'test_logger_name',
}

def test_production(self):

self.app.debug = False
handler = logging_init(self.app)
self.assertEqual(handler.level, logging.INFO)

def test_debug(self):

self.app.debug = True
handler = logging_init(self.app)
self.assertEqual(handler.level, logging.DEBUG)

0 comments on commit 718aa61

Please sign in to comment.