class GetBlogPostsTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() FullBlogSetup(self.env).upgrade_environment(self.env.get_db_cnx()) def tearDown(self): self.env.destroy_db() del self.env def test_get_by_category(self): bp = BlogPost(self.env, 'one') bp.update_fields({'title': 'one', 'body': 'body', 'author': 'user', 'categories': 'about stuff'}) self.assertEquals([], bp.save('user')) posts = get_blog_posts(self.env) self.assertEquals(1, len(posts)) self.assertEquals('one', posts[0][0]) posts = get_blog_posts(self.env, category='non-existing') self.assertEquals(0, len(posts)) posts = get_blog_posts(self.env, category='stuff') self.assertEquals(1, len(posts)) self.assertEquals('one', posts[0][0]) self.assertEquals(get_blog_posts(self.env, category='about'), get_blog_posts(self.env, category='stuff'))
class GetTestPlans(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() QaSetup(self.env).upgrade_environment(self.env.get_db_cnx()) cnx = self.env.get_db_cnx() cursor = cnx.cursor() sql = "INSERT INTO qa_testsuite(title, description) VALUES (%s, %s)" cursor.execute(sql, ['tata', 'tete']) cnx.commit() def tearDown(self): self.env.destroy_db() del self.env #def test_find_testplans(self): # dummy = TestPlan( { 'title' : 'toto title', 'description' : 'toto descr'}) # dummy.title = 'test title' # dummy.description = 'test description' # dummy.save(self.env) # self.assertEquals(dummy.tpid, 0) @unittest.skip("demonstrating skipping") def test_get_testsuites(self): res = TestSuite.find(self.env, fields=['title', 'description']) self.assertEquals(len(res), 1) def test_invalid_testcase_shows_error(self): tc = TestCase() tc.description = 'test' errors = tc.is_valid() self.assertEquals(len(errors), 1)
class GetBlogPostsTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() if hasattr(self.env, 'db_transaction'): with self.env.db_transaction as db: FullBlogSetup(self.env).upgrade_environment(db) else: FullBlogSetup(self.env).upgrade_environment(self.env.get_db_cnx()) def tearDown(self): self.env.destroy_db() del self.env def test_get_by_category(self): bp = BlogPost(self.env, 'one') bp.update_fields({ 'title': 'one', 'body': 'body', 'author': 'user', 'categories': 'about stuff' }) self.assertEquals([], bp.save('user')) posts = get_blog_posts(self.env) self.assertEquals(1, len(posts)) self.assertEquals('one', posts[0][0]) posts = get_blog_posts(self.env, category='non-existing') self.assertEquals(0, len(posts)) posts = get_blog_posts(self.env, category='stuff') self.assertEquals(1, len(posts)) self.assertEquals('one', posts[0][0]) self.assertEquals(get_blog_posts(self.env, category='about'), get_blog_posts(self.env, category='stuff'))
class GetBlogPostsTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() if hasattr(self.env, "db_transaction"): with self.env.db_transaction as db: FullBlogSetup(self.env).upgrade_environment(db) else: FullBlogSetup(self.env).upgrade_environment(self.env.get_db_cnx()) def tearDown(self): self.env.destroy_db() del self.env def test_get_by_category(self): bp = BlogPost(self.env, "one") bp.update_fields({"title": "one", "body": "body", "author": "user", "categories": "about stuff"}) self.assertEquals([], bp.save("user")) posts = get_blog_posts(self.env) self.assertEquals(1, len(posts)) self.assertEquals("one", posts[0][0]) posts = get_blog_posts(self.env, category="non-existing") self.assertEquals(0, len(posts)) posts = get_blog_posts(self.env, category="stuff") self.assertEquals(1, len(posts)) self.assertEquals("one", posts[0][0]) self.assertEquals(get_blog_posts(self.env, category="about"), get_blog_posts(self.env, category="stuff"))
class GroupPostsByMonthTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() FullBlogSetup(self.env).upgrade_environment(self.env.get_db_cnx()) def tearDown(self): self.env.destroy_db() del self.env def test_many_posts(self): # 2 posts in one period one = BlogPost(self.env, 'one') one.update_fields({'title': 'one', 'body': 'body', 'author': 'user'}) self.assertEquals([], one.save('user')) two = BlogPost(self.env, 'two') two.update_fields({'title': 'two', 'body': 'body', 'author': 'user'}) self.assertEquals([], two.save('user')) grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals(1, len(grouped)) # Add 1 post in another period three = BlogPost(self.env, 'three') three.update_fields({'title': 'three', 'body': 'body', 'author': 'user', 'publish_time': three.publish_time - datetime.timedelta(days=-100)}) self.assertEquals([], three.save('user')) grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals(2, len(grouped)) self.assertEquals(1, len(grouped[0][1])) self.assertEquals(2, len(grouped[1][1])) self.assertEquals(type(grouped[0][0]), datetime.datetime) self.assertEquals((one.name, one.version, one.publish_time, one.author, one.title, one.body, []), grouped[1][1][0]) def test_no_posts(self): grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals([], grouped)
def destroy(self): """Remove all of the test environment data.""" env = EnvironmentStub(path=self.tracdir, destroying=True) env.destroy_db() self.destroy_repo() if os.path.exists(self.dirname): rmtree(self.dirname)
def destroy(self): """Remove all of the test environment data.""" env = EnvironmentStub() env.destroy_db() env.shutdown() self.destroy_repo() if os.path.exists(self.dirname): rmtree(self.dirname)
class CustomFieldApiTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() self.cf_api = CustomFields(self.env) def tearDown(self): if hasattr(self.env, "destroy_db"): self.env.destroy_db() del self.env def test_systeminfo(self): try: from trac.loader import get_plugin_info # From ~0.12, Trac handles plugins and versions - no need to test return except ImportError: self.assertTrue( ("CustomFieldAdmin", __import__("customfieldadmin", ["__version__"]).__version__) in self.env.systeminfo ) def test_create(self): for f in ["one", "two", "three"]: cfield = {"name": f, "type": "text"} self.cf_api.create_custom_field(cfield) self.assertEquals( self.cf_api.get_custom_fields(), [ {"name": u"one", "format": "plain", "value": "", "label": u"One", "type": u"text", "order": 1}, {"name": u"two", "format": "plain", "value": "", "label": u"Two", "type": u"text", "order": 2}, {"name": u"three", "format": "plain", "value": "", "label": u"Three", "type": u"text", "order": 3}, ], ) def test_update(self): cfield = {"name": "foo", "type": "text"} self.cf_api.create_custom_field(cfield) self.assertEquals( cfield, {"name": u"foo", "format": "plain", "value": "", "label": u"Foo", "type": u"text", "order": 1} ) cfield["label"] = "Answer" cfield["value"] = "42" self.cf_api.update_custom_field(cfield=cfield) self.assertEquals( cfield, {"name": u"foo", "format": "plain", "value": "42", "label": u"Answer", "type": u"text", "order": 1} ) def test_update_non_existing(self): try: self.cf_api.update_custom_field(cfield={"name": "no_field"}) self.fail("Huh. Missing exception!") except Exception, e: self.assertTrue("'no_field'" in e.message) self.assertTrue("does not exist" in e.message)
class FullBlogTestCaseTemplate(TestCase): def setUp(self): self.env = EnvironmentStub(enable=['trac.*', 'tracfullblog.*']) FullBlogSetup(self.env).upgrade_environment() # permissions self.env.config.set('trac', 'permission_store', 'DefaultPermissionStore') self.env.config.set('trac', 'permission_policies', 'DefaultPermissionPolicy') def tearDown(self): self.env.destroy_db() del self.env
class GetTestPlans(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() QaSetup(self.env).upgrade_environment(self.env.get_db_cnx()) def tearDown(self): self.env.destroy_db() del self.env def test_save(self): # 2 posts in one period testplan = TestPlan(self.env) testplan.title = "test" testplan.description = "test" testplan.save() self.assertEquals([], tesplan.tpid)
class GroupPostsByMonthTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() if hasattr(self.env, 'db_transaction'): with self.env.db_transaction as db: FullBlogSetup(self.env).upgrade_environment(db) else: FullBlogSetup(self.env).upgrade_environment(self.env.get_db_cnx()) def tearDown(self): self.env.destroy_db() del self.env def test_many_posts(self): # 2 posts in one period one = BlogPost(self.env, 'one') one.update_fields({'title': 'one', 'body': 'body', 'author': 'user'}) self.assertEquals([], one.save('user')) two = BlogPost(self.env, 'two') two.update_fields({'title': 'two', 'body': 'body', 'author': 'user'}) self.assertEquals([], two.save('user')) grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals(1, len(grouped)) # Add 1 post in another period three = BlogPost(self.env, 'three') three.update_fields({ 'title': 'three', 'body': 'body', 'author': 'user', 'publish_time': three.publish_time - datetime.timedelta(days=-100) }) self.assertEquals([], three.save('user')) grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals(2, len(grouped)) self.assertEquals(1, len(grouped[0][1])) self.assertEquals(2, len(grouped[1][1])) self.assertEquals(type(grouped[0][0]), datetime.datetime) self.assertEquals((one.name, one.version, one.publish_time, one.author, one.title, one.body, []), grouped[1][1][0]) def test_no_posts(self): grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals([], grouped)
class GroupPostsByMonthTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() if hasattr(self.env, "db_transaction"): with self.env.db_transaction as db: FullBlogSetup(self.env).upgrade_environment(db) else: FullBlogSetup(self.env).upgrade_environment(self.env.get_db_cnx()) def tearDown(self): self.env.destroy_db() del self.env def test_many_posts(self): # 2 posts in one period one = BlogPost(self.env, "one") one.update_fields({"title": "one", "body": "body", "author": "user"}) self.assertEquals([], one.save("user")) two = BlogPost(self.env, "two") two.update_fields({"title": "two", "body": "body", "author": "user"}) self.assertEquals([], two.save("user")) grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals(1, len(grouped)) # Add 1 post in another period three = BlogPost(self.env, "three") three.update_fields( { "title": "three", "body": "body", "author": "user", "publish_time": three.publish_time - datetime.timedelta(days=-100), } ) self.assertEquals([], three.save("user")) grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals(2, len(grouped)) self.assertEquals(1, len(grouped[0][1])) self.assertEquals(2, len(grouped[1][1])) self.assertEquals(type(grouped[0][0]), datetime.datetime) self.assertEquals( (one.name, one.version, one.publish_time, one.author, one.title, one.body, []), grouped[1][1][0] ) def test_no_posts(self): grouped = group_posts_by_month(get_blog_posts(self.env)) self.assertEquals([], grouped)
class FullBlogTestCaseTemplate(TestCase): def setUp(self): self.env = EnvironmentStub(enable=['trac.*', 'tracfullblog.*']) # tables if hasattr(self.env, 'db_transaction'): with self.env.db_transaction as db: FullBlogSetup(self.env).upgrade_environment(db) else: FullBlogSetup(self.env).upgrade_environment(self.env.get_db_cnx()) # permissions self.env.config.set('trac', 'permission_store', 'DefaultPermissionStore') self.env.config.set('trac', 'permission_policies', 'DefaultPermissionPolicy') def tearDown(self): self.env.destroy_db() del self.env
class CustomFieldAdminPageTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() ps = PermissionSystem(self.env) ps.grant_permission('admin', 'TICKET_ADMIN') self.plugin = CustomFieldAdminPage(self.env) self.api = CustomFields(self.env) def tearDown(self): if hasattr(self.env, 'destroy_db'): self.env.destroy_db() del self.env def test_create(self): _redirect_url = '' def redirect(url): _redirect_url = url raise RequestDone req = Mock(perm=PermissionCache(self.env, 'admin'), authname='admin', chrome={}, href=Href('/'), redirect=redirect, method='POST', args={ 'add': True, 'name': "test", 'type': "textarea", 'label': "testing", 'format': "wiki", 'row': '9', 'columns': '42' }) try: self.plugin.render_admin_panel(req, 'ticket', 'customfields', None) except RequestDone, e: self.assertEquals( sorted(list(self.env.config.options('ticket-custom'))), [(u'test', u'textarea'), (u'test.cols', u'60'), (u'test.format', u'wiki'), (u'test.label', u'testing'), (u'test.options', u''), (u'test.order', u'1'), (u'test.rows', u'5'), (u'test.value', u'')])
class CustomFieldAdminPageTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() ps = PermissionSystem(self.env) ps.grant_permission('admin', 'TICKET_ADMIN') self.plugin = CustomFieldAdminPage(self.env) def tearDown(self): if hasattr(self.env, 'destroy_db'): self.env.destroy_db() del self.env def test_create(self): _redirect_url = '' def redirect(url): _redirect_url = url raise RequestDone req = Mock(perm=PermissionCache(self.env, 'admin'), authname='admin', chrome={}, href=Href('/'), redirect=redirect, method='POST', args={'add': True, 'name': "test", 'type': "textarea", 'label': "testing", 'format': "wiki", 'row': '9', 'columns': '42'}) try: self.plugin.render_admin_panel(req, 'ticket', 'customfields', None) except RequestDone, e: self.assertEquals( sorted(list(self.env.config.options('ticket-custom'))), [(u'test', u'textarea'), (u'test.cols', u'60'), (u'test.format', u'wiki'), (u'test.label', u'testing'), (u'test.options', u''), (u'test.order', u'1'), (u'test.rows', u'5'), (u'test.value', u'')])
class CustomFieldL10NTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() self.cf_api = CustomFields(self.env) def tearDown(self): if hasattr(self.env, 'destroy_db'): self.env.destroy_db() del self.env def test_translation_function(self): from customfieldadmin.api import _ self.assertEquals('foo bar', _("foo bar")) self.assertEquals('foo bar', _("foo %(bar)s", bar='bar')) def test_translation_function_tag(self): from customfieldadmin.api import tag_ from genshi.builder import tag self.assertEquals('<p>foo bar</p>', str(tag_(tag.p('foo bar')))) self.assertEquals('<p>foo bar</p>', str(tag_(tag.p('foo %(bar)s' % {'bar': 'bar'}))))
class CustomFieldL10NTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() self.cf_api = CustomFields(self.env) def tearDown(self): if hasattr(self.env, "destroy_db"): self.env.destroy_db() del self.env def test_translation_function(self): from customfieldadmin.api import _ self.assertEquals("foo bar", _("foo bar")) self.assertEquals("foo bar", _("foo %(bar)s", bar="bar")) def test_translation_function_tag(self): from customfieldadmin.api import tag_ from genshi.builder import tag self.assertEquals("<p>foo bar</p>", str(tag_(tag.p("foo bar")))) self.assertEquals("<p>foo bar</p>", str(tag_(tag.p("foo %(bar)s" % {"bar": "bar"}))))
class CustomFieldApiTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() self.cf_api = CustomFields(self.env) def tearDown(self): if hasattr(self.env, 'destroy_db'): self.env.destroy_db() del self.env def test_systeminfo(self): try: from trac.loader import get_plugin_info # From ~0.12, Trac handles plugins and versions - no need to test return except ImportError: self.assertTrue(('CustomFieldAdmin', __import__('customfieldadmin', ['__version__']).__version__) \ in self.env.systeminfo) def test_create(self): for f in ['one', 'two', 'three']: cfield = {'name': f, 'type': 'text'} self.cf_api.create_custom_field(cfield) self.assertEquals(self.cf_api.get_custom_fields(), [{'name': u'one', 'format': 'plain', 'value': '', 'label': u'One', 'type': u'text', 'order': 1}, {'name': u'two', 'format': 'plain', 'value': '', 'label': u'Two', 'type': u'text', 'order': 2}, {'name': u'three', 'format': 'plain', 'value': '', 'label': u'Three', 'type': u'text', 'order': 3}]) def test_update(self): cfield = {'name': 'foo', 'type': 'text'} self.cf_api.create_custom_field(cfield) self.assertEquals(cfield, {'name': u'foo', 'format': 'plain', 'value': '', 'label': u'Foo', 'type': u'text', 'order': 1}) cfield['label'] = 'Answer' cfield['value'] = '42' self.cf_api.update_custom_field(cfield=cfield) self.assertEquals(cfield, {'name': u'foo', 'format': 'plain', 'value': '42', 'label': u'Answer', 'type': u'text', 'order': 1}) def test_update_textarea(self): cfield = {'name': 'foo', 'type': 'textarea'} self.cf_api.create_custom_field(cfield) self.assertEquals(cfield, {'name': u'foo', 'format': 'plain', 'value': '', 'label': u'Foo', 'type': u'textarea', 'order': 1, 'cols': 60, 'rows': 5}) cfield['cols'] = 42 cfield['rows'] = 3 self.cf_api.update_custom_field(cfield=cfield) self.assertEquals(cfield, {'name': u'foo', 'format': 'plain', 'value': '', 'label': u'Foo', 'type': u'textarea', 'order': 1, 'cols': 42, 'rows': 3}) def test_update_non_existing(self): try: self.cf_api.update_custom_field(cfield={'name': 'no_field'}) self.fail("Huh. Missing exception!") except Exception, e: self.assertTrue("'no_field'" in e.message) self.assertTrue('does not exist' in e.message)