This repository has been archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
7,021 additions
and
5,673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.30 | ||
1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-r requirements.txt | ||
|
||
pytest==3.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""test db module.""" | ||
from itertools import product | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'path_isfile_retval, check_dbv_retval, path_is_dbc_path', | ||
product([False, True], repeat=3) | ||
) | ||
def test_init_db(path_isfile_retval, check_dbv_retval, path_is_dbc_path): | ||
"""test sqlite generation and db creation""" | ||
with mock.patch('version.database.db.db_constants') as m_dbc, \ | ||
mock.patch('version.database.db.sqlite3') as m_sl3, \ | ||
mock.patch('version.database.db.os') as m_os, \ | ||
mock.patch('version.database.db.create_db_path') as m_create_db_path, \ | ||
mock.patch('version.database.db.check_db_version') \ | ||
as m_check_dbv: | ||
from version.database import db | ||
m_os.path.isfile.return_value = path_isfile_retval | ||
m_check_dbv.return_value = check_dbv_retval | ||
if path_is_dbc_path: | ||
path = m_dbc.DB_PATH | ||
else: | ||
path = mock.Mock() | ||
# run | ||
res = db.init_db(path) | ||
# test | ||
if path_isfile_retval: | ||
if path == m_dbc.DB_PATH and not check_dbv_retval: | ||
m_sl3.assert_has_calls([ | ||
mock.call.connect(path, check_same_thread=False), | ||
]) | ||
assert res is None | ||
return | ||
else: | ||
m_sl3.assert_has_calls([ | ||
mock.call.connect(path, check_same_thread=False), | ||
mock.call.connect().execute('PRAGMA foreign_keys = on') | ||
]) | ||
else: | ||
m_create_db_path.assert_called_once_with() | ||
|
||
m_sl3.assert_has_calls([ | ||
mock.call.connect(path, check_same_thread=False), | ||
mock.call.connect().cursor(), | ||
mock.call.connect().cursor().execute( | ||
'CREATE TABLE IF NOT EXISTS version(version REAL)'), | ||
mock.call.connect().cursor().execute( | ||
'INSERT INTO version(version) VALUES(?)', | ||
(m_dbc.CURRENT_DB_VERSION,) | ||
), | ||
mock.call.connect().cursor().executescript(db.STRUCTURE_SCRIPT), | ||
mock.call.connect().commit(), | ||
mock.call.connect().execute('PRAGMA foreign_keys = on') | ||
]) | ||
assert res == m_sl3.connect.return_value | ||
assert res.isolation_level is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""test utils module.""" | ||
from unittest import mock | ||
from itertools import product | ||
|
||
import pytest | ||
|
||
from version.utils import backup_database | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'mock_exists_retval, mock_isdir_retval', | ||
product([True, False], repeat=2) | ||
) | ||
def test_run_backup_database(mock_exists_retval, mock_isdir_retval): | ||
"""test run with mock obj as input.""" | ||
mock_db_path = mock.Mock() | ||
mock_base_path = mock.Mock() | ||
mock_name = mock.Mock() | ||
with mock.patch('version.utils.os') as mock_os, \ | ||
mock.patch('version.utils.shutil') as mock_shutil, \ | ||
mock.patch('version.utils.datetime') as mock_datetime: | ||
mock_datetime.datetime.today.return_value = '2016-10-25 15:42:47.649416' | ||
mock_os.path.split.return_value = (mock_base_path, mock_name) | ||
mock_os.path.exists.return_value = mock_exists_retval | ||
mock_os.path.isdir.return_value = mock_isdir_retval | ||
res = backup_database(mock_db_path) | ||
assert res | ||
mock_datetime.datetime.today.assert_called_once_with() | ||
os_calls = [ | ||
mock.call.path.split(mock_db_path), | ||
mock.call.path.join(mock_base_path, 'backup'), | ||
mock.call.path.isdir(mock_os.path.join.return_value), | ||
mock.call.path.join( | ||
mock_os.path.join.return_value, | ||
"2016-10-25-{}".format(mock_name)), | ||
mock.call.path.exists(mock_os.path.join.return_value), | ||
] | ||
if mock_exists_retval: | ||
if mock_isdir_retval: | ||
assert len(mock_os.mock_calls) == 103 | ||
else: | ||
assert len(mock_os.mock_calls) == 104 | ||
os_calls.extend([ | ||
mock.call.path.join( | ||
mock_os.path.join.return_value, | ||
"2016-10-25(1)-2016-10-25-{}".format(mock_name)), | ||
mock.call.path.join( | ||
mock_os.path.join.return_value, | ||
"2016-10-25(2)-2016-10-25-{}".format(mock_name)), | ||
]) | ||
assert not mock_shutil.mock_calls | ||
else: | ||
if mock_isdir_retval: | ||
assert len(mock_os.mock_calls) == 5 | ||
else: | ||
assert len(mock_os.mock_calls) == 6 | ||
mock_shutil.copyfile.assert_called_once_with( | ||
mock_db_path, mock_os.path.join.return_value) | ||
|
||
if mock_isdir_retval: | ||
assert not mock_os.mkdir.called | ||
else: | ||
mock_os.mkdir.assert_called_once_with(mock_os.path.join.return_value) | ||
mock_os.assert_has_calls(os_calls, any_order=True) |
Oops, something went wrong.