Commit a364bcda authored by Ryan Herbert's avatar Ryan Herbert
Browse files

tests/{controllers,models}/tag.py testRunner.py add tests for tags

parent 5669264b
#!/usr/bin/python
import unittest
from gluon.globals import Request, Session, Storage, Response
from gluon.contrib.test_helpers import form_postvars
from gluon import current
class TagController(unittest.TestCase):
def __init__(self, p):
global auth, session, request
unittest.TestCase.__init__(self, p)
def setUp(self):
# Load the to-be-tested file
execfile("applications/vidjil/controllers/tag.py", globals())
# set up default session/request/auth/...
global response, session, request, auth
session = Session()
request = Request({})
auth = VidjilAuth(globals(), db)
auth.login_bare("test@vidjil.org", "1234")
# rewrite info / error functions
# for some reasons we lost them between the testRunner and the testCase but we need them to avoid error so ...
def f(a, **kwargs):
pass
log.info = f
log.error = f
log.debug = f
# for defs
current.db = db
current.auth = auth
def test_auto_complete(self):
resp = auto_complete()
self.assertNotEqual(resp.find("missing group ids"), -1, "auto_complete did not fail correctly")
request.vars["group_ids"] = "[]"
resp = auto_complete()
self.assertEqual(resp.find("missing group ids"), -1, "auto_complete failed to detect group_ids param")
self.assertEqual(resp, "{}", "auto_complete returned an unexpected response")
request.vars["group_ids"] = "[%d,%d]" % (unique_group, fake_group_id)
resp = auto_complete()
json_resp = json.loads(resp)
self.assertTrue(json_resp.has_key(str(unique_group)), "missing tag for unique_group: %s" % unique_group)
tag = json_resp[str(int(unique_group))][0]
self.assertEqual(tag["name"], 'first_fake_tag')
#!/usr/bin/python
import unittest
class TagModel (unittest.TestCase):
def __init__(self, p):
global auth, session, request
unittest.TestCase.__init__(self, p)
def setUp(self):
# Load the to-be-tested file
execfile("applications/vidjil/models/tag.py", globals())
def test_register_tags(self):
text = "this text contains a #tag"
table_name = 'patient'
register_tags(db, table_name, fake_patient_id, text, fake_group_id)
tag = db(db.tag.name == 'tag').select().first()
refs = db((db.tag_ref.table_name == table_name) &
(db.tag_ref.record_id == fake_patient_id) &
(db.tag_ref.tag_id == tag.id)
).select()
self.assertTrue(len(refs) == 1, 'incorrect number of tags match this description')
def test_tags_to_json(self):
tags = get_tags(db, [unique_group, fake_group_id])
json_tags = tags_to_json(tags)
tag_dict = json.loads(json_tags)
self.assertTrue(tag_dict.has_key(str(unique_group)), "tag_dict missing key unique_group: %d" % unique_group)
self.assertTrue(tag_dict.has_key(str(fake_group_id)), "tag_dict missing key unique_group: %d" % unique_group)
self.assertTrue(len(tag_dict[str(unique_group)]) > 0, "missing tags for unique_group: %d" % unique_group)
def test_parse_search(self):
prefix = get_tag_prefix()
search_string = "%stags and a search %sswag" % (prefix, prefix)
search, tags = parse_search(search_string)
self.assertEqual(search, "and a search", "incorrect search terms extracted")
self.assertTrue("tags" in tags, "the tag 'tags' was not detected")
self.assertTrue("swag" in tags, "the tag 'swag' was not detected")
......@@ -230,6 +230,13 @@ fake_mail_preference_id = db.user_preference.insert(user_id =user_id,
fake_task_id = db.scheduler_task.insert(application_name='vidjil_test',
task_name='test_task')
first_fake_tag_id = db.tag.insert(name="first_fake_tag")
sec_fake_tag_id = db.tag.insert(name="sec_fake_tag")
db.group_tag.insert(group_id=unique_group, tag_id=first_fake_tag_id)
db.group_tag.insert(group_id=fake_group_id, tag_id=sec_fake_tag_id)
db.commit()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment