本文整理汇总了Python中trac.test.EnvironmentStub类的典型用法代码示例。如果您正苦于以下问题:Python EnvironmentStub类的具体用法?Python EnvironmentStub怎么用?Python EnvironmentStub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EnvironmentStub类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: PlatformBuildTestCase
class PlatformBuildTestCase(unittest.TestCase):
"""Tests that involve Builds, TargetPlatforms and BuildSteps"""
def setUp(self):
self.env = EnvironmentStub()
self.env.path = tempfile.mkdtemp()
logs_dir = self.env.config.get("bitten", "logs_dir")
if os.path.isabs(logs_dir):
raise ValueError("Should not have absolute logs directory for temporary test")
logs_dir = os.path.join(self.env.path, logs_dir)
os.makedirs(logs_dir)
db = self.env.get_db_cnx()
cursor = db.cursor()
connector, _ = DatabaseManager(self.env)._get_connector()
for schema in [Build._schema, TargetPlatform._schema, BuildStep._schema]:
for table in schema:
for stmt in connector.to_sql(table):
cursor.execute(stmt)
db.commit()
def test_delete_platform_with_pending_builds(self):
"""Check that deleting a platform with pending builds removes those pending builds"""
db = self.env.get_db_cnx()
platform = TargetPlatform(self.env, config='test', name='Linux')
platform.insert()
build = Build(self.env, config='test', platform=platform.id, rev='42', rev_time=12039)
build.insert()
platform.delete()
pending = list(build.select(self.env, config='test', status=Build.PENDING))
self.assertEqual(0, len(pending))
开发者ID:blaxter,项目名称:Bitten,代码行数:32,代码来源:model.py
示例2: ConnectionTestCase
class ConnectionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.db = self.env.get_db_cnx()
def tearDown(self):
self.env.reset_db()
def test_get_last_id(self):
c = self.db.cursor()
q = "INSERT INTO report (author) VALUES ('anonymous')"
c.execute(q)
# Row ID correct before...
id1 = self.db.get_last_id(c, 'report')
self.assertNotEqual(0, id1)
self.db.commit()
c.execute(q)
self.db.commit()
# ... and after commit()
id2 = self.db.get_last_id(c, 'report')
self.assertEqual(id1 + 1, id2)
def test_update_sequence(self):
cursor = self.db.cursor()
cursor.execute("""
INSERT INTO report (id, author) VALUES (42, 'anonymous')
""")
self.db.commit()
self.db.update_sequence(cursor, 'report', 'id')
self.db.commit()
cursor.execute("INSERT INTO report (author) VALUES ('next-id')")
self.db.commit()
cursor.execute("SELECT id FROM report WHERE author='next-id'")
self.assertEqual(43, cursor.fetchall()[0][0])
开发者ID:zjj,项目名称:trac_hack,代码行数:34,代码来源:api.py
示例3: StringsTestCase
class StringsTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
def test_insert_unicode(self):
self.env.db_transaction(
"INSERT INTO system (name,value) VALUES (%s,%s)",
('test-unicode', u'ünicöde'))
self.assertEqual([(u'ünicöde',)], self.env.db_query(
"SELECT value FROM system WHERE name='test-unicode'"))
def test_insert_empty(self):
from trac.util.text import empty
self.env.db_transaction(
"INSERT INTO system (name,value) VALUES (%s,%s)",
('test-empty', empty))
self.assertEqual([(u'',)], self.env.db_query(
"SELECT value FROM system WHERE name='test-empty'"))
def test_insert_markup(self):
from genshi.core import Markup
self.env.db_transaction(
"INSERT INTO system (name,value) VALUES (%s,%s)",
('test-markup', Markup(u'<em>märkup</em>')))
self.assertEqual([(u'<em>märkup</em>',)], self.env.db_query(
"SELECT value FROM system WHERE name='test-markup'"))
def test_quote(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute('SELECT 1 AS %s' % \
db.quote(r'alpha\`\"\'\\beta``gamma""delta'))
self.assertEqual(r'alpha\`\"\'\\beta``gamma""delta',
get_column_names(cursor)[0])
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:35,代码来源:api.py
示例4: VersionControlAdminTestCase
class VersionControlAdminTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
def tearDown(self):
self.env.reset_db()
def test_render_admin_with_alias_to_default_repos(self):
with self.env.db_transaction as db:
# Add aliases to non-existent default repository
db.executemany(
"INSERT INTO repository (id, name, value) VALUES (%s, %s, %s)",
[(1, 'name', ''), (1, 'dir', None), (1, 'alias', ''),
(2, 'name', 'blah'), (2, 'dir', None), (2, 'alias', '')])
panel = RepositoryAdminPanel(self.env)
req = Mock(method='GET', chrome={}, args={}, session={},
abs_href=Href('/'), href=Href('/'), locale=None,
perm=MockPerm(), authname='anonymous', tz=utc)
template, data = panel.render_admin_panel(req, 'versioncontrol',
'repository', '')
repositories = data['repositories']
self.assertNotEqual({}, repositories)
self.assertEqual('', repositories['']['name'])
self.assertEqual('', repositories['']['alias'])
self.assertEqual('blah', repositories['blah']['name'])
self.assertEqual('', repositories['blah']['alias'])
开发者ID:pkdevbox,项目名称:trac,代码行数:28,代码来源:admin.py
示例5: AnnouncementSystemSendTestCase
class AnnouncementSystemSendTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(enable=['trac.*', 'announcer.*'])
self.env.path = tempfile.mkdtemp()
self.db_mgr = DatabaseManager(self.env)
self.db = self.env.get_db_cnx()
self.an_sys = AnnouncementSystem(self.env)
def tearDown(self):
self.db.close()
# Really close db connections.
self.env.shutdown()
shutil.rmtree(self.env.path)
# Tests
def test_filter_added(self):
class DummySubscriptionFilter(Component):
"""Test implementation for checking the filter ExtensionPoint."""
implements(IAnnouncementSubscriptionFilter)
def filter_subscriptions(self, event, subscriptions):
"""Just a pass-through."""
return subscriptions
dummy = DummySubscriptionFilter(self.env)
self.assertTrue(dummy in self.an_sys.subscription_filters)
开发者ID:lkraav,项目名称:trachacks,代码行数:27,代码来源:api.py
示例6: GroupPostsByMonthTestCase
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)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:35,代码来源:model.py
示例7: TargetPlatformTestCase
class TargetPlatformTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.env.path = tempfile.mkdtemp()
logs_dir = self.env.config.get("bitten", "logs_dir")
if os.path.isabs(logs_dir):
raise ValueError("Should not have absolute logs directory for temporary test")
logs_dir = os.path.join(self.env.path, logs_dir)
os.makedirs(logs_dir)
db = self.env.get_db_cnx()
cursor = db.cursor()
connector, _ = DatabaseManager(self.env)._get_connector()
for table in TargetPlatform._schema:
for stmt in connector.to_sql(table):
cursor.execute(stmt)
db.commit()
def test_new(self):
platform = TargetPlatform(self.env)
self.assertEqual(False, platform.exists)
self.assertEqual([], platform.rules)
def test_insert(self):
platform = TargetPlatform(self.env, config='test', name='Windows XP')
platform.rules += [(Build.OS_NAME, 'Windows'), (Build.OS_VERSION, 'XP')]
platform.insert()
assert platform.exists
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute("SELECT config,name FROM bitten_platform "
"WHERE id=%s", (platform.id,))
self.assertEqual(('test', 'Windows XP'), cursor.fetchone())
cursor.execute("SELECT propname,pattern,orderno FROM bitten_rule "
"WHERE id=%s", (platform.id,))
self.assertEqual((Build.OS_NAME, 'Windows', 0), cursor.fetchone())
self.assertEqual((Build.OS_VERSION, 'XP', 1), cursor.fetchone())
def test_fetch(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute("INSERT INTO bitten_platform (config,name) "
"VALUES (%s,%s)", ('test', 'Windows'))
id = db.get_last_id(cursor, 'bitten_platform')
platform = TargetPlatform.fetch(self.env, id)
assert platform.exists
self.assertEqual('test', platform.config)
self.assertEqual('Windows', platform.name)
def test_select(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.executemany("INSERT INTO bitten_platform (config,name) "
"VALUES (%s,%s)", [('test', 'Windows'),
('test', 'Mac OS X')])
platforms = list(TargetPlatform.select(self.env, config='test'))
self.assertEqual(2, len(platforms))
开发者ID:blaxter,项目名称:Bitten,代码行数:60,代码来源:model.py
示例8: TicketFieldTimelineFilterTests
class TicketFieldTimelineFilterTests(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
t1 = self._insert_and_load_ticket("foo")
self.filter = TicketFieldTimelineFilter(self.env)
self.context = Mock(resource=t1.resource)
def tearDown(self):
self.env.reset_db()
def test_returns_none_for_invalid_ticket_id(self):
event = ['ticket', None, None, ['88']]
result = self.filter.filter_event(self.context, None, event, None)
self.assertIsNone(result)
def test_long_resource_id(self):
"""Test resource with long id (#547)"""
resource = self.context.resource
resource.id = long(resource.id)
event = ['ticket', None, None, [resource]]
result = self.filter.filter_event(self.context, None, event, None)
self.assertEqual(result, event)
def _insert_and_load_ticket(self, summary, **kw):
ticket = Ticket(self.env)
ticket["summary"] = summary
for k, v in kw.items():
ticket[k] = v
return Ticket(self.env, ticket.insert())
开发者ID:mohsadki,项目名称:dargest,代码行数:31,代码来源:timeline.py
示例9: GetBlogPostsTestCase
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'))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:25,代码来源:model.py
示例10: _BaseTestCase
class _BaseTestCase(unittest.TestCase):
def setUp(self):
#self.basedir = os.path.realpath(tempfile.mkdtemp())
self.env = EnvironmentStub(enable=['trac.*', 'acct_mgr.*'])
self.env.config.set('account-manager', 'password_store',
'SessionStore')
self.store = SessionStore(self.env)
#self.env.path = os.path.join(self.basedir, 'trac-tempenv')
#os.mkdir(self.env.path)
def test_get_users(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.executemany("INSERT INTO session_attribute "
"(sid,authenticated,name,value) "
"VALUES (%s,1,'password',%s)",
[('a', 'a'),
('b', 'b'),
('c', 'c')])
self.assertEqual(set(['a', 'b', 'c']), set(self.store.get_users()))
def test_has_user(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute("INSERT INTO session_attribute "
"(sid,authenticated,name,value) "
"VALUES (%s,1,'password',%s)",
('bar', 'bar'))
self.assertFalse(self.store.has_user('foo'))
self.assertTrue(self.store.has_user('bar'))
def test_create_user(self):
self.assertFalse(self.store.has_user('foo'))
self.store.set_password('foo', 'password')
self.assertTrue(self.store.has_user('foo'))
def test_update_password(self):
self.store.set_password('foo', 'pass1')
self.assertFalse(self.store.check_password('foo', 'pass2'))
self.store.set_password('foo', 'pass2')
self.assertTrue(self.store.check_password('foo', 'pass2'))
self.store.set_password('foo', 'pass3', 'pass2')
self.assertTrue(self.store.check_password('foo', 'pass3'))
def test_delete_user(self):
self.store.set_password('foo', 'password')
self.assertTrue(self.store.has_user('foo'))
self.assertTrue(self.store.delete_user('foo'))
self.assertFalse(self.store.has_user('foo'))
def test_delete_nonexistant_user(self):
self.assertFalse(self.store.has_user('foo'))
self.assertFalse(self.store.delete_user('foo'))
def test_unicode_username_and_password(self):
username = u'\u4e60'
password = u'\u4e61'
self.store.set_password(username, password)
self.assertTrue(self.store.check_password(username, password))
开发者ID:51reboot,项目名称:huangweiyi,代码行数:60,代码来源:db.py
示例11: create_trac_ctx
def create_trac_ctx(self, website_url, author_name, timezone_str, uri):
req = Mock(href=Href(uri),
abs_href=Href(website_url),
authname=author_name,
perm=MockPerm(),
tz=timezone_str,
args={})
context = Context.from_request(req, 'wiki', 'WikiStart')
env = EnvironmentStub(enable=['trac.*']) # + additional components
# -- macros support
env.path = ''
# -- intertrac support
env.config.set('intertrac', 'trac.title', "Trac's Trac")
env.config.set('intertrac', 'trac.url',
website_url)
env.config.set('intertrac', 't', 'trac')
env.config.set('intertrac', 'th.title', "Trac Hacks")
env.config.set('intertrac', 'th.url',
"http://trac-hacks.org")
env.config.set('intertrac', 'th.compat', 'false')
# -- safe schemes
env.config.set('wiki', 'safe_schemes',
'file,ftp,http,https,svn,svn+ssh,git,'
'rfc-2396.compatible,rfc-2396+under_score')
env.href = req.href
env.abs_href = req.abs_href
return (env, context)
开发者ID:azrdev,项目名称:thot,代码行数:29,代码来源:TracParser.py
示例12: TracHoursByCommentTestCase
class TracHoursByCommentTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True,
enable=['trac.*', 'trachours.*'])
self.env.path = tempfile.mkdtemp()
setup = SetupTracHours(self.env)
setup.upgrade_environment(db=self.env.get_db_cnx())
self.hours_thp = TracHoursPlugin(self.env)
self.hours_thbc = TracHoursByComment(self.env)
self.ticket_system = TicketSystem(self.env)
def tearDown(self):
self.env.reset_db()
revert_trachours_schema_init(db=self.env.get_db_cnx())
shutil.rmtree(self.env.path)
def test_ticket_delete(self):
ticket = Ticket(self.env)
ticket['summary'] = 'ticket summary'
ticket.insert()
self.hours_thp.add_ticket_hours(ticket.id, 'user', 160)
self.hours_thp.add_ticket_hours(ticket.id, 'user', 1200)
ticket.delete()
hours = self.hours_thp.get_ticket_hours(ticket.id)
self.assertEqual([], hours)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:28,代码来源:ticket.py
示例13: ComponentTestCase
class ComponentTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True)
def tearDown(self):
self.env.reset_db()
def test_exists_negative(self):
def get_fake_component():
return Component(self.env, "Shrubbery")
self.assertRaises(TracError, get_fake_component)
def test_exists(self):
"""
http://trac.edgewall.org/ticket/4247
"""
for c in Component.select(self.env):
self.assertEqual(c.exists, True)
def test_create_and_update(self):
component = Component(self.env)
component.name = 'Test'
component.insert()
self.assertEqual([('Test', None, None)], self.env.db_query("""
SELECT name, owner, description FROM component
WHERE name='Test'"""))
# Use the same model object to update the component
component.owner = 'joe'
component.update()
self.assertEqual([('Test', 'joe', None)], self.env.db_query(
"SELECT name, owner, description FROM component WHERE name='Test'"))
开发者ID:nextview,项目名称:medicticket,代码行数:34,代码来源:model.py
示例14: GetBlogPostsTestCase
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"))
开发者ID:kzhamaji,项目名称:TracFullBlogPlugin,代码行数:26,代码来源:model.py
示例15: PluginAdminPanelTestCase
class PluginAdminPanelTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub()
self.req = Mock(
args={},
chrome={"notices": []},
href=self.env.href,
lc_time=locale_en,
method=None,
perm=MockPerm(),
session={},
tz=utc,
)
def tearDown(self):
self.env.reset_db()
def test_abstract_component_not_visible(self):
class AbstractComponent(Component):
abstract = True
class NotAbstractComponent(Component):
abstract = False
panel = PluginAdminPanel(self.env)
data = panel.render_admin_panel(self.req, "general", "plugin", None)[1]
module = self.__class__.__module__
components = []
for plugin in data["plugins"]:
if module in plugin["modules"].keys():
components = plugin["modules"][module]["components"].keys()
self.assertNotIn("AbstractComponent", components)
self.assertIn("NotAbstractComponent", components)
开发者ID:pkdevbox,项目名称:trac,代码行数:34,代码来源:web_ui.py
示例16: VersionTestCase
class VersionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True)
def tearDown(self):
self.env.reset_db()
def test_exists_negative(self):
def get_fake_version():
return Version(self.env, "-1")
self.assertRaises(TracError, get_fake_version)
def test_exists(self):
"""
http://trac.edgewall.org/ticket/4247
"""
for v in Version.select(self.env):
self.assertEqual(v.exists, True)
def test_create_and_update(self):
version = Version(self.env)
version.name = 'Test'
version.insert()
self.assertEqual([('Test', 0, None)], self.env.db_query(
"SELECT name, time, description FROM version WHERE name='Test'"))
# Use the same model object to update the version
version.description = 'Some text'
version.update()
self.assertEqual([('Test', 0, 'Some text')], self.env.db_query(
"SELECT name, time, description FROM version WHERE name='Test'"))
开发者ID:nextview,项目名称:medicticket,代码行数:33,代码来源:model.py
示例17: _BaseTestCase
class _BaseTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True,
enable=['trac.*', 'tractags.*'])
self.env.path = tempfile.mkdtemp()
self.db = self.env.get_db_cnx()
setup = TagSetup(self.env)
# Current tractags schema is setup with enabled component anyway.
# Revert these changes for getting default permissions inserted.
self._revert_tractags_schema_init()
setup.upgrade_environment(self.db)
def tearDown(self):
self.db.close()
# Really close db connections.
self.env.shutdown()
shutil.rmtree(self.env.path)
# Helpers
def _revert_tractags_schema_init(self):
cursor = self.db.cursor()
cursor.execute("DROP TABLE IF EXISTS tags")
cursor.execute("DROP TABLE IF EXISTS tags_change")
cursor.execute("DELETE FROM system WHERE name='tags_version'")
cursor.execute("DELETE FROM permission WHERE action %s"
% self.db.like(), ('TAGS_%',))
def _insert_tags(self, tagspace, name, tags):
cursor = self.db.cursor()
args = [(tagspace, name, tag) for tag in tags]
cursor.executemany("INSERT INTO tags (tagspace,name,tag) "
"VALUES (%s,%s,%s)", args)
开发者ID:kzhamaji,项目名称:TracTagsPlugin,代码行数:35,代码来源:macros.py
示例18: VersionTestCase
class VersionTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True)
self.db = self.env.get_db_cnx()
def tearDown(self):
self.env.reset_db()
def test_exists_negative(self):
def get_fake_version():
return Version(self.env, "-1")
self.assertRaises(TracError, get_fake_version)
def test_exists(self):
"""
http://trac.edgewall.org/ticket/4247
"""
for v in Version.select(self.env):
self.assertEqual(v.exists, True)
def test_create_and_update(self):
version = Version(self.env)
version.name = "Test"
version.insert()
cursor = self.db.cursor()
cursor.execute("SELECT name,time,description FROM version " "WHERE name='Test'")
self.assertEqual(("Test", 0, None), cursor.fetchone())
# Use the same model object to update the version
version.description = "Some text"
version.update()
cursor.execute("SELECT name,time,description FROM version " "WHERE name='Test'")
self.assertEqual(("Test", 0, "Some text"), cursor.fetchone())
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:35,代码来源:model.py
示例19: _BaseTestCase
class _BaseTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True,
enable=['trac.*', 'tractags.*'])
self.env.path = tempfile.mkdtemp()
self.perms = PermissionSystem(self.env)
self.req = Mock(authname='editor')
self.actions = ['TAGS_ADMIN', 'TAGS_MODIFY', 'TAGS_VIEW']
self.db = self.env.get_db_cnx()
setup = TagSetup(self.env)
# Current tractags schema is setup with enabled component anyway.
# Revert these changes for getting default permissions inserted.
self._revert_tractags_schema_init()
setup.upgrade_environment(self.db)
self.tag_s = tractags.api.TagSystem(self.env)
def tearDown(self):
self.db.close()
# Really close db connections.
self.env.shutdown()
shutil.rmtree(self.env.path)
# Helpers
def _revert_tractags_schema_init(self):
cursor = self.db.cursor()
cursor.execute("DROP TABLE IF EXISTS tags")
cursor.execute("DROP TABLE IF EXISTS tags_change")
cursor.execute("DELETE FROM system WHERE name='tags_version'")
cursor.execute("DELETE FROM permission WHERE action %s"
% self.db.like(), ('TAGS_%',))
开发者ID:kzhamaji,项目名称:TracTagsPlugin,代码行数:33,代码来源:api.py
示例20: ComponentTestCase
class ComponentTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True)
self.db = self.env.get_db_cnx()
def tearDown(self):
self.env.reset_db()
def test_exists_negative(self):
def get_fake_component():
return Component(self.env, "Shrubbery")
self.assertRaises(TracError, get_fake_component)
def test_exists(self):
"""
http://trac.edgewall.org/ticket/4247
"""
for c in Component.select(self.env):
self.assertEqual(c.exists, True)
def test_create_and_update(self):
component = Component(self.env)
component.name = "Test"
component.insert()
cursor = self.db.cursor()
cursor.execute("SELECT name,owner,description FROM component " "WHERE name='Test'")
self.assertEqual(("Test", None, None), cursor.fetchone())
# Use the same model object to update the component
component.owner = "joe"
component.update()
cursor.execute("SELECT name,owner,description FROM component " "WHERE name='Test'")
self.assertEqual(("Test", "joe", None), cursor.fetchone())
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:35,代码来源:model.py
注:本文中的trac.test.EnvironmentStub类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论