Parent: [68ed96] (diff)

Download this file

test_app.py    59 lines (48 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
# -*- coding: utf-8 -*-
# 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.
#-*- python -*-
import tempfile
import json
from nose.tools import assert_equal
from pylons import tmpl_context as c
from allura import model as M
from forgediscussion.tests.functional.test_rest import TestDiscussionApiBase
class TestBulkExport(TestDiscussionApiBase):
def test_bulk_export(self):
# Clear out some context vars, to properly simulate how this is run from the export task
# Besides, it's better not to need c context vars
c.app = c.project = None
project = M.Project.query.get(shortname='test')
discussion = project.app_instance('discussion')
f = tempfile.TemporaryFile()
discussion.bulk_export(f)
f.seek(0)
discussion = json.loads(f.read())
forums = sorted(discussion['forums'], key=lambda x: x['name'])
assert_equal(forums[0]['shortname'], u'general')
assert_equal(forums[0]['description'], u'Forum about anything you want to talk about.')
assert_equal(forums[0]['name'], u'General Discussion')
forums[0]['threads'] = sorted(forums[0]['threads'],
key=lambda x: x['posts'][0]['subject'])
assert_equal(forums[0]['threads'][0]['posts'][0]['text'], u'Hi boys and girls')
assert_equal(forums[0]['threads'][0]['posts'][0]['subject'], u'Hi guys')
assert_equal(forums[0]['threads'][1]['posts'][0]['text'], u'1st post')
assert_equal(forums[0]['threads'][1]['posts'][0]['subject'], u"Let's talk")
assert_equal(forums[1]['shortname'], u'h��llo')
assert_equal(forums[1]['description'], u'Say h��llo here')
assert_equal(forums[1]['name'], u'Say H��llo')