<commit_before>from datetime import datetime
from zeit.cms.checkout.helper import checked_out
from zeit.push.interfaces import PARSE_NEWS_CHANNEL, PARSE_BREAKING_CHANNEL
from zeit.push.testing import parse_settings as settings
import mock
import pytz
import unittest
import urlparse
import zeit.push.parse
import zeit.push.testing
import zope.app.appsetup.product


class ParseTest(unittest.TestCase):

    level = 2

    def test_push_works(self):
        # Parse offers no REST API to retrieve push messages,
        # so this is just a smoke test.
        api = zeit.push.parse.Connection(
            settings['application_id'], settings['rest_api_key'], 1)
        api.send('Being pushy.', 'http://example.com', skip_ios=True)

    def test_push_works_with_channels(self):
        api = zeit.push.parse.Connection(
            settings['application_id'], settings['rest_api_key'], 1)
        api.send('Being pushy.', 'http://example.com', channels=['News'],
                 skip_ios=True)

    def test_invalid_credentials_should_raise(self):
        api = zeit.push.parse.Connection('invalid', 'invalid', 1)
        with self.assertRaises(zeit.push.interfaces.WebServiceError):
            api.send('Being pushy.', 'http://example.com')

    def test_channel_breaking_is_pushed_to_all_supporting_app_versions(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('Foo', 'http://b.ar', channels=PARSE_BREAKING_CHANNEL)
            self.assertEqual(7, len(push.call_args_list))

    def test_channel_news_is_pushed_to_all_supporting_app_versions(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('Foo', 'http://b.ar', channels=PARSE_NEWS_CHANNEL)
            self.assertEqual(5, len(push.call_args_list))

    def test_sends_newest_version_first(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('Foo', 'http://b.ar', channels=PARSE_NEWS_CHANNEL)
            self.assertEqual(
                zeit.push.parse.Connection.ANDROID_FRIEDBERT_VERSION,
                push.call_args_list[0][0][0]['where']['appVersion']['$gte'])
            self.assertEqual(
                zeit.push.parse.Connection.IOS_FRIEDBERT_VERSION,
                push.call_args_list[2][0][0]['where']['appVersion']['$gte'])

    def test_friedbert_version_links_to_app_content(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('', 'http://www.zeit.de/bar', channels=PARSE_NEWS_CHANNEL)
            self.assertEqual(
                'http://app-content.zeit.de/bar',
                push.call_args_list[0][0][0]['data']['url'].split('?')[0])
            self.assertEqual(
                'http://app-content.zeit.de/bar',
                push.call_args_list[0][0][0]['data']['url'].split('?')[0])


class RewriteWrapperURLTest(unittest.TestCase):<commit_msg>re DEV-938: Fix test to check URL of iOS as well, rather checking Android twice.<commit_after>from datetime import datetime
from zeit.cms.checkout.helper import checked_out
from zeit.push.interfaces import PARSE_NEWS_CHANNEL, PARSE_BREAKING_CHANNEL
from zeit.push.testing import parse_settings as settings
import mock
import pytz
import unittest
import urlparse
import zeit.push.parse
import zeit.push.testing
import zope.app.appsetup.product


class ParseTest(unittest.TestCase):

    level = 2

    def test_push_works(self):
        # Parse offers no REST API to retrieve push messages,
        # so this is just a smoke test.
        api = zeit.push.parse.Connection(
            settings['application_id'], settings['rest_api_key'], 1)
        api.send('Being pushy.', 'http://example.com', skip_ios=True)

    def test_push_works_with_channels(self):
        api = zeit.push.parse.Connection(
            settings['application_id'], settings['rest_api_key'], 1)
        api.send('Being pushy.', 'http://example.com', channels=['News'],
                 skip_ios=True)

    def test_invalid_credentials_should_raise(self):
        api = zeit.push.parse.Connection('invalid', 'invalid', 1)
        with self.assertRaises(zeit.push.interfaces.WebServiceError):
            api.send('Being pushy.', 'http://example.com')

    def test_channel_breaking_is_pushed_to_all_supporting_app_versions(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('Foo', 'http://b.ar', channels=PARSE_BREAKING_CHANNEL)
            self.assertEqual(7, len(push.call_args_list))

    def test_channel_news_is_pushed_to_all_supporting_app_versions(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('Foo', 'http://b.ar', channels=PARSE_NEWS_CHANNEL)
            self.assertEqual(5, len(push.call_args_list))

    def test_sends_newest_version_first(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('Foo', 'http://b.ar', channels=PARSE_NEWS_CHANNEL)
            self.assertEqual(
                zeit.push.parse.Connection.ANDROID_FRIEDBERT_VERSION,
                push.call_args_list[0][0][0]['where']['appVersion']['$gte'])
            self.assertEqual(
                zeit.push.parse.Connection.IOS_FRIEDBERT_VERSION,
                push.call_args_list[2][0][0]['where']['appVersion']['$gte'])

    def test_friedbert_version_links_to_app_content(self):
        api = zeit.push.parse.Connection(None, None, 1)
        with mock.patch.object(api, 'push') as push:
            api.send('', 'http://www.zeit.de/bar', channels=PARSE_NEWS_CHANNEL)
            android = push.call_args_list[0][0][0]
            self.assertEqual(
                'http://app-content.zeit.de/bar',
                android['data']['url'].split('?')[0])
            ios = push.call_args_list[2][0][0]
            self.assertEqual(
                'http://app-content.zeit.de/bar',
                ios['data']['aps']['url'].split('?')[0])


class RewriteWrapperURLTest(unittest.TestCase):
{'fraction_non_alphanumeric': 0.133991088478676, 'fraction_numerical': 0.008115849777211966, 'mean_word_length': 3.0108487555839183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5608873', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1939, 'n_words': 339}