Skip to content

Commit

Permalink
unify appengine config code into webutil, refactor other config
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Dec 23, 2019
1 parent a148c19 commit ac38264
Show file tree
Hide file tree
Showing 28 changed files with 30 additions and 120 deletions.
1 change: 0 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from webob import exc

from granary import (
appengine_config,
as2,
atom,
facebook,
Expand Down
11 changes: 7 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import urllib.parse
from xml.etree import ElementTree

import appengine_config

from google.cloud import ndb
import mf2util
from oauth_dropins import (
Expand All @@ -16,7 +14,12 @@
mastodon,
twitter,
)
from oauth_dropins.webutil import handlers, util
from oauth_dropins.webutil import (
appengine_config,
appengine_info,
handlers,
util,
)
from oauth_dropins.webutil.util import json_dumps, json_loads
import requests
import webapp2
Expand Down Expand Up @@ -258,4 +261,4 @@ def handle_exception(self, e, debug):
('/cron/build_circle', cron.BuildCircle),
] + oauth_routes + handlers.HOST_META_ROUTES + [
('.*', api.Handler),
], debug=appengine_config.DEBUG), client=appengine_config.ndb_client)
], debug=appengine_info.DEBUG), client=appengine_config.ndb_client)
32 changes: 0 additions & 32 deletions appengine_config.py

This file was deleted.

6 changes: 3 additions & 3 deletions cron.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Cron jobs. Currently just nightly CircleCI build."""
import appengine_config

import requests
import webapp2

CIRCLECI_TOKEN = appengine_config.read('circleci_token')
from oauth_dropins.webutil import util

CIRCLECI_TOKEN = util.read('circleci_token')


class BuildCircle(webapp2.RequestHandler):
Expand Down
3 changes: 1 addition & 2 deletions docs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ cd `dirname $absfile`
# docs/source/oauth_dropins.rst, oauth_dropins.webutil.rst
# only used to bootstrap. we've edited by hand since then so don't run any more
# or it will overwrite them.
# sphinx-apidoc -f -o source ../granary \
# ../granary/{appengine_config.py,tests}
# sphinx-apidoc -f -o source ../granary ../granary/tests

rm -f index.rst
cat > index.rst <<EOF
Expand Down
14 changes: 0 additions & 14 deletions granary/appengine_config.py

This file was deleted.

8 changes: 3 additions & 5 deletions granary/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@

import dateutil.parser
import mf2util
import oauth_dropins.facebook
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads

from . import appengine_config
from . import source

# Since API v2.4, we need to explicitly ask for the fields we want from most API
Expand Down Expand Up @@ -711,8 +711,6 @@ def _create(self, obj, preview=None, include_link=source.OMIT_LINK,
tag.get('url'), tag.get('displayName') or 'User %s' % tag['id'])
for tag in people)
msg_data = collections.OrderedDict({'message': content.encode('utf-8')})
if appengine_config.LOCAL:
msg_data['privacy'] = json_dumps({'value': 'SELF'})

if type == 'comment':
if not base_url:
Expand Down Expand Up @@ -913,8 +911,8 @@ def create_notification(self, user_id, text, link):
'href': link,
# this is a synthetic app access token.
# https://developers.facebook.com/docs/facebook-login/access-tokens/#apptokens
'access_token': '%s|%s' % (appengine_config.FACEBOOK_APP_ID,
appengine_config.FACEBOOK_APP_SECRET),
'access_token': '%s|%s' % (oauth_dropins.facebook.FACEBOOK_APP_ID,
oauth_dropins.facebook.FACEBOOK_APP_SECRET),
}
url = API_BASE + API_NOTIFICATION % user_id
resp = util.urlopen(urllib.request.Request(url, data=urllib.parse.urlencode(params)))
Expand Down
2 changes: 0 additions & 2 deletions granary/flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import mf2util
import urllib.parse

from . import appengine_config

from oauth_dropins.webutil import util
from oauth_dropins import flickr_auth

Expand Down
1 change: 0 additions & 1 deletion granary/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from oauth_dropins.webutil.util import json_dumps, json_loads
import requests

from . import appengine_config
from . import source

REST_API_BASE = 'https://api.github.com'
Expand Down
4 changes: 1 addition & 3 deletions granary/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import urllib.parse, urllib.request
import xml.sax.saxutils

from . import appengine_config
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads
import requests
Expand All @@ -35,8 +34,7 @@
API_MEDIA_LIKES_URL = 'https://api.instagram.com/v1/media/%s/likes'
API_COMMENT_URL = 'https://api.instagram.com/v1/media/%s/comments'

HTML_BASE_URL = (appengine_config.read('instagram_scrape_base') or
'https://www.instagram.com/')
HTML_BASE_URL = util.read('instagram_scrape_base') or 'https://www.instagram.com/'
HTML_MEDIA = HTML_BASE_URL + 'p/%s/'
HTML_PROFILE = HTML_BASE_URL + '%s/'
HTML_PRELOAD_RE = re.compile(
Expand Down
1 change: 0 additions & 1 deletion granary/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from oauth_dropins.webutil.util import json_dumps, json_loads
import requests

from . import appengine_config
from . import source

API_ACCOUNT = '/api/v1/accounts/%s'
Expand Down
2 changes: 0 additions & 2 deletions granary/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads

from . import appengine_config

ME = '@me'
SELF = '@self'
ALL = '@all'
Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_as2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Most of the tests are in testdata/. This is just a few things that are too small
for full testdata tests.
"""
from .. import appengine_config
from oauth_dropins.webutil import testutil

