示例#1
0
    def post(self):
        self._require_login()
        self._require_registration()

        # Check to make sure that they aren't trying to edit another user
        current_user_account_id = self.user_bundle.account.key.id()
        target_account_id = self.request.get('account_id')
        if target_account_id == current_user_account_id:
            client_id = self.request.get('client_id')
            client = MobileClient.get_by_id(int(client_id),
                                            parent=ndb.Key(
                                                Account,
                                                current_user_account_id))
            if client is not None:
                # This makes sure that the client actually exists and that this user owns it
                if client.client_type == ClientType.WEBHOOK:
                    keys = {
                        client.client_type:
                        [(client.messaging_id, client.secret)]
                    }
                else:
                    keys = {client.client_type: [client.messaging_id]}
                notification = PingNotification()
                notification.send(keys)
            self.redirect('/account')
        else:
            self.redirect('/')
class TestBaseNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # User a Ping notification to test the render and send classes
        # It's as simple as it gets
        self.notification = PingNotification()
        self.keys = {ClientType.OS_ANDROID: ["abc123"], ClientType.WEBHOOK: ["123abc"]}
        self.notification.keys = self.keys

    def tearDown(self):
        self.testbed.deactivate()

    def test_render_android(self):
        message = self.notification._render_android()

        self.assertEqual(self.keys[ClientType.OS_ANDROID], message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)

    def test_render_webhook(self):
        message = self.notification._render_webhook()

        self.assertEqual(message, self.notification._build_dict())

    def test_render_ios(self):
        pass
class TestBaseNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # User a Ping notification to test the render and send classes
        # It's as simple as it gets
        self.notification = PingNotification()
        self.keys = {
            ClientType.OS_ANDROID: ["abc123"],
            ClientType.WEBHOOK: ["123abc"]
        }
        self.notification.keys = self.keys

    def tearDown(self):
        self.testbed.deactivate()

    def test_render_android(self):
        message = self.notification._render_android()

        self.assertEqual(self.keys[ClientType.OS_ANDROID],
                         message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)

    def test_render_webhook(self):
        message = self.notification._render_webhook()

        self.assertEqual(message, self.notification._build_dict())

    def test_render_ios(self):
        pass
 def send_ping(cls, client):
     if client.client_type == ClientType.OS_ANDROID:
         notification = PingNotification()
         notification.send({client.client_type: [client.messaging_id]})
     else:
         # Send iOS/web/webhooks ping via TBANS
         return TBANSHelper.ping(client)
 def send_ping(cls, client):
     if client.client_type == ClientType.OS_ANDROID:
         notification = PingNotification()
         notification.send({client.client_type: [client.messaging_id]})
     else:
         # Send iOS/web/webhooks ping via TBANS
         return TBANSHelper.ping(client)
    def send_ping(cls, client):
        if client.client_type == ClientType.WEBHOOK:
            keys = {client.client_type: [(client.messaging_id, client.secret)]}
        else:
            keys = {client.client_type: [client.messaging_id]}

        notification = PingNotification()
        notification.send(keys)
示例#7
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub(root_path=".")

        self.notification = PingNotification()
示例#8
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # User a Ping notification to test the render and send classes
        # It's as simple as it gets
        self.notification = PingNotification()
        self.keys = {ClientType.OS_ANDROID: ["abc123"], ClientType.WEBHOOK: ["123abc"]}
        self.notification.keys = self.keys
示例#9
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()  # Prevent data from leaking between tests

        self.testbed.init_taskqueue_stub(root_path=".")

        self.notification = PingNotification()
示例#10
0
class TestUserPingNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache(
        )  # Prevent data from leaking between tests

        self.testbed.init_taskqueue_stub(root_path=".")

        self.notification = PingNotification()

    def tearDown(self):
        self.testbed.deactivate()

    def test_build(self):
        expected = {}
        expected['message_type'] = NotificationType.type_names[
            NotificationType.PING]
        expected['message_data'] = {
            'title':
            "Test Message",
            'desc':
            "This is a test message ensuring your device can recieve push messages from The Blue Alliance."
        }

        data = self.notification._build_dict()

        self.assertEqual(expected, data)
