import os
import shutil
import tempfile
import commands
from StringIO import StringIO
import twill
from twill import commands as web
import annotater.model
annotater.model.set_default_connection()
import annotater.store
class TestMapper:
store = annotater.store.AnnotaterStore()
map = store.get_routes_mapper()
def test_match_double_slash(self):
# demonstrate that double slashes mess things up!
self.map.environ = { 'REQUEST_METHOD' : 'GET' }
out = self.map.match('//annotation/')
assert out == None
# assert out['action'] == 'index'
def test_match_new(self):
self.map.environ = { 'REQUEST_METHOD' : 'GET' }
out = self.map.match('/annotation/new')
assert out['action'] == 'new'
def test_match_index(self):
self.map.environ = { 'REQUEST_METHOD' : 'GET' }
out = self.map.match('/annotation')
assert out['action'] == 'index'
def test_match_create(self):
self.map.environ = { 'REQUEST_METHOD' : 'POST' }
out = self.map.match('/annotation')
assert out['action'] == 'create'
def test_match_delete(self):
self.map.environ = { 'REQUEST_METHOD' : 'GET' }
out = self.map.match('/annotation/delete/1')
assert out['action'] == 'delete'
assert out['id'] == '1'
self.map.environ = { 'REQUEST_METHOD' : 'DELETE' }
out = self.map.match('/annotation/1')
assert out['action'] == 'delete'
assert out['id'] == '1'
out = self.map.match('/annotation/')
assert out['id'] == None
def test_match_edit(self):
self.map.environ = { 'REQUEST_METHOD' : 'GET' }
out = self.map.match('/annotation/edit/1')
assert out['action'] == 'edit'
assert out['id'] == '1'
self.map.environ = { 'REQUEST_METHOD' : 'PUT' }
out = self.map.match('/annotation/1')
assert out['action'] == 'update'
assert out['id'] == '1'
self.map.environ = { 'REQUEST_METHOD' : 'POST' }
out = self.map.match('/annotation/1')
assert out['action'] == 'update'
def test_url_for_new(self):
offset = self.map.generate(controller='annotation', action='new')
exp = '/annotation/new'
assert offset == exp
def test_url_for_create(self):
offset = self.map.generate(controller='annotation', action='create',
method='POST' )
exp = '/annotation'
assert offset == exp
def test_url_for_delete(self):
offset = self.map.generate(controller='annotation',
action='delete', id=1, method='GET' )
exp = '/annotation/delete/1'
assert offset == exp
offset = self.map.generate(controller='annotation',
action='delete', id=1, method='DELETE' )
exp = '/annotation/1'
assert offset == exp
def test_url_for_edit(self):
offset = self.map.generate(controller='annotation',
action='edit', id=1, method='GET')
exp = '/annotation/edit/1'
assert offset == exp
class TestStatic:
def test__make_annotate_form(self):
app = annotater.store.AnnotaterStore()
defaults = { 'url' : 'http://www.blackandwhite.com' }
out = app._make_annotate_form(form_name='formname', action_url='.',
form_defaults=defaults)
exp1 = '
' % defaults['url']
assert exp1 in out
class TestAnnotaterStore:
store = annotater.store.AnnotaterStore()
map = store.get_routes_mapper()
def setup_method(self, name=''):
twill.add_wsgi_intercept('localhost', 8080, lambda : self.store)
self.outp = StringIO()
twill.set_output(self.outp)
self.siteurl = 'http://localhost:8080/'
def teardown_method(self, name=''):
# remove intercept.
twill.remove_wsgi_intercept('localhost', 8080)
def test_annotate_get(self):
anno = self._create_annotation()
offset = self.map.generate(controller='annotation', action='index')
url = self.siteurl + offset[1:]
web.go(url)
web.code(200)
web.find(anno.url)
web.find(anno.range)
def test_annotate_get_atom(self):
anno = self._create_annotation()
offset = self.map.generate(controller='annotation', action='index')
url = self.siteurl + offset[1:] + '?format=atom'
web.go(url)
web.code(200)
web.find(anno.note)
web.find(anno.range)
out = web.show()
exp1 = '