Skip to content

Commit

Permalink
add instagram live test and cron job to trigger nightly circle build
Browse files Browse the repository at this point in the history
for #106
  • Loading branch information
snarfed committed Jul 26, 2017
1 parent ff219b2 commit d0d3776
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@
/*.egg-info
/l
/local/
circleci_token
datastore.dat
oauth_client_secret
plus-dogfood.json
Expand Down
5 changes: 5 additions & 0 deletions app.yaml
Expand Up @@ -50,6 +50,11 @@ handlers:
script: app.application
secure: always

- url: /cron/build_circle
script: cron.application
login: admin
secure: always

- url: /.+
script: activitystreams.application
secure: always
Expand Down
1 change: 1 addition & 0 deletions circle.yml
Expand Up @@ -25,5 +25,6 @@ test:
override:
- python -m coverage run --source=. --omit=granary/test/\*,local/\*,oauth-dropins/\*,old_apps/\*,setup.py,test_\* -m unittest discover -v
- python -m coverage html -d $CIRCLE_ARTIFACTS
- python ./instagram_live_test.py --debug
post:
- if [ "$COVERALLS_REPO_TOKEN" != "" ]; then coveralls; fi
19 changes: 19 additions & 0 deletions cron.py
@@ -0,0 +1,19 @@
"""Cron jobs. Currently just nightly CircleCI build."""

import appengine_config

import requests
import webapp2

CIRCLECI_TOKEN = appengine_config.read('circleci_token')


class BuildCircle(webapp2.RequestHandler):
def get(self):
resp = requests.post('https://circleci.com/api/v1.1/project/github/snarfed/granary/tree/master?circle-token=%s' % CIRCLECI_TOKEN)
resp.raise_for_status()


application = webapp2.WSGIApplication([
('/cron/build_circle', BuildCircle),
], debug=appengine_config.DEBUG)
7 changes: 7 additions & 0 deletions cron.yaml
@@ -0,0 +1,7 @@
# timezone defaults to UTC
# docs: https://developers.google.com/appengine/docs/python/config/cron

cron:
- description: nightly CircleCI build
url: /cron/build_circle
schedule: every 24 hours
53 changes: 53 additions & 0 deletions instagram_live_test.py
@@ -0,0 +1,53 @@
#!/usr/bin/env python
"""Instagram integration test against the live site.
Just checks that fetching and converting snarfed's feed includes 12 activities,
and all the expected fields are non-empty.
https://github.com/snarfed/granary/issues/106
"""
import logging
import sys
import unittest

from granary import instagram
from granary.source import SELF

USERNAME = 'snarfed'


class InstagramTestLive(unittest.TestCase):

def test_live(self):
resp = instagram.Instagram().get_activities_response(
user_id=USERNAME, group_id=SELF, scrape=True,
fetch_replies=True, fetch_likes=True)

for field in 'username', 'displayName', 'url', 'image', 'id':
self.assertTrue(resp['actor'][field], field)

self.assertTrue(resp['actor']['image']['url'])

items = resp['items']
self.assertEqual(12, len(items))

found = set()
for a in items:
self.assertTrue(a['actor'])
for field in 'id', 'url', 'attachments', 'author', 'image':
self.assertTrue(a['object'][field], field)
for field in 'content', 'replies', 'tags':
if a['object'].get(field):
found.add(field)

for field in 'content', 'replies', 'tags':
self.assertIn(field, found)


if __name__ == '__main__':
if '--debug' in sys.argv:
sys.argv.remove('--debug')
logging.getLogger().setLevel(logging.DEBUG)
else:
logging.getLogger().setLevel(logging.CRITICAL + 1)
unittest.main()

0 comments on commit d0d3776

Please sign in to comment.