##// END OF EJS Templates
added latest changes
added latest changes

File last commit:

r5608:6d33e504 default
r5658:a109f5ac merge default
Show More
test_utils.py
178 lines | 7.0 KiB | text/x-python | PythonLexer
core: updated copyright to 2024
r5608 # Copyright (C) 2010-2024 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
tests: use gunicorn for testing. This is close to production testing...
r2453 import os
project: added all source files and assets
r1 import datetime
python3: remove usage of subprocess32
r4926 import subprocess
project: added all source files and assets
r1
import pytest
tests: fixed all tests for python3 BIG changes
r5087 from rhodecode.lib.vcs.backends.git import GitRepository
project: added all source files and assets
r1 from rhodecode.lib.vcs.exceptions import VCSError
from rhodecode.lib.vcs.utils import author_email, author_name
from rhodecode.lib.vcs.utils.helpers import get_scm
from rhodecode.lib.vcs.utils.helpers import get_scms_for_path
from rhodecode.lib.vcs.utils.helpers import parse_datetime
from rhodecode.lib.vcs.utils.paths import get_dirs_for_path
pylons: remove pylons as dependency...
r2351 @pytest.mark.usefixtures("baseapp")
tests: use gunicorn for testing. This is close to production testing...
r2453 class TestPaths(object):
project: added all source files and assets
r1 def _test_get_dirs_for_path(self, path, expected):
"""
Tests if get_dirs_for_path returns same as expected.
"""
expected = sorted(expected)
result = sorted(get_dirs_for_path(path))
tests: fixed test suite for celery adoption
r5607 assert result == expected, "%s != %s which was expected result for path %s" % (result, expected, path)
project: added all source files and assets
r1
def test_get_dirs_for_path(self):
tests: fixed test suite for celery adoption
r5607 path = "foo/bar/baz/file"
project: added all source files and assets
r1 paths_and_results = (
tests: fixed test suite for celery adoption
r5607 ("foo/bar/baz/file", ["foo", "foo/bar", "foo/bar/baz"]),
("foo/bar/", ["foo", "foo/bar"]),
("foo/bar", ["foo"]),
project: added all source files and assets
r1 )
for path, expected in paths_and_results:
self._test_get_dirs_for_path(path, expected)
def test_get_scms_for_path(self, tmpdir):
new = tmpdir.strpath
assert get_scms_for_path(new) == []
tests: fixed test suite for celery adoption
r5607 os.mkdir(os.path.join(new, ".tux"))
project: added all source files and assets
r1 assert get_scms_for_path(new) == []
tests: fixed test suite for celery adoption
r5607 os.mkdir(os.path.join(new, ".git"))
assert set(get_scms_for_path(new)) == set(["git"])
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 os.mkdir(os.path.join(new, ".hg"))
assert set(get_scms_for_path(new)) == set(["git", "hg"])
project: added all source files and assets
r1
tests: use gunicorn for testing. This is close to production testing...
r2453 class TestGetScm(object):
project: added all source files and assets
r1 def test_existing_repository(self, vcs_repository_support):
alias, repo = vcs_repository_support
assert (alias, repo.path) == get_scm(repo.path)
def test_raises_if_path_is_empty(self, tmpdir):
with pytest.raises(VCSError):
get_scm(str(tmpdir))
def test_get_scm_error_path(self):
with pytest.raises(VCSError):
tests: fixed test suite for celery adoption
r5607 get_scm("err")
project: added all source files and assets
r1
def test_get_two_scms_for_path(self, tmpdir):
multialias_repo_path = str(tmpdir)
tests: fixed all tests for python3 BIG changes
r5087 git_default_branch = GitRepository.DEFAULT_BRANCH_NAME
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 subprocess.check_call(["hg", "init", multialias_repo_path])
subprocess.check_call(["git", "-c", f"init.defaultBranch={git_default_branch}", "init", multialias_repo_path])
project: added all source files and assets
r1
with pytest.raises(VCSError):
get_scm(multialias_repo_path)
def test_ignores_svn_working_copy(self, tmpdir):
tests: fixed test suite for celery adoption
r5607 tmpdir.mkdir(".svn")
project: added all source files and assets
r1 with pytest.raises(VCSError):
get_scm(tmpdir.strpath)
tests: use gunicorn for testing. This is close to production testing...
r2453 class TestParseDatetime(object):
project: added all source files and assets
r1 def test_datetime_text(self):
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("2010-04-07 21:29:41") == datetime.datetime(2010, 4, 7, 21, 29, 41)
project: added all source files and assets
r1
def test_no_seconds(self):
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("2010-04-07 21:29") == datetime.datetime(2010, 4, 7, 21, 29)
project: added all source files and assets
r1
def test_date_only(self):
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("2010-04-07") == datetime.datetime(2010, 4, 7)
project: added all source files and assets
r1
def test_another_format(self):
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("04/07/10 21:29:41") == datetime.datetime(2010, 4, 7, 21, 29, 41)
project: added all source files and assets
r1
def test_now(self):
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("now") - datetime.datetime.now() < datetime.timedelta(seconds=1)
project: added all source files and assets
r1
def test_today(self):
today = datetime.date.today()
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("today") == datetime.datetime(*today.timetuple()[:3])
project: added all source files and assets
r1
def test_yesterday(self):
yesterday = datetime.date.today() - datetime.timedelta(days=1)
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("yesterday") == datetime.datetime(*yesterday.timetuple()[:3])
project: added all source files and assets
r1
def test_tomorrow(self):
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
args = tomorrow.timetuple()[:3] + (23, 59, 59)
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("tomorrow") == datetime.datetime(*args)
project: added all source files and assets
r1
def test_days(self):
timestamp = datetime.datetime.today() - datetime.timedelta(days=3)
args = timestamp.timetuple()[:3] + (0, 0, 0, 0)
expected = datetime.datetime(*args)
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("3d") == expected
assert parse_datetime("3 d") == expected
assert parse_datetime("3 day") == expected
assert parse_datetime("3 days") == expected
project: added all source files and assets
r1
def test_weeks(self):
timestamp = datetime.datetime.today() - datetime.timedelta(days=3 * 7)
args = timestamp.timetuple()[:3] + (0, 0, 0, 0)
expected = datetime.datetime(*args)
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("3w") == expected
assert parse_datetime("3 w") == expected
assert parse_datetime("3 week") == expected
assert parse_datetime("3 weeks") == expected
project: added all source files and assets
r1
def test_mixed(self):
tests: fixed test suite for celery adoption
r5607 timestamp = datetime.datetime.today() - datetime.timedelta(days=2 * 7 + 3)
project: added all source files and assets
r1 args = timestamp.timetuple()[:3] + (0, 0, 0, 0)
expected = datetime.datetime(*args)
tests: fixed test suite for celery adoption
r5607 assert parse_datetime("2w3d") == expected
assert parse_datetime("2w 3d") == expected
assert parse_datetime("2w 3 days") == expected
assert parse_datetime("2 weeks 3 days") == expected
project: added all source files and assets
r1
tests: fixed test suite for celery adoption
r5607 @pytest.mark.parametrize(
"test_str, name, email",
[
("Marcin Kuzminski <marcin@python-works.com>", "Marcin Kuzminski", "marcin@python-works.com"),
("Marcin Kuzminski Spaces < marcin@python-works.com >", "Marcin Kuzminski Spaces", "marcin@python-works.com"),
(
"Marcin Kuzminski <marcin.kuzminski@python-works.com>",
"Marcin Kuzminski",
"marcin.kuzminski@python-works.com",
),
("mrf RFC_SPEC <marcin+kuzminski@python-works.com>", "mrf RFC_SPEC", "marcin+kuzminski@python-works.com"),
("username <user@email.com>", "username", "user@email.com"),
("username <user@email.com", "username", "user@email.com"),
("broken missing@email.com", "broken", "missing@email.com"),
("<justemail@mail.com>", "", "justemail@mail.com"),
("justname", "justname", ""),
("Mr Double Name withemail@email.com ", "Mr Double Name", "withemail@email.com"),
],
)
tests: use gunicorn for testing. This is close to production testing...
r2453 class TestAuthorExtractors(object):
project: added all source files and assets
r1 def test_author_email(self, test_str, name, email):
assert email == author_email(test_str)
def test_author_name(self, test_str, name, email):
assert name == author_name(test_str)