Commit 0b38da1b authored by Yuri Konotopov's avatar Yuri Konotopov

update-info: allow POST requests

Since json-encoded list of installed extensions may be big enough it
should be provided in POST request.
Deprecate GET requests for '/update-info/' API.

Bug: https://github.com/nE0sIghT/chrome-gnome-shell-mirror/issues/97
parent cdd3359b
......@@ -472,6 +472,14 @@ class UpdateVersionTest(TestCase):
return json.loads(response.content.decode(response.charset))
def grab_post_response(self, installed):
installed = self.build_response(installed)
response = self.client.post(reverse('extensions-shell-update') + "?shell_version=3.2.0",
data=json.dumps(installed),
content_type='application/json')
return json.loads(response.content.decode(response.charset))
def test_upgrade_me(self):
uuid = self.upgrade_uuid
......@@ -479,10 +487,14 @@ class UpdateVersionTest(TestCase):
expected = {uuid: self.full_expected[self.upgrade_uuid]}
response = self.grab_response({ uuid: 1 })
self.assertEqual(response, expected)
response = self.grab_post_response({ uuid: 1 })
self.assertEqual(response, expected)
# The user has a newer version on his machine.
response = self.grab_response({ uuid: 2 })
self.assertEqual(response, {})
response = self.grab_post_response({ uuid: 2 })
self.assertEqual(response, {})
def test_reject_me(self):
uuid = self.reject_uuid
......@@ -490,10 +502,14 @@ class UpdateVersionTest(TestCase):
expected = {uuid: self.full_expected[self.reject_uuid]}
response = self.grab_response({ uuid: 1 })
self.assertEqual(response, expected)
response = self.grab_post_response({ uuid: 1 })
self.assertEqual(response, expected)
# The user has a newer version than what's on the site.
response = self.grab_response({ uuid: 2 })
self.assertEqual(response, {})
response = self.grab_post_response({ uuid: 2 })
self.assertEqual(response, {})
def test_downgrade_me(self):
uuid = self.downgrade_uuid
......@@ -502,15 +518,21 @@ class UpdateVersionTest(TestCase):
expected = { uuid: self.full_expected[self.downgrade_uuid] }
response = self.grab_response({ uuid: 2 })
self.assertEqual(response, expected)
response = self.grab_post_response({ uuid: 2 })
self.assertEqual(response, expected)
# The user has the appropriate version on his machine.
response = self.grab_response({ uuid: 1 })
self.assertEqual(response, {})
response = self.grab_post_response({ uuid: 1 })
self.assertEqual(response, {})
def test_nonexistent_uuid(self):
# The user has an extension that's not on the site.
response = self.grab_response({ self.nonexistant_uuid: 1 })
self.assertEqual(response, {})
response = self.grab_post_response({ self.nonexistant_uuid: 1 })
self.assertEqual(response, {})
def test_multiple(self):
installed = { self.upgrade_uuid: 1,
......@@ -520,6 +542,8 @@ class UpdateVersionTest(TestCase):
response = self.grab_response(installed)
self.assertEqual(self.full_expected, response)
response = self.grab_post_response(installed)
self.assertEqual(self.full_expected, response)
def test_wrong_version(self):
uuid = self.upgrade_uuid
......@@ -528,10 +552,14 @@ class UpdateVersionTest(TestCase):
expected = {uuid: self.full_expected[self.upgrade_uuid]}
response = self.grab_response({uuid: ''})
self.assertEqual(response, expected)
response = self.grab_post_response({uuid: ''})
self.assertEqual(response, expected)
expected = {uuid: self.full_expected[self.upgrade_uuid]}
response = self.grab_response({uuid: '0.8.4'})
self.assertEqual(response, expected)
response = self.grab_post_response({uuid: '0.8.4'})
self.assertEqual(response, expected)
class QueryExtensionsTest(BasicUserTestCase, TestCase):
......
......@@ -108,7 +108,11 @@ def shell_download(request, uuid):
@ajax_view
def shell_update(request):
try:
installed = json.loads(request.GET['installed'])
if request.method == 'POST':
installed = json.load(request)
# TODO: drop GET request support at year after chrome-gnome-shell 11 release
else:
installed = json.loads(request.GET['installed'])
shell_version = request.GET['shell_version']
disable_version_validation = request.GET.get('disable_version_validation', False)
except (KeyError, ValueError):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment