Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
喜羊羊3508
Dak
提交
b330cb76
D
Dak
项目概览
喜羊羊3508
/
Dak
10 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dak
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b330cb76
编写于
1月 19, 2011
作者:
T
Torsten Werner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extend PackageTestCase.
Signed-off-by:
N
Torsten Werner
<
twerner@debian.org
>
上级
dbf51c0e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
26 deletion
+36
-26
daklib/dbconn.py
daklib/dbconn.py
+13
-25
tests/dbtest_packages.py
tests/dbtest_packages.py
+23
-1
未找到文件。
daklib/dbconn.py
浏览文件 @
b330cb76
...
...
@@ -1084,13 +1084,16 @@ class PoolFile(object):
def fullpath(self):
return os.path.join(self.location.path, self.filename)
def is_valid(self, filesize = -1, md5sum = None):
\
return self.filesize == filesize and self.md5sum == md5sum
__all__.append('PoolFile')
@session_wrapper
def check_poolfile(filename, filesize, md5sum, location_id, session=None):
"""
Returns a tuple:
(ValidFileFound [boolean
or None
], PoolFile object or None)
(ValidFileFound [boolean], PoolFile object or None)
@type filename: string
@param filename: the filename of the file to check against the DB
...
...
@@ -1106,34 +1109,24 @@ def check_poolfile(filename, filesize, md5sum, location_id, session=None):
@rtype: tuple
@return: Tuple of length 2.
- If more than one file found with that name: (C{None}, C{None})
- If valid pool file found: (C{True}, C{PoolFile object})
- If valid pool file not found:
- (C{False}, C{None}) if no file found
- (C{False}, C{PoolFile object}) if file found with size/md5sum mismatch
"""
q = session.query(PoolFile).filter_by(filename=filename)
q = q.join(Location).filter_by(location_id=location_id)
ret = None
if q.count() > 1:
ret = (None, None)
elif q.count() < 1:
ret = (False, None)
else:
obj = q.one()
if obj.md5sum != md5sum or obj.filesize != int(filesize):
ret = (False, obj)
if ret is None:
ret = (True, obj)
poolfile = session.query(Location).get(location_id).
\
files.filter_by(filename=filename).first()
valid = False
if poolfile and poolfile.is_valid(filesize = filesize, md5sum = md5sum):
valid = True
return
ret
return
(valid, poolfile)
__all__.append('check_poolfile')
# TODO: the implementation can trivially be inlined at the place where the
# function is called
@session_wrapper
def get_poolfile_by_id(file_id, session=None):
"""
...
...
@@ -1146,12 +1139,7 @@ def get_poolfile_by_id(file_id, session=None):
@return: either the PoolFile object or None
"""
q = session.query(PoolFile).filter_by(file_id=file_id)
try:
return q.one()
except NoResultFound:
return None
return session.query(PoolFile).get(file_id)
__all__.append('get_poolfile_by_id')
...
...
tests/dbtest_packages.py
浏览文件 @
b330cb76
...
...
@@ -3,7 +3,8 @@
from
db_test
import
DBDakTestCase
from
daklib.dbconn
import
Architecture
,
Suite
,
get_suite_architectures
,
\
get_architecture_suites
,
Maintainer
,
DBSource
,
Location
,
PoolFile
get_architecture_suites
,
Maintainer
,
DBSource
,
Location
,
PoolFile
,
\
check_poolfile
,
get_poolfile_like_name
import
unittest
...
...
@@ -129,6 +130,11 @@ class PackageTestCase(DBDakTestCase):
filter
(
PoolFile
.
filename
.
like
(
'%/hello/hello%'
)).
one
()
self
.
assertEqual
(
'main/h/hello/hello_2.2-2.dsc'
,
poolfile
.
filename
)
self
.
assertEqual
(
location
,
poolfile
.
location
)
# test get()
self
.
assertEqual
(
poolfile
,
\
self
.
session
.
query
(
PoolFile
).
get
(
poolfile
.
file_id
))
self
.
assertEqual
(
None
,
self
.
session
.
query
(
PoolFile
).
get
(
-
1
))
# test remove() and append()
location
.
files
.
remove
(
self
.
file
[
'sl'
])
# TODO: deletion should cascade automatically
self
.
session
.
delete
(
self
.
file
[
'sl'
])
...
...
@@ -143,6 +149,22 @@ class PackageTestCase(DBDakTestCase):
# test fullpath
self
.
assertEqual
(
'/srv/ftp-master.debian.org/ftp/pool/main/s/sl/sl_3.03-16.dsc'
,
\
self
.
file
[
'sl'
].
fullpath
)
# test check_poolfile()
self
.
assertEqual
((
True
,
self
.
file
[
'sl'
]),
\
check_poolfile
(
'main/s/sl/sl_3.03-16.dsc'
,
0
,
''
,
\
location
.
location_id
,
self
.
session
))
self
.
assertEqual
((
False
,
None
),
\
check_poolfile
(
'foobar'
,
0
,
''
,
location
.
location_id
,
self
.
session
))
self
.
assertEqual
((
False
,
self
.
file
[
'sl'
]),
\
check_poolfile
(
'main/s/sl/sl_3.03-16.dsc'
,
42
,
''
,
\
location
.
location_id
,
self
.
session
))
self
.
assertEqual
((
False
,
self
.
file
[
'sl'
]),
\
check_poolfile
(
'main/s/sl/sl_3.03-16.dsc'
,
0
,
'deadbeef'
,
\
location
.
location_id
,
self
.
session
))
# test get_poolfile_like_name()
self
.
assertEqual
([
self
.
file
[
'sl'
]],
\
get_poolfile_like_name
(
'sl_3.03-16.dsc'
,
self
.
session
))
self
.
assertEqual
([],
get_poolfile_like_name
(
'foobar'
,
self
.
session
))
def
setup_maintainers
(
self
):
'create some Maintainer objects'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录