allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [06/14] allura git commit: [#7922] ticket:826 Fix tests
Date Mon, 17 Aug 2015 19:38:14 GMT
[#7922] ticket:826 Fix tests


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/90625979
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/90625979
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/90625979

Branch: refs/heads/master
Commit: 906259792f93c4b7a4c4898ac7aba04837b52436
Parents: 8a50235
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Aug 3 13:21:53 2015 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Aug 17 17:54:13 2015 +0000

----------------------------------------------------------------------
 .../tests/functional/test_neighborhood.py       |  2 +-
 AlluraTest/alluratest/controller.py             |  6 ++
 .../tests/functional/test_controllers.py        | 13 +++--
 .../forgetracker/tests/functional/test_root.py  | 61 ++++++++++++--------
 .../forgewiki/tests/functional/test_rest.py     |  2 +-
 .../forgewiki/tests/functional/test_root.py     |  9 ++-
 6 files changed, 60 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/90625979/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 9359efc..8b6a74f 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -173,7 +173,7 @@ class TestNeighborhood(TestController):
 
         r = self.app.get('/p/test/admin/tools')
         assert '<div class="fleft isnt_sorted">' in r
-        delete_tool = r.html.find('a', {'class': 'mount_delete'})
+        delete_tool = r.html.findAll('a', {'class': 'admin_tool_delete_modal'})
         assert_equal(len(delete_tool), 1)
 
     def test_show_title(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/90625979/AlluraTest/alluratest/controller.py
----------------------------------------------------------------------
diff --git a/AlluraTest/alluratest/controller.py b/AlluraTest/alluratest/controller.py
index 5a61ab7..babf262 100644
--- a/AlluraTest/alluratest/controller.py
+++ b/AlluraTest/alluratest/controller.py
@@ -185,6 +185,12 @@ class TestController(object):
         json_dict = json_dict.strip(' ;')
         return json.loads(json_dict)
 
+    def find_form(self, resp, cond):
+        """Find form on the page that meets given condition"""
+        for f in resp.forms.itervalues():
+            if cond(f):
+                return f
+
 
 class TestRestApiBase(TestController):
 

http://git-wip-us.apache.org/repos/asf/allura/blob/90625979/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 4c363d2..dcc975f 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -574,10 +574,15 @@ class TestFork(_TestCase):
         r = self._follow(r, **kw)
         return r
 
+    def _find_request_merge_form(self, resp):
+        cond = lambda f: f.action == 'do_request_merge'
+        return self.find_form(resp, cond)
+
     def _request_merge(self, **kw):
         r = self.app.get('/p/test2/code/request_merge', **kw)
         r = self._follow(r, **kw)
-        r = r.forms[0].submit()
+        form = self._find_request_merge_form(r)
+        r = form.submit()
         r = self._follow(r, **kw)
         mr_num = r.request.url.split('/')[-2]
         assert mr_num.isdigit(), mr_num
@@ -640,7 +645,7 @@ class TestFork(_TestCase):
         assert 'git checkout master' in merge_instructions
         assert 'git fetch git://git.localhost/p/test2/code master' in merge_instructions
         assert 'git merge {}'.format(c_id) in merge_instructions
-        assert_in('less than 1 minute ago', r.html.findAll('p')[0].getText())
+        assert_in('less than 1 minute ago', r.html.findAll('p')[2].getText())
 
         merge_form = r.html.find('form', action='merge')
         assert merge_form
@@ -669,8 +674,8 @@ class TestFork(_TestCase):
         r, mr_num = self._request_merge()
         r = self.app.get('/p/test/src-git/merge-requests/')
         assert 'href="%s/"' % mr_num in r, r
-        assert_equal(r.html.findAll('span')[8].getText(), 'less than 1 minute ago')
-        assert_equal(r.html.findAll('span')[9].getText(), 'less than 1 minute ago')
+        assert_equal(r.html.findAll('span')[-2].getText(), 'less than 1 minute ago')
+        assert_equal(r.html.findAll('span')[-1].getText(), 'less than 1 minute ago')
 
     def test_merge_request_update_status(self):
         r, mr_num = self._request_merge()

http://git-wip-us.apache.org/repos/asf/allura/blob/90625979/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 47c9aab..351b80b 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -27,6 +27,7 @@ import allura
 import mock
 
 import PIL
+from BeautifulSoup import BeautifulSoup
 from mock import patch
 from nose.tools import (
     assert_true,
@@ -65,11 +66,19 @@ class TrackerTestController(TestController):
     def setup_with_tools(self):
         pass
 
+    def _find_new_ticket_form(self, resp):
+        cond = lambda f: f.action.endswith('/save_ticket')
+        return self.find_form(resp, cond)
+
+    def _find_update_ticket_form(self, resp):
+        cond = lambda f: f.action.endswith('/update_ticket_from_widget')
+        return self.find_form(resp, cond)
+
     def new_ticket(self, mount_point='/bugs/', extra_environ=None, **kw):
         extra_environ = extra_environ or {}
         response = self.app.get(mount_point + 'new/',
                                 extra_environ=extra_environ)
-        form = response.forms[1]
+        form = self._find_new_ticket_form(response)
         # If this is ProjectUserCombo's select populate it
         # with all the users in the project. This is a workaround for tests,
         # in real enviroment this is populated via ajax.
@@ -346,7 +355,7 @@ class TestFunctionalController(TrackerTestController):
 
     def test_new_ticket_form(self):
         response = self.app.get('/bugs/new/')
-        form = response.forms[1]
+        form = self._find_new_ticket_form(response)
         form['ticket_form.summary'] = 'test new ticket form'
         form['ticket_form.description'] = 'test new ticket form description'
         response = form.submit().follow()
@@ -841,7 +850,8 @@ class TestFunctionalController(TrackerTestController):
         }, upload_files=[upload]).follow()
         assert file_name in ticket_editor, ticket_editor.showbrowser()
         req = self.app.get('/bugs/1/')
-        file_link = req.html.findAll('form')[1].findAll('a')[1]
+        form = self._find_update_ticket_form(req)
+        file_link = BeautifulSoup(form.text).findAll('a')[1]
         assert_equal(file_link.string, file_name)
         self.app.post(str(file_link['href']), {
             'delete': 'True'
@@ -883,7 +893,8 @@ class TestFunctionalController(TrackerTestController):
         ticket_editor = self.app.post('/bugs/1/update_ticket', {
             'summary': 'zzz'
         }, upload_files=[upload]).follow()
-        download = self.app.get(str(ticket_editor.html.findAll('form')[1].findAll('a')[1]['href']))
+        form = self._find_update_ticket_form(ticket_editor)
+        download = self.app.get(str(BeautifulSoup(form.text).findAll('a')[1]['href']))
         assert_equal(download.body, file_data)
 
     def test_two_attachments(self):
@@ -1229,18 +1240,17 @@ class TestFunctionalController(TrackerTestController):
             '/admin/bugs/set_custom_fields', params=variable_encode(params))
         # Test new ticket form
         r = self.app.get('/bugs/new/')
-        form = r.forms[1]
+        form = self._find_new_ticket_form(r)
         form['ticket_form.custom_fields._priority'] = 'urgent'
         form['ticket_form.custom_fields._category'] = 'bugs'
         error_form = form.submit()
-        assert_equal(error_form.forms[1]['ticket_form.custom_fields._priority'].value,
-                     'urgent')
-        assert_equal(error_form.forms[1]['ticket_form.custom_fields._category'].value,
-                     'bugs')
+        form = self._find_new_ticket_form(error_form)
+        assert_equal(form['ticket_form.custom_fields._priority'].value, 'urgent')
+        assert_equal(form['ticket_form.custom_fields._category'].value, 'bugs')
         # Test edit ticket form
         self.new_ticket(summary='Test ticket')
         response = self.app.get('/bugs/1/')
-        form = response.forms[1]
+        form = self._find_update_ticket_form(response)
         assert_equal(
             form['ticket_form.custom_fields._priority'].value, 'normal')
         assert_equal(form['ticket_form.custom_fields._category'].value, '')
@@ -1248,29 +1258,29 @@ class TestFunctionalController(TrackerTestController):
         form['ticket_form.custom_fields._priority'] = 'urgent'
         form['ticket_form.custom_fields._category'] = 'bugs'
         error_form = form.submit()
-        assert_equal(error_form.forms[1]['ticket_form.custom_fields._priority'].value,
-                     'urgent')
-        assert_equal(error_form.forms[1]['ticket_form.custom_fields._category'].value,
-                     'bugs')
+        form = self._find_update_ticket_form(error_form)
+        assert_equal(form['ticket_form.custom_fields._priority'].value, 'urgent')
+        assert_equal(form['ticket_form.custom_fields._category'].value, 'bugs')
 
     def test_new_ticket_validation(self):
         summary = 'ticket summary'
         response = self.app.get('/bugs/new/')
         assert not response.html.find('div', {'class': 'error'})
-        form = response.forms[1]
+        form = self._find_new_ticket_form(response)
         form['ticket_form.labels'] = 'foo'
         # try submitting with no summary set and check for error message
         error_form = form.submit()
-        assert error_form.forms[1]['ticket_form.labels'].value == 'foo'
-        error_message = error_form.html.find('div', {'class': 'error'})
+        form = self._find_new_ticket_form(error_form)
+        assert form['ticket_form.labels'].value == 'foo'
+        error_message = BeautifulSoup(form.text).find('div', {'class': 'error'})
         assert error_message
         assert (error_message.string == 'You must provide a Title' or
                 error_message.string == 'Missing value')
         assert error_message.findPreviousSibling('input').get('name') == 'ticket_form.summary'
         # set a summary, submit, and check for success
-        error_form.forms[1]['ticket_form.summary'] = summary
-        success = error_form.forms[1].submit().follow().html
-        assert success.findAll('form')[1].get('action') == '/p/test/bugs/1/update_ticket_from_widget'
+        form['ticket_form.summary'] = summary
+        success = form.submit().follow().html
+        assert success.findAll('form', {'action': '/p/test/bugs/1/update_ticket_from_widget'})
is not None
         assert success.find('input', {'name': 'ticket_form.summary'})['value'] == summary
 
     def test_edit_ticket_validation(self):
@@ -1281,7 +1291,7 @@ class TestFunctionalController(TrackerTestController):
         # check that existing form is valid
         assert response.html.find('input', {'name': 'ticket_form.summary'})['value'] == old_summary
         assert not response.html.find('div', {'class': 'error'})
-        form = response.forms[1]
+        form = self._find_update_ticket_form(response)
         # try submitting with no summary set and check for error message
         form['ticket_form.summary'] = ""
         error_form = form.submit()
@@ -1290,11 +1300,12 @@ class TestFunctionalController(TrackerTestController):
         assert error_message.string == 'You must provide a Title'
         assert error_message.findPreviousSibling('input').get('name') == 'ticket_form.summary'
         # set a summary, submit, and check for success
-        error_form.forms[1]['ticket_form.summary'] = new_summary
-        r = error_form.forms[1].submit()
+        form = self._find_update_ticket_form(error_form)
+        form['ticket_form.summary'] = new_summary
+        r = form.submit()
         assert r.status_int == 302, r.showbrowser()
         success = r.follow().html
-        assert success.findAll('form')[1].get('action') == '/p/test/bugs/1/update_ticket_from_widget'
+        assert success.findAll('form', {'action': '/p/test/bugs/1/update_ticket_from_widget'})
is not None
         assert success.find('input', {'name': 'ticket_form.summary'})['value'] == new_summary
 
     def test_home(self):
@@ -2721,7 +2732,7 @@ class TestCustomUserField(TrackerTestController):
     def test_change_user_field(self):
         kw = {'custom_fields._code_review': ''}
         r = self.new_ticket(summary='test custom fields', **kw).follow()
-        f = r.forms[1]
+        f = self._find_update_ticket_form(r)
         # Populate ProjectUserCombo's select with option we want.
         # This is a workaround for tests,
         # in real enviroment this is populated via ajax.

http://git-wip-us.apache.org/repos/asf/allura/blob/90625979/ForgeWiki/forgewiki/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_rest.py b/ForgeWiki/forgewiki/tests/functional/test_rest.py
index 6a5de3b..a2b58ae 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_rest.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_rest.py
@@ -42,7 +42,7 @@ class TestWikiApi(TestRestApiBase):
 
     def test_get_page(self):
         r = self.app.get('/p/test/wiki/Home/')
-        discussion_url = r.html.findAll('form')[2]['action'][:-4]
+        discussion_url = r.html.findAll('form')[3]['action'][:-4]
         content = file(__file__).read()
         self.app.post('/wiki/Home/attach',
                       upload_files=[('file_info', 'test_root.py', content)])

http://git-wip-us.apache.org/repos/asf/allura/blob/90625979/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index 3f69d89..276c4b9 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -54,6 +54,10 @@ class TestRootController(TestController):
     def setup_with_tools(self):
         pass
 
+    def _find_edit_form(self, resp):
+        cond = lambda f: f.id == 'page_edit_form'
+        return self.find_form(resp, cond)
+
     def test_root_index(self):
         page_url = h.urlquote(u'/wiki/t├ęst/')
         r = self.app.get(page_url).follow()
@@ -678,8 +682,9 @@ class TestRootController(TestController):
         assert 'The resource was found at http://localhost/p/test/wiki/Home/;' in self.app.get(
             '/p/test/wiki/')
         req = self.app.get('/p/test/wiki/Home/edit')
-        req.forms[1]['title'].value = 'new_title'
-        req.forms[1].submit()
+        form = self._find_edit_form(req)
+        form['title'].value = 'new_title'
+        form.submit()
         assert 'The resource was found at http://localhost/p/test/wiki/new_title/;' in self.app.get(
             '/p/test/wiki/')
 


Mime
View raw message