Child: [d69cb3] (diff)

Download this file

test_filesystem.py    34 lines (30 with data), 970 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
"""
Model tests for auth
"""
import mock
from pylons import c, g
from ming.orm.ormsession import ThreadLocalORMSession
from allura import model as M
from allura.lib.app_globals import Globals
def setUp():
g._push_object(Globals())
c._push_object(mock.Mock())
ThreadLocalORMSession.close_all()
g.set_project('test')
g.set_app('hello')
M.File.remove({})
c.user = M.User.query.get(username='test-admin')
def test_file():
f = M.File.save('test.txt', 'text/plain', '')
f = M.File.save('test.txt', 'text/plain', 'This is some text')
assert f.filename != 'test.txt'
f1 = M.File.by_metadata(filename='test.txt').one()
assert f1 is f
with M.File.create('text/plain', filename='test1.txt') as fp:
print >> fp, 'This is another file'
assert len(M.File.list()) == 2
with f1.open() as fp:
assert fp.read() == 'This is some text'
f1.delete()
assert len(M.File.list()) == 1