示例#11
0
class TestBaseNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # User a Ping notification to test the render and send classes
        # It's as simple as it gets
        self.notification = PingNotification()
        self.keys = {ClientType.OS_IOS: ["abc123"], ClientType.OS_ANDROID: ["abc123"], ClientType.WEB: ["abc123"], ClientType.WEBHOOK: ["123abc"]}
        self.notification.keys = self.keys

    def tearDown(self):
        self.testbed.deactivate()

    def test_render_android(self):
        self._test_render_gcm(ClientType.OS_ANDROID)

    def test_render_ios(self):
        self._test_render_gcm(ClientType.OS_IOS)

    def test_render_web(self):
        self._test_render_gcm(ClientType.WEB)

    def test_render_webhook(self):
        message = self.notification._render_webhook()

        self.assertEqual(message, self.notification._build_dict())

    def _test_render_gcm(self, client_type):
        message = self.notification._render_gcm(client_type)

        self.assertEqual(self.keys[client_type], message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)

    def test_render_method(self):
        self.assertEqual(self.notification.render_method(ClientType.OS_ANDROID), self.notification._render_android)
        self.assertEqual(self.notification.render_method(ClientType.OS_IOS), self.notification._render_ios)
        self.assertEqual(self.notification.render_method(ClientType.WEB), self.notification._render_web)
        self.assertEqual(self.notification.render_method(ClientType.WEBHOOK), self.notification._render_webhook)

    def test_render_method_renders(self):
        client_type = ClientType.OS_IOS
        client_render_method = self.notification.render_method(client_type)

        message = client_render_method()
        self.assertEqual(self.keys[client_type], message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub(root_path=".")

        self.notification = PingNotification()
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # User a Ping notification to test the render and send classes
        # It's as simple as it gets
        self.notification = PingNotification()
        self.keys = {ClientType.OS_ANDROID: ["abc123"], ClientType.WEBHOOK: ["123abc"]}
        self.notification.keys = self.keys
    def post(self):
        self._require_registration()

        # Check to make sure that they aren't trying to edit another user
        current_user_account_id = self.user_bundle.account.key.id()
        target_account_id = self.request.get('account_id')
        if target_account_id == current_user_account_id:
            client_id = self.request.get('client_id')
            client = MobileClient.get_by_id(int(client_id), parent=ndb.Key(Account, current_user_account_id))
            if client is not None:
                # This makes sure that the client actually exists and that this user owns it
                if client.client_type == ClientType.WEBHOOK:
                    keys = {client.client_type: [(client.messaging_id, client.secret)]}
                else:
                    keys = {client.client_type: [client.messaging_id]}
                notification = PingNotification()
                notification.send(keys)
            self.redirect('/account')
        else:
            self.redirect('/')
class TestBaseNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # User a Ping notification to test the render and send classes
        # It's as simple as it gets
        self.notification = PingNotification()
        self.keys = {
            ClientType.OS_ANDROID: ["abc123"],
            ClientType.WEBHOOK: ["123abc"]
        }
        self.notification.keys = self.keys

    def tearDown(self):
        self.testbed.deactivate()

    def test_render_android(self):
        self._test_render_gcm(ClientType.OS_ANDROID)

    def test_render_webhook(self):
        message = self.notification._render_webhook()
        expect = {
            'message_type': 'ping',
            'message_data': {
                'title':
                'Test Message',
                'desc':
                'This is a test message ensuring your device can recieve push messages from The Blue Alliance.'
            }
        }
        self.assertEqual(message, expect)

    def _test_render_gcm(self, client_type):
        message = self.notification._render_gcm(client_type)

        self.assertEqual(self.keys[client_type], message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)

    def test_render_method(self):
        self.assertEqual(
            self.notification.render_method(ClientType.OS_ANDROID),
            self.notification._render_android)
        self.assertEqual(self.notification.render_method(ClientType.WEBHOOK),
                         self.notification._render_webhook)

    def test_render_method_renders(self):
        client_type = ClientType.OS_ANDROID
        client_render_method = self.notification.render_method(client_type)

        message = client_render_method()
        self.assertEqual(self.keys[client_type], message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)
示例#16
0
    def get(self):
        webhooks = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch()
        failures = []

        notification = PingNotification()._render_webhook()

        for key in webhooks:
            if not NotificationSender.send_webhook(notification, [(key.messaging_id, key.secret)]):
                failures.append(key.key)

        count = len(failures)
        if failures:
            ndb.delete_multi(failures)
        logging.info("Deleted {} broken webhooks".format(count))

        template_values = {'count': count}
        path = os.path.join(os.path.dirname(__file__), '../../templates/admin/webhooks_clear_do.html')
        self.response.out.write(template.render(path, template_values))
class TestUserPingNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.notification = PingNotification()

    def tearDown(self):
        self.testbed.deactivate()

    def test_build(self):
        expected = {}
        expected['message_type'] = NotificationType.type_names[NotificationType.PING]
        expected['message_data'] = {'title': "Test Message",
                                    'desc': "This is a test message ensuring your device can recieve push messages from The Blue Alliance."}

        data = self.notification._build_dict()

        self.assertEqual(expected, data)
示例#18
0
class TestUserPingNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.notification = PingNotification()

    def tearDown(self):
        self.testbed.deactivate()

    def test_build(self):
        expected = {}
        expected['message_type'] = NotificationType.type_names[NotificationType.PING]
        expected['message_data'] = {'title': "Test Message",
                                    'desc': "This is a test message ensuring your device can recieve push messages from The Blue Alliance."}

        data = self.notification._build_dict()

        self.assertEqual(expected, data)
class TestBaseNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # User a Ping notification to test the render and send classes
        # It's as simple as it gets
        self.notification = PingNotification()
        self.keys = {ClientType.OS_ANDROID: ["abc123"], ClientType.WEBHOOK: ["123abc"]}
        self.notification.keys = self.keys

    def tearDown(self):
        self.testbed.deactivate()

    def test_render_android(self):
        self._test_render_gcm(ClientType.OS_ANDROID)

    def test_render_webhook(self):
        message = self.notification._render_webhook()
        expect = {
            'message_type': 'ping',
            'message_data': {
                'title': 'Test Message',
                'desc': 'This is a test message ensuring your device can recieve push messages from The Blue Alliance.'
            }
        }
        self.assertEqual(message, expect)

    def _test_render_gcm(self, client_type):
        message = self.notification._render_gcm(client_type)

        self.assertEqual(self.keys[client_type], message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)

    def test_render_method(self):
        self.assertEqual(self.notification.render_method(ClientType.OS_ANDROID), self.notification._render_android)
        self.assertEqual(self.notification.render_method(ClientType.WEBHOOK), self.notification._render_webhook)

    def test_render_method_renders(self):
        client_type = ClientType.OS_ANDROID
        client_render_method = self.notification.render_method(client_type)

        message = client_render_method()
        self.assertEqual(self.keys[client_type], message.device_tokens)
        self.assertEqual(self.notification._build_dict(), message.notification)
class TestUserPingNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()  # Prevent data from leaking between tests

        self.testbed.init_taskqueue_stub(root_path=".")

        self.notification = PingNotification()

    def tearDown(self):
        self.testbed.deactivate()

    def test_build(self):
        expected = {}
        expected['notification_type'] = NotificationType.type_names[NotificationType.PING]
        expected['message_data'] = {'title': "Test Message",
                                    'desc': "This is a test message ensuring your device can recieve push messages from The Blue Alliance."}

        data = self.notification._build_dict()

        self.assertEqual(expected, data)
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.notification = PingNotification()
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.notification = PingNotification()