##// END OF EJS Templates
pytest: Unify create_test_* functions.
Martin Bornhold -
r215:f36a5359 default
parent child Browse files
Show More
@@ -77,11 +77,15 b' def initialize_test_environment(settings'
77 77 if test_env is None:
78 78 test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0))
79 79
80 from rhodecode.lib.utils import create_test_env, create_test_index
80 from rhodecode.lib.utils import (
81 create_test_directory, create_test_database, create_test_repositories,
82 create_test_index)
81 83 from rhodecode.tests import TESTS_TMP_PATH
82 84 # test repos
83 85 if test_env:
84 create_test_env(TESTS_TMP_PATH, settings)
86 create_test_directory(TESTS_TMP_PATH)
87 create_test_database(TESTS_TMP_PATH, settings)
88 create_test_repositories(TESTS_TMP_PATH, settings)
85 89 create_test_index(TESTS_TMP_PATH, settings)
86 90
87 91
@@ -724,7 +724,16 b' def create_test_index(repo_location, con'
724 724 'vcs_search_index', os.path.dirname(config['search.location']))
725 725
726 726
727 def create_test_env(repos_test_path, config):
727 def create_test_directory(test_path):
728 """
729 create test dir if it doesn't exist
730 """
731 if not os.path.isdir(test_path):
732 log.debug('Creating testdir %s', test_path)
733 os.makedirs(test_path)
734
735
736 def create_test_database(test_path, config):
728 737 """
729 738 Makes a fresh database.
730 739 """
@@ -734,33 +743,26 b' def create_test_env(repos_test_path, con'
734 743 dbconf = config['sqlalchemy.db1.url']
735 744 log.debug('making test db %s', dbconf)
736 745
737 # create test dir if it doesn't exist
738 if not os.path.isdir(repos_test_path):
739 log.debug('Creating testdir %s', repos_test_path)
740 os.makedirs(repos_test_path)
741
742 746 dbmanage = DbManage(log_sql=False, dbconf=dbconf, root=config['here'],
743 747 tests=True, cli_args={'force_ask': True})
744 748 dbmanage.create_tables(override=True)
745 749 dbmanage.set_db_version()
746 750 # for tests dynamically set new root paths based on generated content
747 dbmanage.create_settings(dbmanage.config_prompt(repos_test_path))
751 dbmanage.create_settings(dbmanage.config_prompt(test_path))
748 752 dbmanage.create_default_user()
749 753 dbmanage.create_test_admin_and_users()
750 754 dbmanage.create_permissions()
751 755 dbmanage.populate_default_permissions()
752 756 Session().commit()
753 757
754 create_test_repositories(repos_test_path, config)
755 758
756
757 def create_test_repositories(path, config):
759 def create_test_repositories(test_path, config):
758 760 """
759 761 Creates test repositories in the temporary directory. Repositories are
760 762 extracted from archives within the rc_testdata package.
761 763 """
762 764 import rc_testdata
763 from rhodecode.tests import HG_REPO, GIT_REPO, SVN_REPO, TESTS_TMP_PATH
765 from rhodecode.tests import HG_REPO, GIT_REPO, SVN_REPO
764 766
765 767 log.debug('making test vcs repositories')
766 768
@@ -776,15 +778,15 b' def create_test_repositories(path, confi'
776 778 log.debug('remove %s', data_path)
777 779 shutil.rmtree(data_path)
778 780
779 rc_testdata.extract_hg_dump('vcs_test_hg', jn(TESTS_TMP_PATH, HG_REPO))
780 rc_testdata.extract_git_dump('vcs_test_git', jn(TESTS_TMP_PATH, GIT_REPO))
781 rc_testdata.extract_hg_dump('vcs_test_hg', jn(test_path, HG_REPO))
782 rc_testdata.extract_git_dump('vcs_test_git', jn(test_path, GIT_REPO))
781 783
782 784 # Note: Subversion is in the process of being integrated with the system,
783 785 # until we have a properly packed version of the test svn repository, this
784 786 # tries to copy over the repo from a package "rc_testdata"
785 787 svn_repo_path = rc_testdata.get_svn_repo_archive()
786 788 with tarfile.open(svn_repo_path) as tar:
787 tar.extractall(jn(TESTS_TMP_PATH, SVN_REPO))
789 tar.extractall(jn(test_path, SVN_REPO))
788 790
789 791
790 792 #==============================================================================
General Comments 0
You need to be logged in to leave comments. Login now