import unittest import turbogears from turbogears import testutil from turbogears.database import bind_metadata, metadata, session from transifex.controllers import Root import cherrypy from transifex.model import Repository, User, Group cherrypy.root = Root() class TestRepo(unittest.TestCase): """Set up the database accordingly for this set of tests.""" def setUp(self): """Set up the database for this set of tests.""" # Testing elements self.testrepo = u'foorepo2' bind_metadata() metadata.create_all() # Create a repo session.begin() r = Repository(name=self.testrepo, description=self.testrepo, disabled=False) u = User(user_name=u'admin', display_name=u'Adminy Administrator', email_address=u'admin@example.com', password=u'admin') g=Group(group_name=u'l10n-admin', display_name=u'Administrators') g.users.append(u) session.commit() turbogears.startup.startTurboGears() def tearDown(self): """Clean up the database.""" metadata.drop_all() turbogears.startup.stopTurboGears() class TestRepoVisitor(TestRepo): """Test how repos pages look to a visitor (non authenticated user).""" def test_repolist(self): """Test the content of the Repos list page.""" testutil.create_request("/repos/") page = cherrypy.response.body[0] assert "Repositories" in page repos = Repository.query().filter_by(disabled=False) for r in repos: #FIXME: Do we really have to use encode here? assert r.name.encode() in page, \ "Assert that Active repos are shown" assert not 'action="/repos/save"' in page, \ "Assert that the form for adding repos is not shown" class TestRepoAdmin(TestRepo): def test_repo_add_view_logged(self): """Test access to the Repository Add page as Admin """ user = testutil.BrowsingSession() user.goto('/login?user_name=admin&password=admin&login=Login') user.goto('/repos/') assert 'Add a new repository' in user.response def test_repo_add_validation_view_logged(self): """Test Validation to the Repository Add page as Admin """ user = testutil.BrowsingSession() user.goto('/login?user_name=admin&password=admin&login=Login') user.goto('/repos/save/') assert 'There was an error with your form' in user.response assert 'Please enter a value' in user.response def test_repo_edit_view_logged(self): """Test Edit to the Repository Add page as Admin """ user = testutil.BrowsingSession() user.goto('/login?user_name=admin&password=admin&login=Login') user.goto('/repos/%s' % self.testrepo) assert 'Update a repository' in user.response