mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
fix issue with unicode encoding in geosync command output, (#582)
add --commit option to geosync command to be in line with other peeringdb commands, add tests for running geosync command
This commit is contained in:
@@ -20,11 +20,18 @@ class Command(BaseCommand):
|
||||
parser.add_argument(
|
||||
"--limit", type=int, default=0,
|
||||
help="limit how many rows are synced, useful for testing")
|
||||
parser.add_argument(
|
||||
'--commit', action='store_true',
|
||||
help="commit changes, otherwise run in pretend mode")
|
||||
|
||||
def log(self, msg):
|
||||
print(msg)
|
||||
if not self.commit:
|
||||
self.stdout.write(u"[pretend] {}".format(msg))
|
||||
else:
|
||||
self.stdout.write(msg)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.commit = options.get("commit", False)
|
||||
reftag = options.get("reftag")
|
||||
limit = options.get("limit")
|
||||
if reftag.find(".") > -1:
|
||||
@@ -38,7 +45,7 @@ class Command(BaseCommand):
|
||||
def sync(self, reftag, _id, limit=0):
|
||||
model = models.REFTAG_MAP.get(reftag)
|
||||
if not model:
|
||||
raise ValueError("Unknown reftag: %s" % reftag)
|
||||
raise ValueError(u"Unknown reftag: {}".format(reftag))
|
||||
if not hasattr(model, "geocode_status"):
|
||||
raise TypeError(
|
||||
"Can only geosync models containing GeocodeBaseMixin")
|
||||
@@ -53,6 +60,8 @@ class Command(BaseCommand):
|
||||
if entity.geocode_status:
|
||||
continue
|
||||
i += 1
|
||||
self.log("Syncing %s [%s %d/%d ID:%s]" % (entity, reftag, i, count,
|
||||
entity.id))
|
||||
entity.geocode(self.gmaps)
|
||||
self.log(u"Syncing {} [{} {}/{} ID:{}]".format(entity.name, reftag, i,
|
||||
count, entity.id))
|
||||
|
||||
if self.commit:
|
||||
entity.geocode(self.gmaps)
|
||||
|
@@ -165,6 +165,7 @@ settings.configure(
|
||||
SITE_ID=1,
|
||||
IXF_POSTMORTEM_LIMIT=250,
|
||||
ABSTRACT_ONLY=True,
|
||||
GOOGLE_GEOLOC_API_KEY="AIzatest",
|
||||
RATELIMITS={
|
||||
"view_affiliate_to_org_POST": "100/m",
|
||||
"resend_confirmation_mail": "2/m",
|
||||
|
@@ -1,11 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
import json
|
||||
import uuid
|
||||
import re
|
||||
import StringIO
|
||||
|
||||
from django.test import Client, TestCase, RequestFactory
|
||||
from django.contrib.auth.models import Group, AnonymousUser
|
||||
from django.contrib.auth import get_user
|
||||
from django.core.management import call_command
|
||||
|
||||
import django_namespace_perms as nsp
|
||||
|
||||
import peeringdb_server.models as models
|
||||
@@ -25,7 +29,7 @@ class ViewTestCase(TestCase):
|
||||
cls.facilities = dict(
|
||||
(k,
|
||||
models.Facility.objects.create(
|
||||
name="Geocode Fac %s" % k, status="ok", org=cls.organizations[
|
||||
name=u"Geocode Fac {}".format(k), status="ok", org=cls.organizations[
|
||||
k], address1="Some street", address2=k, city="Chicago",
|
||||
country="US", state="IL", zipcode="1234", latitude=1.23,
|
||||
longitude=-1.23, geocode_status=True))
|
||||
@@ -50,3 +54,22 @@ class ViewTestCase(TestCase):
|
||||
self.facilities["d"].website = 'http://www.test.com'
|
||||
self.facilities["d"].save()
|
||||
self.assertEqual(self.facilities["d"].geocode_status, True)
|
||||
|
||||
def test_command(self):
|
||||
self.assertEqual(self.facilities["a"].geocode_status, True)
|
||||
|
||||
# change address to flag facility for geocoding
|
||||
|
||||
self.facilities["a"].address1 = "Another street a"
|
||||
|
||||
# test unicode output from command by adding special characters
|
||||
# to the new address
|
||||
|
||||
self.facilities["a"].name = "sdílených služeb"
|
||||
self.facilities["a"].save()
|
||||
|
||||
out = StringIO.StringIO()
|
||||
call_command("pdb_geosync", "fac", limit=1, stdout=out)
|
||||
out = out.getvalue()
|
||||
|
||||
assert out.find("[fac 1/1 ID:1]") > -1
|
||||
|
Reference in New Issue
Block a user