Parent: [2b5c68] (diff)

Child: [9ef3a2] (diff)

Download this file

factories.py    86 lines (65 with data), 2.5 kB

 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from functools import wraps
from ming.orm import ThreadLocalORMSession
from allura.model.project import Project, Neighborhood, AppConfig
from allura.model.auth import User
from allura.model.discuss import Discussion, Thread, Post
def flush_on_return(fn):
@wraps(fn)
def new_fn(*args, **kwargs):
result = fn(*args, **kwargs)
ThreadLocalORMSession.flush_all()
return result
return new_fn
@flush_on_return
def create_project(shortname):
neighborhood = create_neighborhood()
return Project(shortname=shortname,
database_uri='mim://test/myproject_db',
neighborhood_id=neighborhood._id,
is_root=True)
@flush_on_return
def create_neighborhood():
neighborhood = Neighborhood(url_prefix='http://example.com/myproject')
return neighborhood
@flush_on_return
def create_app_config(project, mount_point):
return AppConfig(
project_id=project._id,
tool_name='myapp',
options={'mount_point': 'my_mounted_app'},
acl=[])
@flush_on_return
def create_post(slug):
discussion = create_discussion()
thread = create_thread(discussion=discussion)
author = create_user(username='someguy')
return Post(slug=slug,
thread_id=thread._id,
full_slug='%s:%s' % (thread._id,slug),
discussion_id=discussion._id,
author_id=author._id)
@flush_on_return
def create_thread(discussion):
return Thread.new(discussion_id=discussion._id)
@flush_on_return
def create_discussion():
return Discussion()
@flush_on_return
def create_user(**kw):
return User(**kw)