from .. import as2
Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Unit tests for atom.py."""
import copy

from .. import appengine_config
from mox3 import mox
from oauth_dropins.webutil import testutil
import requests
Expand Down
9 changes: 4 additions & 5 deletions granary/tests/test_facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import urllib.parse

from mox3 import mox
import oauth_dropins.facebook
from oauth_dropins.webutil import testutil
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads

from .. import appengine_config
from .. import facebook
from ..facebook import (
API_ALBUMS,
Expand Down Expand Up @@ -1050,8 +1050,7 @@ def tag_uri(name):
"""

def read_testdata(filename):
return appengine_config.read(os.path.join(os.path.dirname(__file__),
'testdata', filename))
return util.read(os.path.join(os.path.dirname(__file__), 'testdata', filename))

COMMENT_EMAIL = read_testdata('facebook.comment.email.html')
COMMENT_EMAIL_USER_ID = COMMENT_EMAIL % {
Expand Down Expand Up @@ -2929,8 +2928,8 @@ def test_create_with_video(self):
self.assert_equals({'type': 'post', 'url': None}, self.fb.create(obj).content)

def test_create_notification(self):
appengine_config.FACEBOOK_APP_ID = 'my_app_id'
appengine_config.FACEBOOK_APP_SECRET = 'my_app_secret'
oauth_dropins.facebook.FACEBOOK_APP_ID = 'my_app_id'
oauth_dropins.facebook.FACEBOOK_APP_SECRET = 'my_app_secret'
params = {
'template': 'my text',
'href': 'my link',
Expand Down
6 changes: 3 additions & 3 deletions granary/tests/test_flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import socket
import urllib.parse

from oauth_dropins import appengine_config
from oauth_dropins import flickr_auth
from oauth_dropins.webutil import testutil
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads
Expand Down Expand Up @@ -661,8 +661,8 @@ class FlickrTest(testutil.TestCase):

def setUp(self):
super(FlickrTest, self).setUp()
appengine_config.FLICKR_APP_KEY = 'fake'
appengine_config.FLICKR_APP_SECRET = 'fake'
flickr_auth.FLICKR_APP_KEY = 'fake'
flickr_auth.FLICKR_APP_SECRET = 'fake'
self.flickr = flickr.Flickr('key', 'secret')

def expect_call_api_method(self, method, params, result):
Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads

from .. import appengine_config
from .. import github
from ..github import (
GRAPHQL_BASE,
Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_jsonfeed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8
"""Unit tests for jsonfeed.py."""
from .. import appengine_config
from oauth_dropins.webutil import testutil

from ..jsonfeed import activities_to_jsonfeed, jsonfeed_to_activities
Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from oauth_dropins.webutil import testutil, util
from oauth_dropins.webutil.util import json_dumps, json_loads

from .. import appengine_config
from .. import mastodon
from .. import source
from ..mastodon import (
Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
import re

from .. import appengine_config
from oauth_dropins.webutil import testutil
import mf2py

Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_rss.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8
"""Unit tests for rss.py."""
from .. import appengine_config
from oauth_dropins.webutil import testutil

from .. import rss
Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import copy
import re

from .. import appengine_config
from oauth_dropins.webutil import testutil
from oauth_dropins.webutil import util

Expand Down
1 change: 0 additions & 1 deletion granary/tests/test_testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import os

from .. import appengine_config
from oauth_dropins.webutil import testutil
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads
Expand Down
6 changes: 3 additions & 3 deletions granary/tests/test_twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import urllib.parse

from mox3 import mox
from oauth_dropins import appengine_config
from oauth_dropins import twitter_auth
from oauth_dropins.webutil import testutil
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads
Expand Down Expand Up @@ -705,8 +705,8 @@ class TwitterTest(testutil.TestCase):
def setUp(self):
super(TwitterTest, self).setUp()
self.maxDiff = None
appengine_config.TWITTER_APP_KEY = 'fake'
appengine_config.TWITTER_APP_SECRET = 'fake'
twitter_auth.TWITTER_APP_KEY = 'fake'
twitter_auth.TWITTER_APP_SECRET = 'fake'
self.twitter = twitter.Twitter('key', 'secret')

def expect_urlopen(self, url, response=None, params=None, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions granary/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import socket
import urllib.parse, urllib.request

from . import appengine_config

from oauth_dropins import twitter_auth
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import json_dumps, json_loads
Expand Down
5 changes: 3 additions & 2 deletions instagram_live_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import sys
import unittest

from granary import appengine_config
from oauth_dropins.webutil import util
from oauth_dropins.instagram import INSTAGRAM_SESSIONID_COOKIE
from granary import instagram
from granary.source import SELF

Expand All @@ -20,7 +21,7 @@
class InstagramTestLive(unittest.TestCase):

def test_live(self):
ig = instagram.Instagram(cookie=appengine_config.INSTAGRAM_SESSIONID_COOKIE)
ig = instagram.Instagram(cookie=INSTAGRAM_SESSIONID_COOKIE)
resp = ig.get_activities_response(
user_id=USERNAME, group_id=SELF, scrape=True,
fetch_replies=True, fetch_likes=True, count=10)
Expand Down
12 changes: 0 additions & 12 deletions test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@
import copy
import socket

# webutil.tests must be imported before appengine_config!
#
# Both the App Engine SDK and the google-auth library (installed in our
# virtualenv) provide the google package. This works locally, ie we can import
# from both places, but doesn't work on Circle. Not sure why. This fixes that.
#
# Related:
# https://github.com/googleapis/google-auth-library-python/issues/169#issuecomment-315417916
# https://stackoverflow.com/questions/49194575
import oauth_dropins.webutil.tests
import appengine_config

from oauth_dropins.webutil import testutil
from oauth_dropins.webutil.util import json_dumps, json_loads

Expand Down
Loading

0 comments on commit ac38264

Please sign in to comment.