1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-30 21:50:59 +00:00
seahub/tests/seahub/base/test_models.py
王健辉 5a97b20065 file uuid map use origin repo_id (#4045)
* file_uuid_map_use_origin_repo_id

* fix test error
2019-09-02 18:11:05 +08:00

92 lines
3.8 KiB
Python

import hashlib
from seahub.base.models import FileComment
from seahub.test_utils import BaseTestCase
from seahub.tags.models import FileUUIDMap
class FileCommentManagerTest(BaseTestCase):
def setUp(self):
self.repo_id = self.repo.id
def tearDown(self):
self.remove_repo()
def test_can_add(self):
assert len(FileComment.objects.all()) == 0
o = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar',
item_name='test.txt',
author=self.user.username,
comment='test comment')
assert o.uuid.parent_path == '/foo/bar'
assert len(FileComment.objects.all()) == 1
def test_add_by_file_path(self):
assert len(FileComment.objects.all()) == 0
o = FileComment.objects.add_by_file_path(
repo_id=self.repo_id, file_path='/foo/bar/test.txt',
author=self.user.username, comment='test comment')
assert o.uuid.parent_path == '/foo/bar'
assert len(FileComment.objects.all()) == 1
def test_get_by_file_path(self):
o1 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar/',
item_name='test.txt',
author=self.user.username,
comment='test comment 1')
o2 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar',
item_name='test.txt',
author=self.user.username,
comment='test comment 2')
assert len(FileComment.objects.get_by_file_path(self.repo_id, '/foo/bar/test.txt')) == 2
def test_get_by_parent_path(self):
o1 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar/',
item_name='test1.txt',
author=self.user.username,
comment='comment 1')
o2 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar',
item_name='test2.txt',
author=self.user.username,
comment='comment 2')
assert len(FileComment.objects.get_by_parent_path(self.repo_id, '/foo/bar/')) == 2
assert len(FileComment.objects.get_by_parent_path(self.repo_id, '/foo/bar')) == 2
class FileCommentTest(BaseTestCase):
def setUp(self):
self.repo_id = self.repo.id
def tearDown(self):
self.remove_repo()
def test_md5_repo_id_parent_path(self):
md5 = FileUUIDMap.md5_repo_id_parent_path(self.repo_id, '/')
assert md5 == hashlib.md5(self.repo_id + '/').hexdigest()
md5 = FileUUIDMap.md5_repo_id_parent_path(self.repo_id, '/foo')
assert md5 == hashlib.md5(self.repo_id + '/foo').hexdigest()
md5 = FileUUIDMap.md5_repo_id_parent_path(self.repo_id, '/foo/')
assert md5 == hashlib.md5(self.repo_id + '/foo').hexdigest()
def test_normalize_path(self):
o = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar/',
item_name='test.txt',
author=self.user.username,
comment='test comment')
assert o.uuid.parent_path == '/foo/bar'
def test_can_save(self):
assert len(FileComment.objects.all()) == 0
uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(self.repo_id, '/foo/bar/', 'test.txt', False)
FileComment(uuid=uuid, author=self.user.username,
comment='test comment').save()
assert len(FileComment.objects.all()) == 1