tests: fixed tests after removing hardcoded timezone in tests.
This commit is contained in:
parent
e326a3f835
commit
05d89e4d2c
5 changed files with 30 additions and 48 deletions
|
|
@ -29,6 +29,7 @@ import socket
|
|||
import subprocess32
|
||||
import time
|
||||
import uuid
|
||||
import dateutil.tz
|
||||
|
||||
import mock
|
||||
import pyramid.testing
|
||||
|
|
@ -1814,3 +1815,11 @@ def root_repos_integration_stub(request, StubIntegrationType,
|
|||
IntegrationModel().delete(integration)
|
||||
|
||||
return integration
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def local_dt_to_utc():
|
||||
def _factory(dt):
|
||||
return dt.replace(tzinfo=dateutil.tz.tzlocal()).astimezone(
|
||||
dateutil.tz.tzutc()).replace(tzinfo=None)
|
||||
return _factory
|
||||
|
|
|
|||
|
|
@ -28,34 +28,6 @@ from rhodecode.tests.vcs.base import BackendTestMixin
|
|||
|
||||
class TestBranches(BackendTestMixin):
|
||||
|
||||
@classmethod
|
||||
def _get_commits(cls):
|
||||
commits = [
|
||||
{
|
||||
'message': 'Initial commit',
|
||||
'author': 'Joe Doe <joe.doe@example.com>',
|
||||
'date': datetime.datetime(2010, 1, 1, 20),
|
||||
'added': [
|
||||
FileNode('foobar', content='Foobar'),
|
||||
FileNode('foobar2', content='Foobar II'),
|
||||
FileNode('foo/bar/baz', content='baz here!'),
|
||||
],
|
||||
},
|
||||
{
|
||||
'message': 'Changes...',
|
||||
'author': 'Jane Doe <jane.doe@example.com>',
|
||||
'date': datetime.datetime(2010, 1, 1, 21),
|
||||
'added': [
|
||||
FileNode('some/new.txt', content='news...'),
|
||||
],
|
||||
'changed': [
|
||||
FileNode('foobar', 'Foobar I'),
|
||||
],
|
||||
'removed': [],
|
||||
},
|
||||
]
|
||||
return commits
|
||||
|
||||
def test_empty_repository_has_no_branches(self, vcsbackend):
|
||||
empty_repo = vcsbackend.create_repo()
|
||||
assert empty_repo.branches == {}
|
||||
|
|
@ -71,9 +43,10 @@ class TestBranches(BackendTestMixin):
|
|||
def test_closed_branches(self):
|
||||
assert len(self.repo.branches_closed) == 0
|
||||
|
||||
def test_simple(self):
|
||||
def test_simple(self, local_dt_to_utc):
|
||||
tip = self.repo.get_commit()
|
||||
assert tip.date == datetime.datetime(2010, 1, 1, 21)
|
||||
assert tip.message == 'Changes...'
|
||||
assert tip.date == local_dt_to_utc(datetime.datetime(2010, 1, 1, 21))
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_new_branch(self):
|
||||
|
|
@ -145,7 +118,7 @@ class TestBranches(BackendTestMixin):
|
|||
assert '123' in self.repo.branches
|
||||
|
||||
|
||||
class TestSvnBranches:
|
||||
class TestSvnBranches(object):
|
||||
|
||||
def test_empty_repository_has_no_tags_and_branches(self, vcsbackend_svn):
|
||||
empty_repo = vcsbackend_svn.create_repo()
|
||||
|
|
|
|||
|
|
@ -321,16 +321,13 @@ class TestCommits(BackendTestMixin):
|
|||
def test_get_file_annotate(self):
|
||||
file_added_commit = self.repo.get_commit(commit_idx=3)
|
||||
annotations = list(file_added_commit.get_file_annotate('file_3.txt'))
|
||||
|
||||
line_no, commit_id, commit_loader, line = annotations[0]
|
||||
|
||||
assert line_no == 1
|
||||
assert commit_id == file_added_commit.raw_id
|
||||
assert commit_loader() == file_added_commit
|
||||
|
||||
# git annotation is generated differently thus different results
|
||||
if self.repo.alias == 'git':
|
||||
assert line == '(Joe Doe 2010-01-03 08:00:00 +0000 1) Foobar 3'
|
||||
else:
|
||||
assert line == 'Foobar 3'
|
||||
assert 'Foobar 3' in line
|
||||
|
||||
def test_get_file_annotate_does_not_exist(self):
|
||||
file_added_commit = self.repo.get_commit(commit_idx=2)
|
||||
|
|
@ -519,7 +516,7 @@ class TestCommitsChanges(BackendTestMixin):
|
|||
},
|
||||
]
|
||||
|
||||
def test_initial_commit(self):
|
||||
def test_initial_commit(self, local_dt_to_utc):
|
||||
commit = self.repo.get_commit(commit_idx=0)
|
||||
assert set(commit.added) == set([
|
||||
commit.get_node('foo/bar'),
|
||||
|
|
@ -531,7 +528,8 @@ class TestCommitsChanges(BackendTestMixin):
|
|||
assert set(commit.removed) == set()
|
||||
assert set(commit.affected_files) == set(
|
||||
['foo/bar', 'foo/bał', 'foobar', 'qwe'])
|
||||
assert commit.date == datetime.datetime(2010, 1, 1, 20, 0)
|
||||
assert commit.date == local_dt_to_utc(
|
||||
datetime.datetime(2010, 1, 1, 20, 0))
|
||||
|
||||
def test_head_added(self):
|
||||
commit = self.repo.get_commit()
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ class TestInMemoryCommit(BackendTestMixin):
|
|||
repo = self.Backend(self.repo_path)
|
||||
assert len(repo.commit_ids) == N
|
||||
|
||||
def test_date_attr(self):
|
||||
def test_date_attr(self, local_dt_to_utc):
|
||||
node = FileNode('foobar.txt', content='Foobared!')
|
||||
self.imc.add(node)
|
||||
date = datetime.datetime(1985, 1, 30, 1, 45)
|
||||
|
|
@ -328,7 +328,7 @@ class TestInMemoryCommit(BackendTestMixin):
|
|||
u"Committed at time when I was born ;-)",
|
||||
author=u'lb', date=date)
|
||||
|
||||
assert commit.date == date
|
||||
assert commit.date == local_dt_to_utc(date)
|
||||
|
||||
def assert_succesful_commit(self, added_nodes):
|
||||
newtip = self.repo.get_commit()
|
||||
|
|
|
|||
|
|
@ -90,22 +90,24 @@ class TestRepositoryBase(BackendTestMixin):
|
|||
self.Backend.check_url(self.repo.path + "invalid", config)
|
||||
|
||||
def test_get_contact(self):
|
||||
self.repo.contact
|
||||
assert self.repo.contact
|
||||
|
||||
def test_get_description(self):
|
||||
self.repo.description
|
||||
assert self.repo.description
|
||||
|
||||
def test_get_hook_location(self):
|
||||
assert len(self.repo.get_hook_location()) != 0
|
||||
|
||||
def test_last_change(self):
|
||||
assert self.repo.last_change >= datetime.datetime(2010, 1, 1, 21, 0)
|
||||
def test_last_change(self, local_dt_to_utc):
|
||||
assert self.repo.last_change >= local_dt_to_utc(
|
||||
datetime.datetime(2010, 1, 1, 21, 0))
|
||||
|
||||
def test_last_change_in_empty_repository(self, vcsbackend):
|
||||
def test_last_change_in_empty_repository(self, vcsbackend, local_dt_to_utc):
|
||||
delta = datetime.timedelta(seconds=1)
|
||||
start = datetime.datetime.now()
|
||||
|
||||
start = local_dt_to_utc(datetime.datetime.now())
|
||||
empty_repo = vcsbackend.create_repo()
|
||||
now = datetime.datetime.now()
|
||||
now = local_dt_to_utc(datetime.datetime.now())
|
||||
assert empty_repo.last_change >= start - delta
|
||||
assert empty_repo.last_change <= now + delta
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue