Skip to content

Commit

Permalink
Merge pull request #652 from plone/gforcada-fix-more-warnings
Browse files Browse the repository at this point in the history
Fix more warnings
  • Loading branch information
tisto committed Dec 30, 2018
2 parents fbd357b + cdcc0aa commit 8f4b1e3
Show file tree
Hide file tree
Showing 31 changed files with 105 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Expand Up @@ -10,7 +10,7 @@ Bugfixes:
This prevents lots of ResourceWarnings about unclosed sockets.
Fixes issues `636 <https://github.com/plone/plone.restapi/issues/636>`_
and `648 <https://github.com/plone/plone.restapi/issues/648>`_.
[maurits]
[maurits, gforcada]

- Standardize errors data structure of email-notification endpoint.
[cekk]
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/tests/test_atcontent_deserializer.py
Expand Up @@ -156,7 +156,7 @@ def __call__(self, request):

def test_set_layout(self):
current_layout = self.doc1.getLayout()
self.assertNotEquals(current_layout, "my_new_layout")
self.assertNotEqual(current_layout, "my_new_layout")
self.deserialize(body='{"layout": "my_new_layout"}')
self.assertEqual('my_new_layout', self.doc1.getLayout())

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_batching.py
Expand Up @@ -35,6 +35,9 @@ def setUp(self):
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

def tearDown(self):
self.api_session.close()

def _create_doc(self, container, number):
createContentInContainer(
container, u'DXTestDocument',
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_copymove.py
Expand Up @@ -87,6 +87,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_copy_single_object(self):
response = self.api_session.post(
'/@copy',
Expand Down
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_documentation.py
Expand Up @@ -226,6 +226,7 @@ def create_folder(self):
return folder

def tearDown(self):
self.api_session.close()
self.time_freezer.stop()
popGlobalRegistry(getSite())
self.api_session.close()
Expand Down Expand Up @@ -646,6 +647,7 @@ def test_documentation_users_as_anonymous(self):
response = logged_out_api_session.get('@users')
save_request_and_response_for_docs('users_anonymous', response)
self.assertEqual(response.status_code, 401)
logged_out_api_session.close()

def test_documentations_users_as_unauthorized_user(self):
properties = {
Expand All @@ -671,6 +673,7 @@ def test_documentations_users_as_unauthorized_user(self):
response = standard_api_session.get('@users')
save_request_and_response_for_docs('users_unauthorized', response)
self.assertEqual(response.status_code, 401)
standard_api_session.close()

def test_documentation_users_get(self):
properties = {
Expand Down Expand Up @@ -711,6 +714,7 @@ def test_documentation_users_anonymous_get(self):

response = logged_out_api_session.get('@users/noam')
save_request_and_response_for_docs('users_anonymous_get', response)
logged_out_api_session.close()

def test_documentation_users_unauthorized_get(self):
properties = {
Expand Down Expand Up @@ -743,6 +747,7 @@ def test_documentation_users_unauthorized_get(self):

response = logged_out_api_session.get('@users/noam')
save_request_and_response_for_docs('users_unauthorized_get', response)
logged_out_api_session.close()

def test_documentation_users_authorized_get(self):
properties = {
Expand All @@ -766,6 +771,7 @@ def test_documentation_users_authorized_get(self):
logged_out_api_session.auth = ('noam', 'secret')
response = logged_out_api_session.get('@users/noam')
save_request_and_response_for_docs('users_authorized_get', response)
logged_out_api_session.close()

def test_documentation_users_filtered_get(self):
properties = {
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/tests/test_dxcontent_deserializer.py
Expand Up @@ -210,7 +210,7 @@ def test_deserializer_sets_missing_value_on_required_field(self):

def test_set_layout(self):
current_layout = self.portal.doc1.getLayout()
self.assertNotEquals(current_layout, "my_new_layout")
self.assertNotEqual(current_layout, "my_new_layout")
self.deserialize(body='{"layout": "my_new_layout"}')
self.assertEqual('my_new_layout', self.portal.doc1.getLayout())

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_error_handling.py
Expand Up @@ -52,6 +52,9 @@ def setUp(self):
self.folder_url = self.folder.absolute_url()
transaction.commit()

def tearDown(self):
self.api_session.close()

@unittest.skip('Not working since we moved to plone.rest')
def test_404_not_found(self):
response = self.api_session.get('non-existing-resource')
Expand Down
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_expansion.py
Expand Up @@ -120,6 +120,9 @@ def setUp(self):
title=u'Some Folder')
transaction.commit()

def tearDown(self):
self.api_session.close()

def test_actions_is_expandable(self):
response = self.api_session.get('/folder')

Expand Down Expand Up @@ -331,6 +334,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_translations_is_expandable(self):
response = self.api_session.get('/en/test-document')

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_locking.py
Expand Up @@ -32,6 +32,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_lock_object(self):
response = self.api_session.post('/@lock',)
transaction.commit()
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_permissions.py
Expand Up @@ -24,6 +24,9 @@ def setUp(self):
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (TEST_USER_NAME, TEST_USER_PASSWORD)

def tearDown(self):
self.api_session.close()

def test_anonymous_allowed_to_use_api_by_default(self):
setRoles(self.portal, TEST_USER_ID, ['Anonymous'])
transaction.commit()
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_registry.py
Expand Up @@ -39,6 +39,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_get_registry_record(self):
response = self.api_session.get('/@registry/foo.bar')

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_roles.py
Expand Up @@ -19,6 +19,9 @@ def setUp(self):
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

def tearDown(self):
self.api_session.close()

def test_roles_endpoint_lists_roles(self):
response = self.api_session.get('/@roles')

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_search.py
Expand Up @@ -102,6 +102,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_overall_response_format(self):
response = self.api_session.get('/@search')

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services.py
Expand Up @@ -33,6 +33,9 @@ def setUp(self):
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

def tearDown(self):
self.api_session.close()

def test_get_document(self):
self.portal.invokeFactory(
'Document',
Expand Down
6 changes: 5 additions & 1 deletion src/plone/restapi/tests/test_services_actions.py
Expand Up @@ -17,7 +17,7 @@
TEST_CATEGORY_ID = 'testcategory'


class TestRegistry(unittest.TestCase):
class TestActions(unittest.TestCase):

layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING

Expand Down Expand Up @@ -66,6 +66,10 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()
self.anon_api_session.close()

def test_actions_all_categories(self):
response = self.api_session.get('/@actions')

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_breadcrumbs.py
Expand Up @@ -35,6 +35,9 @@ def setUp(self):
title=u'A document')
transaction.commit()

def tearDown(self):
self.api_session.close()

def test_breadcrumbs(self):
response = self.api_session.get('/folder/doc1/@breadcrumbs')

Expand Down
4 changes: 4 additions & 0 deletions src/plone/restapi/tests/test_services_comments.py
Expand Up @@ -55,6 +55,10 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()
self.user_session.close()

def test_list_datastructure(self):
url = '{}/@comments'.format(self.doc.absolute_url())
response = self.api_session.get(url)
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_content.py
Expand Up @@ -34,6 +34,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_response(self):
response = self.api_session.get(self.doc.absolute_url())
self.assertIn('version', response.json())
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_controlpanels.py
Expand Up @@ -32,6 +32,9 @@ def setUp(self):
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

def tearDown(self):
self.api_session.close()

def test_get_listing(self):
# Do we get a list with at least one item?
response = self.api_session.get('/@controlpanels')
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_email_notification.py
Expand Up @@ -46,6 +46,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_email_notification_missing_parameters(self):
response = self.api_session.post(
'/@email-notification',
Expand Down
4 changes: 4 additions & 0 deletions src/plone/restapi/tests/test_services_email_send.py
Expand Up @@ -46,6 +46,10 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()
self.anon_api_session.close()

def test_email_send(self):
response = self.api_session.post(
'/@email-send',
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_groups.py
Expand Up @@ -38,6 +38,9 @@ def setUp(self):
description=properties['description'])
transaction.commit()

def tearDown(self):
self.api_session.close()

def test_list_groups(self):
response = self.api_session.get('/@groups')

Expand Down
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_services_history.py
Expand Up @@ -40,6 +40,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_get_types(self):
# Check if we have all history types in our test setup
response = self.api_session.get(self.endpoint_url)
Expand Down Expand Up @@ -165,6 +168,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_actions_are_translated(self):
url = self.doc.absolute_url() + '/@history'
response = self.api_session.get(url)
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_navigation.py
Expand Up @@ -55,6 +55,9 @@ def setUp(self):
title=u'A document')
transaction.commit()

def tearDown(self):
self.api_session.close()

def test_navigation_with_no_params_gets_only_top_level(self):
response = self.api_session.get('/folder/@navigation')

Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_principals.py
Expand Up @@ -52,6 +52,9 @@ def setUp(self):
description=properties['description'])
transaction.commit()

def tearDown(self):
self.api_session.close()

def test_get_principals(self):
response = self.api_session.get(
'/@principals',
Expand Down
3 changes: 3 additions & 0 deletions src/plone/restapi/tests/test_services_tiles.py
Expand Up @@ -75,6 +75,9 @@ def setUp(self):
provideAdapter(SampleTile, (Interface, Interface),
IBasicTile, name=u'sample.tile')

def tearDown(self):
self.api_session.close()

def test_get_available_tiles(self):
response = self.api_session.get('/@tiles')

Expand Down
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_services_types.py
Expand Up @@ -26,6 +26,9 @@ def setUp(self):
self.api_session.headers.update({'Accept': 'application/json'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

def tearDown(self):
self.api_session.close()

def test_get_types(self):
response = self.api_session.get(
'{}/@types'.format(self.portal.absolute_url())
Expand Down Expand Up @@ -184,6 +187,9 @@ def setUp(self):

transaction.commit()

def tearDown(self):
self.api_session.close()

def test_get_types_translated(self):
response = self.api_session.get(
'{}/@types'.format(self.portal.absolute_url())
Expand Down
7 changes: 7 additions & 0 deletions src/plone/restapi/tests/test_services_users.py
Expand Up @@ -67,6 +67,10 @@ def setUp(self):
)
transaction.commit()

def tearDown(self):
self.api_session.close()
self.anon_api_session.close()

def test_list_users(self):
response = self.api_session.get('/@users')

Expand Down Expand Up @@ -95,6 +99,7 @@ def test_list_users_without_being_manager(self):

response = noam_api_session.get('/@users')
self.assertEqual(response.status_code, 401)
noam_api_session.close()

def test_list_users_as_anonymous(self):

Expand Down Expand Up @@ -343,6 +348,7 @@ def test_get_other_user_info_when_logged_in(self):

response = noam_api_session.get('/@users/otheruser')
self.assertEqual(response.status_code, 401)
noam_api_session.close()

def test_get_search_user_with_filter(self):
response = self.api_session.post(
Expand Down Expand Up @@ -406,6 +412,7 @@ def test_get_search_user_with_filter_as_unauthorized_user(self):

response = noam_api_session.get('/@users', params={'query': 'howa'})
self.assertEqual(response.status_code, 401)
noam_api_session.close()

def test_get_non_existing_user(self):
response = self.api_session.get('/@users/non-existing-user')
Expand Down
1 change: 1 addition & 0 deletions src/plone/restapi/tests/test_services_vocabularies.py
Expand Up @@ -139,6 +139,7 @@ def test_context_vocabulary(self):
})

def tearDown(self):
self.api_session.close()
gsm = getGlobalSiteManager()
gsm.unregisterUtility(provided=IVocabularyFactory,
name='plone.restapi.tests.test_vocabulary')
2 changes: 1 addition & 1 deletion src/plone/restapi/tests/test_site_deserializer.py
Expand Up @@ -35,6 +35,6 @@ def deserialize(self, body='{}', validate_all=False, context=None):

def test_set_layout(self):
current_layout = self.portal.getLayout()
self.assertNotEquals(current_layout, "my_new_layout")
self.assertNotEqual(current_layout, "my_new_layout")
self.deserialize(body='{"layout": "my_new_layout"}')
self.assertEqual('my_new_layout', self.portal.getLayout())

0 comments on commit 8f4b1e3

Please sign in to comment.