mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-18 16:36:15 +00:00
add unit test
This commit is contained in:
@@ -2,14 +2,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import uuid
|
||||
import hashlib
|
||||
import logging
|
||||
|
||||
from django.db import models
|
||||
|
||||
from seahub.base.fields import LowerCaseCharField
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
########## Manager
|
||||
class FileUUIDMapManager(models.Manager):
|
||||
|
0
tests/seahub/tags/__init__.py
Normal file
0
tests/seahub/tags/__init__.py
Normal file
0
tests/seahub/tags/models/__init__.py
Normal file
0
tests/seahub/tags/models/__init__.py
Normal file
31
tests/seahub/tags/models/test_file_uuidmap_manager.py
Normal file
31
tests/seahub/tags/models/test_file_uuidmap_manager.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from seahub.tags.models import FileUUIDMap
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
from seaserv import seafile_api
|
||||
|
||||
|
||||
class FileUUIDMapManagerTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.login_as(self.user)
|
||||
self.repo = seafile_api.get_repo(self.create_repo(name='test-repo', desc='',
|
||||
username=self.user.username,
|
||||
passwd=None))
|
||||
|
||||
def test_get_fileuuid_by_uuid(self):
|
||||
args = (self.repo.id, '/', 'dev', True)
|
||||
uuid_obj = FileUUIDMap.objects.get_or_create_fileuuidmap(*args)
|
||||
uuidmap_obj = FileUUIDMap.objects.get_fileuuidmap_by_uuid(uuid_obj.uuid)
|
||||
assert uuid_obj == uuidmap_obj
|
||||
|
||||
def test_create(self):
|
||||
args = (self.repo.id, '/', 'dev_create', True)
|
||||
uuidmap_obj = FileUUIDMap.objects.get_or_create_fileuuidmap(*args)
|
||||
data = (uuidmap_obj.repo_id, uuidmap_obj.parent_path, uuidmap_obj.filename, uuidmap_obj.is_dir)
|
||||
assert args == data
|
||||
|
||||
def test_file_uuidmap_by_path(self):
|
||||
args = (self.repo.id, '/', 'dev_by_path', True)
|
||||
assert None == FileUUIDMap.objects.get_fileuuidmap_by_path(*args)
|
||||
uuidmap_obj = FileUUIDMap.objects.get_or_create_fileuuidmap(*args)
|
||||
assert uuidmap_obj == FileUUIDMap.objects.get_fileuuidmap_by_path(*args)
|
||||
|
42
tests/seahub/tags/models/test_filetag_manager.py
Normal file
42
tests/seahub/tags/models/test_filetag_manager.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from seahub.tags.models import FileTag, FileUUIDMap
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
from seaserv import seafile_api
|
||||
|
||||
|
||||
class FileTagManagerTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.login_as(self.user)
|
||||
self.repo = seafile_api.get_repo(self.create_repo(name='test-repo', desc='',
|
||||
username=self.user.username,
|
||||
passwd=None))
|
||||
|
||||
def test_create_file_tag(self):
|
||||
args = (self.repo.id, '/', 'q.q', True, 'test_tag', self.user.username)
|
||||
data = FileTag.objects.get_or_create_file_tag(*args)
|
||||
assert ('test_tag', True) == (data[0].tag.name, data[1])
|
||||
data = FileTag.objects.get_or_create_file_tag(*args)
|
||||
assert ('test_tag', False) == (data[0].tag.name, data[1])
|
||||
|
||||
def test_exists_filetag(self):
|
||||
uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(self.repo.id, '/', 'q.q', True)
|
||||
data = FileTag.objects.exists_filetag(uuid, 'test_exists')
|
||||
assert (None, False) == data
|
||||
data = FileTag.objects.get_or_create_file_tag(self.repo.id, '/', 'q.q', True, 'test_exists', self.user.username)
|
||||
data = FileTag.objects.exists_filetag(uuid, 'test_exists')
|
||||
assert ('test_exists', True) == (data[0].tag.name, True)
|
||||
|
||||
def test_get_all_file_tag_by_path(self):
|
||||
data = FileTag.objects.get_or_create_file_tag(self.repo.id, '/', 'q.2', True, 'test_get_all', self.user.username)
|
||||
assert data[0].tag.name in [e.tag.name for e in FileTag.objects.get_all_file_tag_by_path(self.repo.id, '/', 'q.2', True)]
|
||||
|
||||
def test_delete_one(self):
|
||||
args = (self.repo.id, '/', 'q.q', True, 'test_tag', self.user.username)
|
||||
del_args = (self.repo.id, '/', 'q.q', True, 'test_tag')
|
||||
data = FileTag.objects.get_or_create_file_tag(*args)
|
||||
assert FileTag.objects.delete_file_tag_by_path(*del_args)
|
||||
|
||||
def test_delete_all(self):
|
||||
data = FileTag.objects.get_or_create_file_tag(self.repo.id, '/', 'q.3', True, 'test_get_all', self.user.username)
|
||||
FileTag.objects.delete_all_filetag_by_path(self.repo.id, '/', 'q.3', True)
|
||||
assert data[0].tag.name not in [e.tag.name for e in FileTag.objects.get_all_file_tag_by_path(self.repo.id, '/', 'q.3', True)]
|
10
tests/seahub/tags/models/test_tags_manager.py
Normal file
10
tests/seahub/tags/models/test_tags_manager.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from seahub.tags.models import Tags
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
|
||||
class TagsManagerTest(BaseTestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test_create_tag(self):
|
||||
assert 'a' == Tags.objects.get_or_create_tag('a').name
|
Reference in New Issue
Block a user