misc: apply double-quote-string-fixer (#79788)
This commit is contained in:
parent
4edb5ca5b2
commit
1dd4eda05f
|
@ -2,8 +2,8 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "petale.settings")
|
||||
if __name__ == '__main__':
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'petale.settings')
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ def cut_exists(request, cut_uuid):
|
|||
url = urlparse.urljoin(authentic_url, 'api/users/synchronization/')
|
||||
try:
|
||||
response = requests.post(
|
||||
url, json={"known_uuids": [cut_uuid]}, auth=request.user.credentials, timeout=28
|
||||
url, json={'known_uuids': [cut_uuid]}, auth=request.user.credentials, timeout=28
|
||||
)
|
||||
response.raise_for_status()
|
||||
except requests.RequestException as e:
|
||||
|
@ -80,7 +80,7 @@ def cut_exists(request, cut_uuid):
|
|||
logger.warning('authentic synchro API failed to decode response: %s', e)
|
||||
return False
|
||||
|
||||
if data.get("unknown_uuids"):
|
||||
if data.get('unknown_uuids'):
|
||||
logger.warning('unknown uuid : %s %s', request.user.credentials[0], data)
|
||||
return False
|
||||
|
||||
|
|
|
@ -61,16 +61,16 @@ class MissingContentType(PetalAPIException):
|
|||
class GlobalSpaceExhausted(PetalAPIException):
|
||||
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
detail = {
|
||||
"error": "global-space-exhausted",
|
||||
"description": "no more space left for this partner",
|
||||
'error': 'global-space-exhausted',
|
||||
'description': 'no more space left for this partner',
|
||||
}
|
||||
|
||||
|
||||
class PetalSizeExhausted(PetalAPIException):
|
||||
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
detail = {
|
||||
"error": "key-space-exhausted",
|
||||
"description": "no more space left for this key",
|
||||
'error': 'key-space-exhausted',
|
||||
'description': 'no more space left for this key',
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,7 +78,7 @@ class ConcurrentAccess(PetalAPIException):
|
|||
status_code = status.HTTP_412_PRECONDITION_FAILED
|
||||
detail = {
|
||||
'error': 'concurrent-access',
|
||||
"description": "data changed since last read",
|
||||
'description': 'data changed since last read',
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,10 +33,10 @@ def check_unknown_cuts(uuids, creds):
|
|||
raise ValueError('PETALE_AUTHENTIC SETTINGS improperly defined')
|
||||
|
||||
url = urljoin(authentic_url, 'api/users/synchronization/')
|
||||
response = requests.post(url, json={"known_uuids": list(uuids)}, auth=creds, timeout=28)
|
||||
response = requests.post(url, json={'known_uuids': list(uuids)}, auth=creds, timeout=28)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return data.get("unknown_uuids") or []
|
||||
return data.get('unknown_uuids') or []
|
||||
|
||||
|
||||
def grouper(n, iterable, fillvalue=None):
|
||||
|
|
|
@ -179,7 +179,7 @@ class AccessControlList(models.Model):
|
|||
partner = models.ForeignKey(Partner, verbose_name=_('Partner'), on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, verbose_name=_('User'), on_delete=models.CASCADE)
|
||||
methods = models.CharField(
|
||||
_('Allowed methods'), max_length=128, default='GET,PUT,DELETE', help_text=("GET, PUT, DELETE")
|
||||
_('Allowed methods'), max_length=128, default='GET,PUT,DELETE', help_text=('GET, PUT, DELETE')
|
||||
)
|
||||
key = models.CharField(_('Allowed keys'), max_length=128, default='*')
|
||||
|
||||
|
|
|
@ -19,5 +19,5 @@ import os
|
|||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ["DJANGO_SETTINGS_MODULE"] = "petale.settings"
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'petale.settings'
|
||||
application = get_wsgi_application()
|
||||
|
|
|
@ -165,7 +165,7 @@ def test_binary_data(app, partner_southpark, cut_kevin_uuid, acl):
|
|||
assert len(list(xml_data)) == 4
|
||||
|
||||
# test update by changing format
|
||||
payload = {"friends": [{"name": "Token", "age": 10}, {"name": "Kenny", "age": 10}]}
|
||||
payload = {'friends': [{'name': 'Token', 'age': 10}, {'name': 'Kenny', 'age': 10}]}
|
||||
resp = app.put_json(url, params=payload, status=200)
|
||||
resp = app.get(url, status=200)
|
||||
data = json.loads(resp.text)
|
||||
|
@ -202,15 +202,15 @@ def test_binary_data(app, partner_southpark, cut_kevin_uuid, acl):
|
|||
|
||||
def test_caching(app, partner_southpark, cut_kevin_uuid, acl):
|
||||
payload = {
|
||||
"favourites": [
|
||||
'favourites': [
|
||||
{
|
||||
"name": "bus stations",
|
||||
"url": "https://southpark.com/bus/station",
|
||||
"items": ["33", "42"],
|
||||
'name': 'bus stations',
|
||||
'url': 'https://southpark.com/bus/station',
|
||||
'items': ['33', '42'],
|
||||
},
|
||||
{
|
||||
"name": "weather",
|
||||
"url": "https://southpark.com/weather/",
|
||||
'name': 'weather',
|
||||
'url': 'https://southpark.com/weather/',
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -244,9 +244,9 @@ def test_caching(app, partner_southpark, cut_kevin_uuid, acl):
|
|||
data = json.loads(resp.text)
|
||||
data['favourites'].append(
|
||||
{
|
||||
"name": "best books",
|
||||
"url": "https://southpark.com/library",
|
||||
"items": ["Guide To Life by E. Cartman", "Gingers Have Sools by Kyle"],
|
||||
'name': 'best books',
|
||||
'url': 'https://southpark.com/library',
|
||||
'items': ['Guide To Life by E. Cartman', 'Gingers Have Sools by Kyle'],
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -256,9 +256,9 @@ def test_caching(app, partner_southpark, cut_kevin_uuid, acl):
|
|||
# update attempts from the cityhall
|
||||
app.authorization = ('Basic', ('cityhall', 'cityhall'))
|
||||
new_item = {
|
||||
"name": "Green zones",
|
||||
"url": "https://southpark.com/parks",
|
||||
"items": ["Main Street", "Emo Kids Street"],
|
||||
'name': 'Green zones',
|
||||
'url': 'https://southpark.com/parks',
|
||||
'items': ['Main Street', 'Emo Kids Street'],
|
||||
}
|
||||
payload['favourites'].append(new_item)
|
||||
resp = app.put_json(url, params=payload, headers={'If-Match': cache}, status=412)
|
||||
|
@ -330,7 +330,7 @@ def test_partner_size_limit(app, cut_kevin_uuid, acl, petal_invoice, petal_books
|
|||
|
||||
def test_api_logging(caplog, app, cut_kevin_uuid, acl):
|
||||
app.authorization = ('Basic', ('library', 'library'))
|
||||
payload = {"friends": [{"name": "Token", "age": 10}, {"name": "Kenny", "age": 10}]}
|
||||
payload = {'friends': [{'name': 'Token', 'age': 10}, {'name': 'Kenny', 'age': 10}]}
|
||||
url = '/api/southpark/%s/profile-friends/' % cut_kevin_uuid
|
||||
resp = app.put_json(url, params=payload, status=201, headers={'If-None-Match': '*'})
|
||||
|
||||
|
@ -357,13 +357,13 @@ def test_api_logging(caplog, app, cut_kevin_uuid, acl):
|
|||
@mock.patch('petale.authentication.requests.post')
|
||||
def test_idp_based_partner_authentication(mocked_post, app, cut_kevin_uuid, acl):
|
||||
app.authorization = ('Basic', ('library', 'whatever'))
|
||||
payload = {"friends": [{"name": "Token", "age": 10}, {"name": "Kenny", "age": 10}]}
|
||||
payload = {'friends': [{'name': 'Token', 'age': 10}, {'name': 'Kenny', 'age': 10}]}
|
||||
url = '/api/southpark/%s/profile-whatever/' % cut_kevin_uuid
|
||||
# failure
|
||||
response = {"result": 0, "errors": ["Invalid username/password."]}
|
||||
response = {'result': 0, 'errors': ['Invalid username/password.']}
|
||||
mocked_post.return_value = FakedResponse(content=json.dumps(response))
|
||||
app.put_json(url, params=payload, status=403, headers={'If-None-Match': '*'})
|
||||
response = {"result": 1, "errors": []}
|
||||
response = {'result': 1, 'errors': []}
|
||||
# test with RP
|
||||
client_id = client_secret = 'a1b2' * 8
|
||||
app.authorization = ('Basic', (client_id, client_secret))
|
||||
|
@ -380,35 +380,35 @@ def test_idp_based_partner_authentication(mocked_post, app, cut_kevin_uuid, acl)
|
|||
def test_cut_uuid_idp_checking(mocked_post, settings, app, acl):
|
||||
cut_uuid = 'a1b2' * 8
|
||||
app.authorization = ('Basic', ('library', 'library'))
|
||||
payload = {"username": "t0k3n", "email": "t0k3n@deadsec.org"}
|
||||
payload = {'username': 't0k3n', 'email': 't0k3n@deadsec.org'}
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
# failure with AUTHENTIC_PETALE improperly defined
|
||||
settings.PETALE_AUTHENTIC_URL = ''
|
||||
resp = app.put_json('/api/southpark/%s/profile/' % cut_uuid, params=payload, headers=headers, status=404)
|
||||
assert resp.json["error"] == "cut-not-found"
|
||||
assert resp.json['error'] == 'cut-not-found'
|
||||
# failure when cut uuid doesn't exist on idp
|
||||
response = {"unknown_uuids": [cut_uuid], "result": 1}
|
||||
response = {'unknown_uuids': [cut_uuid], 'result': 1}
|
||||
mocked_post.return_value = FakedResponse(content=json.dumps(response), status_code=200)
|
||||
resp = app.put_json('/api/southpark/%s/profile/' % cut_uuid, params=payload, headers=headers, status=404)
|
||||
assert resp.json["error"] == "cut-not-found"
|
||||
assert resp.json['error'] == 'cut-not-found'
|
||||
|
||||
resp = app.get('/api/southpark/%s/' % cut_uuid, headers=headers, status=404)
|
||||
assert resp.json["error"] == "cut-not-found"
|
||||
assert resp.json['error'] == 'cut-not-found'
|
||||
|
||||
resp = app.get('/api/southpark/%s/profile/' % cut_uuid, headers=headers, status=404)
|
||||
assert resp.json["error"] == "cut-not-found"
|
||||
assert resp.json['error'] == 'cut-not-found'
|
||||
|
||||
# sucess
|
||||
settings.PETALE_AUTHENTIC_URL = 'http://example.net/idp/'
|
||||
response = {"unknown_uuids": [], "result": 1}
|
||||
response = {'unknown_uuids': [], 'result': 1}
|
||||
mocked_post.return_value = FakedResponse(content=json.dumps(response), status_code=200)
|
||||
|
||||
resp = app.get('/api/southpark/%s/profile/' % cut_uuid, headers=headers, status=404)
|
||||
assert resp.json["error"] == "key-not-found"
|
||||
assert resp.json['error'] == 'key-not-found'
|
||||
|
||||
resp = app.get('/api/southpark/%s/' % cut_uuid, headers=headers)
|
||||
assert resp.json["keys"] == []
|
||||
assert resp.json['keys'] == []
|
||||
|
||||
resp = app.put_json('/api/southpark/%s/profile/' % cut_uuid, params=payload, headers=headers, status=201)
|
||||
assert CUT.objects.get(uuid=cut_uuid)
|
||||
|
|
Loading…
Reference in New Issue