Child: [f64061] (diff)

Download this file

test_search.py    64 lines (53 with data), 1.9 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
import os
import mock
from pylons import c, g, request
from webob import Request
from ming.orm.ormsession import ThreadLocalORMSession
from allura import model as M
from allura.lib import search
from allura.lib import helpers as h
from allura.command import reactor
from allura.ext.search import search_main
from allura.lib.app_globals import Globals
from forgewiki import model as WM
from . import helpers
def setUp():
helpers.setup_basic_test()
helpers.setup_global_objects()
def test_index_artifact():
a = WM.Page.query.find().first()
search.add_artifacts([a])
search.solarize(a)
a.text = None
search.remove_artifacts([a])
g.solr.add([search.solarize(a)])
r = search.search('WikiPage')
assert r.hits == 1
r = search.search_artifact(WM.Page, 'title:"WikiPage Home"')
assert r.hits == 1
r = search.search_artifact(WM.Page, 'title:"Home"')
assert r.hits == 0
def test_searchapp():
h.set_context('test', 'wiki')
a = WM.Page.query.find().first()
a.text = '\n[Home]\n'
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
g.mock_amq.setup_handlers()
g.publish('react', 'artifacts_altered', dict(project_id=a.project_id,
mount_point=a.app_config.options.mount_point,
artifacts=[a.dump_ref()]))
g.mock_amq.handle_all()
a = WM.Page.query.find().first()
assert len(a.references) == 1
assert len(a.backreferences) == 1
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
g.mock_amq.handle_all()
g.publish('react', 'artifacts_removed', dict(project_id=a.project_id,
mount_point=a.app_config.options.mount_point,
artifacts=[a.dump_ref()]))
g.mock_amq.handle_all()
a = WM.Page.query.find().first()
assert len(a.references) == 1
assert len(a.backreferences) == 0