Skip to content

Commit

Permalink
Tests reviewed
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jun 29, 2017
1 parent d80fa32 commit 0ca409b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
1 change: 0 additions & 1 deletion python/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
__author__ = 'RomanovDA'
1 change: 0 additions & 1 deletion python/tests/test_argparse.py

This file was deleted.

10 changes: 5 additions & 5 deletions python/tests/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import unittest
import os
from ccdb import get_ccdb_home_path

from ccdb.authentication import EnvironmentAuthentication

from ccdb import AlchemyProvider


class AuthenticationTest(unittest.TestCase):

def setUp(self):
Expand All @@ -15,12 +14,13 @@ def setUp(self):
self.mysql_connection_str = "mysql://ccdb_user@127.0.0.1:3306/ccdb"
self.provider = AlchemyProvider()


def test_environment_auth(self):
self.provider.connect(self.sqlite_connection_str)

if "CCDB_USER" in os.environ: del os.environ["CCDB_USER"]
if "USER" in os.environ: del os.environ["USER"]
if "CCDB_USER" in os.environ:
del os.environ["CCDB_USER"]
if "USER" in os.environ:
del os.environ["USER"]

os.environ["CCDB_USER"] = "test_user"

Expand Down
14 changes: 5 additions & 9 deletions python/tests/test_console_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,37 @@ def setUp(self):
self.sqlite_connection_str = "sqlite:///" + os.path.join(ccdb_path, "sql", "ccdb.sqlite")
self.mysql_connection_str = "mysql://ccdb_user@127.0.0.1:3306/ccdb"

#initialize but disable colorama
# initialize but disable colorama
ccdb.cmd.colorama.init(autoreset=True)
ccdb.cmd.colorama.deinit()

#create console context
# create console context
self.context = ConsoleContext()
self.context.silent_exceptions = False
self.context.theme = ccdb.cmd.themes.NoColorTheme()
self.context.connection_string = self.sqlite_connection_str
self.context.user_name = "python_tests"
self.context.register_utilities()

#save stdout
# save stdout
self.output = StringIO()
self.saved_stdout = sys.stdout
sys.stdout = self.output

#logger
# logger
ch = logging.StreamHandler()
ch.stream = self.output
logger.addHandler(ch)
logger.setLevel(logging.INFO)



def tearDown(self):
#restore stdout
# restore stdout
sys.stdout = self.saved_stdout


def test_context(self):
"""Test utils are loaded"""
self.assertTrue(len(self.context.utils)>0)


def test_cat(self):
"""cat. General help"""
self.context.process_command_line("cat /test/test_vars/test_table")
Expand Down
17 changes: 6 additions & 11 deletions python/tests/test_path_utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@

import unittest

import ccdb.path_utils


class AuthenticationTest(unittest.TestCase):


def test_parse_time(self):
#test of simple parse
# test of simple parse
dt = ccdb.path_utils.parse_time("2012-11x13_12-37:55") # set different symbols as separators
self.assertEqual(dt.strftime("%Y-%m-%d_%H-%M-%S"), "2012-11-13_12-37-55")

#test of non full parse
# test of non full parse
dt = ccdb.path_utils.parse_time("2012-11x13") # set different symbols as separators
self.assertEqual(dt.strftime("%Y-%m-%d_%H-%M-%S"), "2012-11-13_23-59-59")


def test_full_parse_request(self):
#test full request
# test full request
result = ccdb.path_utils.parse_request("/test/test_vars/test_table:100:mc:2012-11-13_12:37:55")
self.assertTrue(result.path_is_parsed)
self.assertEqual(result.path, "/test/test_vars/test_table")
Expand All @@ -29,19 +27,17 @@ def test_full_parse_request(self):
self.assertEqual(result.time_str, "2012-11-13_12:37:55")
self.assertEqual(result.time.strftime("%Y-%m-%d_%H-%M-%S"), "2012-11-13_12-37-55")


def test_partial1_parse_request(self):
#test full request
# test full request
result = ccdb.path_utils.parse_request("/test/test_vars/test_table")
self.assertTrue(result.path_is_parsed)
self.assertEqual(result.path, "/test/test_vars/test_table")
self.assertFalse(result.run_is_parsed)
self.assertFalse(result.variation_is_parsed)
self.assertFalse(result.time_is_parsed)


def test_partial2_parse_request(self):
#test full request
# test full request
result = ccdb.path_utils.parse_request("/test/test_vars/test_table::mc")
self.assertTrue(result.path_is_parsed)
self.assertEqual(result.path, "/test/test_vars/test_table")
Expand All @@ -50,7 +46,6 @@ def test_partial2_parse_request(self):
self.assertEqual(result.variation, "mc")
self.assertFalse(result.time_is_parsed)


def test_validate_name(self):
""" Checks if name is valid ccdb object name """
self.assertTrue(ccdb.path_utils.validate_name("this_is_variation2"))
Expand Down
2 changes: 0 additions & 2 deletions python/tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class SQLiteAlchemyProviderTest(AlchemyProviderTest):


def setUp(self):
AlchemyProviderTest.setUp(self)
self.connection_str = "sqlite:///" + os.path.join(self.ccdb_path, "sql", "ccdb.sqlite")
Expand All @@ -17,7 +16,6 @@ def test_sqlite_wrong_file(self):

class MySQLAlchemyProviderTest(AlchemyProviderTest):


def setUp(self):
AlchemyProviderTest.setUp(self)
self.connection_str = "mysql://ccdb_user@127.0.0.1:3306/ccdb"
Expand Down

0 comments on commit 0ca409b

Please sign in to comment.