Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions opentreemap/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


import base64
import hashlib
import hmac
import re
import urllib
import urllib.request
import urllib.parse
import urllib.error

from django.http import HttpResponse
from django.contrib.auth import authenticate
Expand All @@ -29,9 +29,9 @@ def get_signature_for_request(request, secret_key):
# This used to use request.REQUEST, but after some testing and analysis it
# seems that both iOS & Android always pass named parameters in the query
# string, even for non-GET requests
params = sorted(request.GET.iteritems(), key=lambda a: a[0])
params = sorted(iter(request.GET.items()), key=lambda a: a[0])

paramstr = '&'.join(['%s=%s' % (k, urllib.quote_plus(str(v)))
paramstr = '&'.join(['%s=%s' % (k, urllib.parse.quote_plus(str(v)))
for (k, v) in params
if k.lower() != "signature"])

Expand Down
4 changes: 1 addition & 3 deletions opentreemap/api/decorators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


import datetime

Expand Down
10 changes: 4 additions & 6 deletions opentreemap/api/instance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


import json
import copy
Expand Down Expand Up @@ -53,13 +51,13 @@ def wrapper(request, *args, **kwargs):
if request.api_version < 4:
multichoice_fields = {
field for field, info
in instance_info_dict['fields'].iteritems()
in instance_info_dict['fields'].items()
if info['data_type'] == 'multichoice'}

# Remove multichoice fields from perms
instance_info_dict['fields'] = {
field: info for field, info
in instance_info_dict['fields'].iteritems()
in instance_info_dict['fields'].items()
if field not in multichoice_fields}

# Remove multichoice fields from field groups
Expand Down Expand Up @@ -300,7 +298,7 @@ def public_instances(request):

def _contextify_instances(instances):
""" Converts instances to context dictionary"""
return map(_instance_info_dict, instances)
return list(map(_instance_info_dict, instances))


def _instance_info_dict(instance):
Expand Down
2 changes: 1 addition & 1 deletion opentreemap/api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations
from django.conf import settings
Expand Down
4 changes: 1 addition & 3 deletions opentreemap/api/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


import uuid
import base64
Expand Down
8 changes: 3 additions & 5 deletions opentreemap/api/plots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


import json
from functools import wraps
Expand Down Expand Up @@ -42,7 +40,7 @@ def plots_closest_to_point(request, instance, lat, lng):
try:
max_plots = int(request.GET.get('max_plots', '1'))

if max_plots not in xrange(1, 501):
if max_plots not in range(1, 501):
raise ValueError()
except ValueError:
raise HttpBadRequestException(
Expand Down Expand Up @@ -80,7 +78,7 @@ def update_or_create_plot(request, instance, plot_id=None):

for model in ["plot", "tree"]:
if model in request_dict:
for key, val in request_dict[model].iteritems():
for key, val in request_dict[model].items():
data["%s.%s" % (model, key)] = val

# We explicitly disallow setting a plot's tree id.
Expand Down
4 changes: 1 addition & 3 deletions opentreemap/api/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from django.contrib.gis.geos.collections import MultiPolygon
from django.contrib.gis.geos.polygon import Polygon
Expand Down
58 changes: 29 additions & 29 deletions opentreemap/api/tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from StringIO import StringIO

from io import StringIO
from json import loads, dumps
from urlparse import urlparse
from urllib.parse import urlparse

import urllib
import urllib.request
import urllib.parse
import urllib.error
import os
import json
import base64
Expand Down Expand Up @@ -84,9 +84,9 @@ def _get_path(parsed_url):
"""
# If there are parameters, add them
if parsed_url[3]:
return urllib.unquote(parsed_url[2] + ";" + parsed_url[3])
return urllib.parse.unquote(parsed_url[2] + ";" + parsed_url[3])
else:
return urllib.unquote(parsed_url[2])
return urllib.parse.unquote(parsed_url[2])


def send_json_body(url, body_object, client, method, user=None):
Expand Down Expand Up @@ -794,7 +794,7 @@ def test_update_plot_with_pending(self):
self.assertEqual(3, len(Audit.pending_audits()),
"Expected 3 pends, one for each edited field")

self.assertEqual(3, len(response_json['pending_edits'].keys()),
self.assertEqual(3, len(list(response_json['pending_edits'].keys())),
"Expected the json response to have a "
"pending_edits dict with 3 keys, one for each field")

Expand All @@ -808,10 +808,10 @@ def test_invalid_field_returns_200_field_is_not_in_response(self):

self.assertEqual(200, response.status_code)
response_json = loads(response.content)
self.assertFalse("error" in response_json.keys(),
self.assertFalse("error" in list(response_json.keys()),
"Did not expect an error")

self.assertFalse("foo" in response_json.keys(),
self.assertFalse("foo" in list(response_json.keys()),
"Did not expect foo to be added to the plot")

def test_update_creates_tree(self):
Expand Down Expand Up @@ -924,7 +924,7 @@ def test_update_tree_with_pending(self):
"Expected 1 pend record for the edited field.")

response_json = loads(response.content)
self.assertEqual(1, len(response_json['pending_edits'].keys()),
self.assertEqual(1, len(list(response_json['pending_edits'].keys())),
"Expected the json response to have a"
" pending_edits dict with 1 keys")

Expand Down Expand Up @@ -1418,7 +1418,7 @@ def test_multichoice_fields_v4(self):

response = instance_info_endpoint(request, 4, self.instance.url_name)
info_dict = json.loads(response.content)
self.assertIn('plot.udf:multi', info_dict['fields'].keys())
self.assertIn('plot.udf:multi', list(info_dict['fields'].keys()))
self.assertTrue(any('plot.udf:multi' in group.get('field_keys', [])
for group in info_dict['field_key_groups']))

Expand All @@ -1428,7 +1428,7 @@ def test_multichoice_removed_in_v3(self):
response = instance_info_endpoint(request, 3, self.instance.url_name)
info_dict = json.loads(response.content)

self.assertNotIn('plot.udf:multi', info_dict['fields'].keys())
self.assertNotIn('plot.udf:multi', list(info_dict['fields'].keys()))
self.assertFalse(any('plot.udf:multi' in group.get('field_keys', [])
for group in info_dict['field_key_groups']))

Expand Down Expand Up @@ -1630,7 +1630,7 @@ def testUploadPhoto(self):
response = update_profile_photo_endpoint(req, LATEST_API,
str(peon.pk))

self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)

peon = User.objects.get(pk=peon.pk)
self.assertIsNotNone(peon.photo)
Expand All @@ -1657,15 +1657,15 @@ def testCanOnlyUploadAsSelf(self):
response = update_profile_photo_endpoint(req, LATEST_API,
str(grunt.pk))

self.assertEquals(response.status_code, 403)
self.assertEqual(response.status_code, 403)

def testCreateUser(self):
rslt = create_user(self.make_post_request(self.defaultUserDict))
pk = rslt['id']

user = User.objects.get(pk=pk)

for field, target_value in self.defaultUserDict.iteritems():
for field, target_value in self.defaultUserDict.items():
if field != 'password':
self.assertEqual(getattr(user, field), target_value)

Expand Down Expand Up @@ -1758,12 +1758,12 @@ def updatePeonRequest(d):
updatePeonRequest({'last_name': 'l1'})

peon = User.objects.get(pk=peon.pk)
self.assertEquals(peon.last_name, 'l1')
self.assertEqual(peon.last_name, 'l1')

updatePeonRequest({'last_name': 'l2'})

peon = User.objects.get(pk=peon.pk)
self.assertEquals(peon.last_name, 'l2')
self.assertEqual(peon.last_name, 'l2')

updatePeonRequest({'password': 'whateva'})

Expand All @@ -1785,12 +1785,12 @@ def updatePeonRequest(d):
updatePeonRequest({'lastname': 'l1'})

peon = User.objects.get(pk=peon.pk)
self.assertEquals(peon.last_name, 'l1')
self.assertEqual(peon.last_name, 'l1')

updatePeonRequest({'lastname': 'l2'})

peon = User.objects.get(pk=peon.pk)
self.assertEquals(peon.last_name, 'l2')
self.assertEqual(peon.last_name, 'l2')

def testCantRemoveRequiredFields(self):
peon = make_user(username='peon', password='pw')
Expand All @@ -1802,7 +1802,7 @@ def testCantRemoveRequiredFields(self):
resp = put_json(url, {'username': ''},
self.client, user=peon)

self.assertEquals(resp.status_code, 400)
self.assertEqual(resp.status_code, 400)

def testCanOnlyUpdateLoggedInUser(self):
peon = make_user(username='peon', password='pw')
Expand All @@ -1817,7 +1817,7 @@ def testCanOnlyUpdateLoggedInUser(self):
resp = put_json(url, {'password': 'whateva'},
self.client, user=grunt)

self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)


class SigningTest(OTMTestCase):
Expand Down Expand Up @@ -1876,7 +1876,7 @@ def testAwsExample(self):
sig = get_signature_for_request(
req, b'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY')

self.assertEquals(
self.assertEqual(
sig, 'i91nKc4PWAt0JJIdXwz9HxZCJDdiy6cf/Mj6vPxyYIs=')

def testTimestampVoidsSignature(self):
Expand Down Expand Up @@ -2035,7 +2035,7 @@ def test_user_has_rep(self):
ijim.save()

auth = base64.b64encode("jim:password")
withauth = dict(self.sign.items() +
withauth = dict(list(self.sign.items()) +
[("HTTP_AUTHORIZATION", "Basic %s" % auth)])

ret = self.client.get("%s/user" % API_PFX, **withauth)
Expand All @@ -2060,18 +2060,18 @@ def _test_requires_admin_access(self, endpoint_name):
iuser.save_with_user(iuser)

resp = get_signed(self.client, url, user=self.user1)
self.assertEquals(resp.status_code, 403)
self.assertEqual(resp.status_code, 403)

iuser.admin = True
iuser.save_with_user(self.user1)

resp = get_signed(self.client, url, user=self.user1)
self.assertEquals(resp.status_code, 200)
self.assertEqual(resp.status_code, 200)

iuser.delete_with_user(self.user1)

resp = get_signed(self.client, url, user=self.user1)
self.assertEquals(resp.status_code, 401)
self.assertEqual(resp.status_code, 401)

def test_csv_requires_admin(self):
self._test_requires_admin_access('users_csv')
Expand All @@ -2089,7 +2089,7 @@ def test_send_password_reset_email_url(self):
url = "%s/send-password-reset-email?email=%s"
response = post_json(url % (API_PFX, self.jim.email),
{}, self.client, None)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)


class SpeciesListTest(OTMTestCase):
Expand Down
4 changes: 1 addition & 3 deletions opentreemap/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from django.conf.urls import url

Expand Down
4 changes: 1 addition & 3 deletions opentreemap/api/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


import json
from functools import wraps
Expand Down
4 changes: 1 addition & 3 deletions opentreemap/api/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from functools import partial

Expand Down
4 changes: 1 addition & 3 deletions opentreemap/appevents/handlers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division


from django.utils.timezone import now

Expand Down
2 changes: 1 addition & 1 deletion opentreemap/appevents/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations
import treemap.json_field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-09-07 14:37
from __future__ import unicode_literals


from django.db import migrations
import treemap.DotDict
Expand Down
Loading