Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
Fix test_gcm_send
Browse files Browse the repository at this point in the history
  • Loading branch information
Mechazawa committed Aug 26, 2016
1 parent 2173347 commit 4256f60
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion controllers/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from flask import Blueprint, jsonify, request
from flask import current_app

from utils import Error, has_uuid, has_secret, queue_zmq_message
from shared import db
from models import Subscription, Message, Gcm
Expand Down Expand Up @@ -30,7 +32,7 @@ def message_send(service):
db.session.add(msg)
db.session.commit()

if google_api_key:
if google_api_key or current_app.config['TESTING']:
Gcm.send_message(msg)

if zeromq_relay_uri:
Expand Down
2 changes: 1 addition & 1 deletion models/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ def gcm_send(ids, data):
data = dict(registration_ids=ids, data=data)

if current_app.config['TESTING'] is True:
current_app.config['TESTING_GCM'](data)
current_app.config['TESTING_GCM'].append(data)
else:
requests.post(url, json=data, headers=headers)
7 changes: 4 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class PushjetTestCase(unittest.TestCase):
def setUp(self):
config.google_api_key = config.google_api_key or 'PLACEHOLDER'
self.uuid = str(uuid4())
self.gcm = []

app.config['TESTING'] = True
app.config['TESTING_GCM'] = lambda x: self.gcm.append(x)
app.config['TESTING_GCM'] = []

self.gcm = app.config['TESTING_GCM']
self.app = app.test_client()
self.app_real = app

def _random_str(self, length=10, unicode=True):
# A random string with the "cupcake" in Japanese appended to it
Expand Down Expand Up @@ -207,7 +208,7 @@ def test_gcm_register_double(self):
self.test_gcm_register()
self.test_gcm_register()

def test_gmc_send(self):
def test_gcm_send(self):
reg_id = self.test_gcm_register()
public, secret, data = self.test_message_send()

Expand Down

0 comments on commit 4256f60

Please sign in to comment.