class TestNotifications(unittest.TestCase): def setUp(self): self.app = pp_tests.get_app() self.connection, self.db = pp_tests.connect_to_mongo() self.account = pp_tests.create_account_and_login(self.app, self.db, { 'email': '*****@*****.**', 'password': '******', 'name': 'Daniel', 'startup': 'Payparrot', 'url': 'http://payparrot.com/', 'callback_url': 'http://www.epistemonikos.org', 'notification_url': 'http://www.epistemonikos.org', }) self.notification = Notifications(self.db, { 'suscription_id': ObjectId(), 'account_id': self.account.id, 'external_id': '238462834', 'parrot_id': ObjectId(), 'request_url': 'http://localhost:3000/notifications/echo', 'status': 'pending', 'type': 'subscription_activated' }) self.notification.insert() def tearDown(self): pp_tests.tear_down(self.db, self.app) self.connection.close() def test_get_notification(self): response = self.app.get('/accounts/%s/notifications/%s' % (self.account.id, self.notification.id)) expected = self.notification.JSON() self.assertEqual(200, response.status_int) self.assertEqual(expected, response.json)
def _create_notification(db, account,parrot,subscription): notification = Notifications(db, { 'account_id': account.id, 'parrot_id': parrot.id, 'type': 'subscription_activated', 'subscription_id': subscription.id, 'external_id': subscription.external_id, 'request_url': account.notification_url }) notification.insert() return notification.id
def send_notification(db, payment, notification_type): subscription = Subscriptions.findOne(db, {'account_id': payment.account_id, 'parrot_id': payment.parrot_id}) if subscription: account = Accounts.findOne(db, payment.account_id) if account: notification = Notifications(db, { 'account_id': payment.account_id, 'parrot_id': payment.parrot_id, 'type': notification_type, 'subscription_id': subscription.id, 'external_id': subscription.external_id, 'request_url': account.notification_url }) notification.insert()