def setUp(self):
     super(TestCase, self).setUp()
     article_legacy = ARTICLE.copy()
     article_legacy['anpa_category'] = [{
         'name': 'service1'
     }, {
         'name': 'service2'
     }, {
         'name': 'service3'
     }]
     self.formatter = NTBNITFMultiFileFormatter()
     self.base_formatter = Formatter()
     init_app(self.app)
     self.tz = pytz.timezone(self.app.config['DEFAULT_TIMEZONE'])
     if self.article is None:
         # formatting is done once for all tests to save time
         # as long as used attributes are not modified, it's fine
         self.article = article_legacy
         self.formatter_output = self.formatter.format(
             self.article, {'name': 'Test NTBNITF'})
         self.docs = [
             formatter['encoded_item']
             for formatter in self.formatter_output
         ]
         self.nitf_xmls = [etree.fromstring(doc) for doc in self.docs]
         self.nitf_xml = self.nitf_xmls[0]
Example #2
0
    def setUp(self):
        super().setUp()
        self.init_data()

        self.app.data.insert('users', self.users)
        self.app.data.insert('desks', self.desks)
        self.app.data.insert('products', self.products)
        self.app.data.insert('subscribers', self.subscribers)
        self.app.data.insert(ARCHIVE, self.articles)

        self.filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), "validators.json")
        self.json_data = [
            {"_id": "kill_text", "act": "kill", "type": "text", "schema": {"headline": {"type": "string"}}},
            {"_id": "publish_text", "act": "publish", "type": "text", "schema": {}},
            {"_id": "correct_text", "act": "correct", "type": "text", "schema": {}},
            {"_id": "publish_composite", "act": "publish", "type": "composite", "schema": {}},
        ]
        self.article_versions = self._init_article_versions()

        with open(self.filename, "w+") as file:
            json.dump(self.json_data, file)
        init_app(self.app)
        ValidatorsPopulateCommand().run(self.filename)

        self.app.media.url_for_media = MagicMock(return_value='url_for_media')
        self.app.media.put = MagicMock(return_value='media_id')
Example #3
0
    def setUp(self):
        self.init_data()

        self.app.data.insert('users', self.users)
        self.app.data.insert('desks', self.desks)
        self.app.data.insert('products', self.products)
        self.app.data.insert('subscribers', self.subscribers)
        self.app.data.insert(ARCHIVE, self.articles)

        self.filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), "validators.json")
        self.json_data = [
            {"_id": "kill_text", "act": "kill", "type": "text", "schema": {"headline": {"type": "string"}}},
            {"_id": "publish_text", "act": "publish", "type": "text", "schema": {}},
            {"_id": "correct_text", "act": "correct", "type": "text", "schema": {}},
            {"_id": "publish_composite", "act": "publish", "type": "composite", "schema": {}},
        ]
        self.article_versions = self._init_article_versions()

        with open(self.filename, "w+") as file:
            json.dump(self.json_data, file)
        init_app(self.app)
        ValidatorsPopulateCommand().run(self.filename)

        self.app.media.url_for_media = MagicMock(return_value='url_for_media')
        self._put = self.app.media.put
        self.app.media.put = MagicMock(return_value='media_id')
Example #4
0
    def test_files_publishing(self):
        init_app(self.app)
        with tempfile.NamedTemporaryFile(suffix='txt') as input:
            input.write('foo'.encode('utf-8'))
            input.seek(0)
            input.filename = 'foo.txt'
            input.mimetype = 'text/plain'
            attachment = {'media': input}
            store_media_files(attachment, 'events_files')
            files_ids = self.app.data.insert('events_files', [attachment])
        item = self.item.copy()
        item['files'] = files_ids

        subscriber = {'name': 'Test Subscriber', 'is_active': True}
        destination = {'delivery_type': 'http_push'}
        formatter = JsonEventFormatter()
        formatter.set_destination(destination, subscriber)
        with mock.patch.object(registered_transmitters['http_push'], '_transmit_media', return_value='new-href') as push_media:  # noqa
            output = formatter.format(item, subscriber)[0]
            push_media.assert_called_once_with(mock.ANY, destination)

        output_item = json.loads(output[1])
        self.assertEqual(1, len(output_item['files']))
        self.assertEqual({
            'name': 'foo.txt',
            'length': 3,
            'mimetype': 'text/plain',
            'media': str(self.app.data.find_one('events_files', req=None, _id=files_ids[0]).get('media')),
        }, output_item['files'][0])
 def setUp(self):
     self.app.data.insert('vocabularies', self.vocab)
     self.formatter = ReutersNewsML12Formatter()
     self.base_formatter = Formatter()
     init_app(self.app)
     self.app.config['INIT_DATA_PATH'] = os.path.abspath(
         os.path.join(os.path.abspath(os.path.dirname(__file__)), '../../../data'))
    def setUp(self):
        init_app(self.app)
        self.app.data.insert('users', self.users)
        self.app.data.insert('archive', self.archive)

        # insert pictures
        media_items = (
            {
                '_id': 'pic_1',
                'content': BytesIO(b'pic_one_content'),
                'content_type': 'image/jpeg',
                'metadata': {
                    'length': 10
                }
            },
            {
                '_id': 'video_1',
                'content': BytesIO(b'czech rap xD'),
                'content_type': 'video/mp4',
                'metadata': {
                    'length': 12
                }
            },
        )
        for media_item in media_items:
            # base rendition
            self.app.media.put(**media_item)

        self.article['state'] = 'published'
        self.formatter = BelgaNewsML12Formatter()
        seq, doc = self.formatter.format(self.article, self.subscriber)[0]
        self.newsml = etree.XML(
            bytes(bytearray(doc, encoding=BelgaNewsML12Formatter.ENCODING)))
Example #7
0
 def setUp(self):
     init_app(self.app)
     self.app.data.insert('archive', self.archive)
     self.formatter = NTBNITFFormatter()
     self.formatter_output = self.formatter.format(self.archive[-1],
                                                   {'name': 'Test NTBNITF'})
     self.doc = self.formatter_output[0]['encoded_item']
     self.nitf_xml = etree.fromstring(self.doc)
Example #8
0
    def setUp(self):
        self.subscribers[0]['destinations'][0]['config']['connection_string'] = \
            superdesk.app.config["ODBC_TEST_CONNECTION_STRING"]
        self.app.data.insert('subscribers', self.subscribers)

        self.queue_items[0]['destination']['config']['connection_string'] = \
            superdesk.app.config["ODBC_TEST_CONNECTION_STRING"]
        self.app.data.insert('publish_queue', self.queue_items)
        init_app(self.app)
Example #9
0
    def setUp(self):
        self.subscribers[0]['destinations'][0]['config']['connection_string'] = \
            superdesk.app.config["ODBC_TEST_CONNECTION_STRING"]
        self.app.data.insert('subscribers', self.subscribers)

        self.queue_items[0]['destination']['config']['connection_string'] = \
            superdesk.app.config["ODBC_TEST_CONNECTION_STRING"]
        self.app.data.insert('publish_queue', self.queue_items)
        init_app(self.app)
Example #10
0
 def setUp(self):
     self.article['state'] = 'published'
     self._setup_dates([self.article])
     self.newsml = etree.Element("NewsML")
     self.formatter = KVHNewsML12Formatter()
     self.formatter.now = self.now
     self.formatter.string_now = self.now.strftime('%Y%m%dT%H%M%S+0000')
     with self.app.app_context():
         init_app(self.app)
         self.app.data.insert('vocabularies', self.vocab)
 def setUp(self):
     init_app(self.app)
     self.maxDiff = None
     contact = [{
         '_id':
         '5ab491271d41c88e98ad9336',
         'contact_email': ['*****@*****.**'],
         '_updated':
         '2018-03-23T05:31:19.000Z',
         'postcode':
         '2040',
         'is_active':
         True,
         'locality':
         'Rhodes',
         'website':
         'fubar.com',
         'public':
         True,
         'contact_state':
         'NSW',
         'last_name':
         'Doe',
         'notes':
         'Exceptionally good looking',
         'mobile': [{
             'public': False,
             'number': '999',
             'usage': 'Private Mobile'
         }, {
             'public': True,
             'number': '666',
             'usage': 'Office Mobile'
         }],
         'organisation':
         'FUBAR',
         'first_name':
         'John',
         'country':
         'Australia',
         'city':
         'Sydney',
         'job_title':
         'Media Contact',
         'honorific':
         'Mr',
         'contact_phone': [{
             'usage': 'Business',
             'public': True,
             'number': '99999999'
         }],
         '_created':
         '2018-03-23T05:31:19.000Z'
     }]
     self.app.data.insert('contacts', contact)
Example #12
0
    def setUp(self):
        self.subscribers[0]["destinations"][0]["config"][
            "connection_string"] = superdesk.app.config[
                "ODBC_TEST_CONNECTION_STRING"]
        self.app.data.insert("subscribers", self.subscribers)

        self.queue_items[0]["destination"]["config"][
            "connection_string"] = superdesk.app.config[
                "ODBC_TEST_CONNECTION_STRING"]
        self.app.data.insert("publish_queue", self.queue_items)
        init_app(self.app)
    def setUp(self):
        init_app(self.app)
        self.app.data.insert('users', self.users)
        self.app.data.insert('archive', self.archive)
        self.app.data.insert('roles', self.roles)
        self.app.data.insert('vocabularies', self.vocabularies)

        self.article['state'] = 'published'
        self.formatter = BelgaNewsML12Formatter()
        seq, doc = self.formatter.format(self.article, self.subscriber)[0]
        self.newsml = etree.XML(bytes(bytearray(doc, encoding=BelgaNewsML12Formatter.ENCODING)))
Example #14
0
    def setUp(self):
        self.init_data()

        self.app.data.insert('users', self.users)
        self.app.data.insert('desks', self.desks)
        self.app.data.insert('products', self.products)
        self.app.data.insert('subscribers', self.subscribers)
        self.app.data.insert(ARCHIVE, self.articles)

        self.article_versions = self._init_article_versions()

        with tempfile.TemporaryDirectory() as tmp:
            json_data = [
                {
                    "_id": "kill_text",
                    "act": "kill",
                    "type": "text",
                    "schema": {
                        "headline": {
                            "type": "string"
                        }
                    }
                },
                {
                    "_id": "publish_text",
                    "act": "publish",
                    "type": "text",
                    "schema": {}
                },
                {
                    "_id": "correct_text",
                    "act": "correct",
                    "type": "text",
                    "schema": {}
                },
                {
                    "_id": "publish_composite",
                    "act": "publish",
                    "type": "composite",
                    "schema": {}
                },
            ]

            filename = os.path.join(tmp, 'validators.json')
            with open(filename, 'w') as file:
                json.dump(json_data, file)

            init_app(self.app)
            AppPopulateCommand().run(filename)

        self.app.media.url_for_media = MagicMock(return_value='url_for_media')
        self._put = self.app.media.put
        self.app.media.put = MagicMock(return_value='media_id')
 def setUp(self):
     self.article['state'] = 'published'
     self._setup_dates([self.article, self.video, self.picture,
                        self.package, self.picture_package,
                        self.preformatted, self.picture_text_package,
                        self.picture_text_package_multi_group])
     self.newsml = etree.Element("NewsML")
     self.formatter = NewsML12Formatter()
     self.formatter.now = self.now
     self.formatter.string_now = self.now.strftime('%Y%m%dT%H%M%S+0000')
     with self.app.app_context():
         init_app(self.app)
         self.app.data.insert('vocabularies', self.vocab)
Example #16
0
 def setUp(self):
     super().setUp()
     self.formatter = NTBNITFFormatter()
     self.base_formatter = Formatter()
     init_app(self.app)
     self.tz = pytz.timezone(self.app.config['DEFAULT_TIMEZONE'])
     if self.article is None:
         # formatting is done once for all tests to save time
         # as long as used attributes are not modified, it's fine
         self.article = ARTICLE
         self.formatter_output = self.formatter.format(self.article, {'name': 'Test NTBNITF'})
         self.doc = self.formatter_output[0]['encoded_item']
         self.nitf_xml = etree.fromstring(self.doc)
 def setUp(self):
     self.article['state'] = 'published'
     self._setup_dates([
         self.article, self.video, self.picture, self.package,
         self.picture_package, self.preformatted, self.picture_text_package,
         self.picture_text_package_multi_group
     ])
     self.newsml = etree.Element("NewsML")
     self.formatter = NewsML12Formatter()
     self.formatter.now = self.now
     self.formatter.string_now = self.now.strftime('%Y%m%dT%H%M%S+0000')
     with self.app.app_context():
         init_app(self.app)
         self.app.data.insert('vocabularies', self.vocab)
Example #18
0
    def setUp(self):
        super().setUp()
        self.init_data()

        self.app.data.insert('subscribers', self.subscribers)
        self.app.data.insert(ARCHIVE, self.articles)

        self.filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), "validators.json")
        self.json_data = [
            {"_id": "kill_text", "act": "kill", "type": "text", "schema": {"headline": {"type": "string"}}},
            {"_id": "publish_text", "act": "publish", "type": "text", "schema": {}},
            {"_id": "correct_text", "act": "correct", "type": "text", "schema": {}},
            {"_id": "publish_composite", "act": "publish", "type": "composite", "schema": {}},
        ]
        self.article_versions = self._init_article_versions()

        with open(self.filename, "w+") as file:
            json.dump(self.json_data, file)
        init_app(self.app)
        ValidatorsPopulateCommand().run(self.filename)
Example #19
0
 def setUp(self):
     super().setUp()
     init_app(self.app)
Example #20
0
 def setUp(self):
     super().setUp()
     init_app(self.app)
 def setUp(self):
     self.formatter = NewsroomNinjsFormatter()
     init_app(self.app)
     self.maxDiff = None
 def setUp(self):
     super().setUp()
     self.formatter = NITFFormatter()
     self.base_formatter = Formatter()
     init_app(self.app)
 def setUp(self):
     super().setUp()
     self.formatter = NINJSFormatter()
     init_app(self.app)
     self.maxDiff = None
Example #24
0
 def setUp(self):
     init_app(self.app)
     self._media = self.app.media
     self.app.media = MockMediaFS()
     self._mail = self.app.mail
     self.app.mail = MockMail()
 def setUp(self):
     self.formatter = NINJSFormatter()
     init_app(self.app)
     self.maxDiff = None
Example #26
0
 def setUp(self):
     init_app(self.app)
 def setUp(self):
     self.formatter = IRESSNITFFormatter()
     self.base_formatter = Formatter()
     init_app(self.app)
     self.setUpData()
 def setUp(self):
     self.formatter = NewsroomNinjsFormatter()
     init_app(self.app)
     self.maxDiff = None
 def setUp(self):
     self.formatter = EmailFormatter()
     # self.base_formatter = Formatter()
     init_app(self.app)
Example #30
0
 def setUp(self):
     self.formatter = AAPNITFFormatter()
     self.base_formatter = Formatter()
     init_app(self.app)
Example #31
0
 def setUp(self):
     with self.app.app_context():
         init_app(self.app)
 def setUp(self):
     self.formatter = IRESSNITFFormatter()
     self.base_formatter = Formatter()
     init_app(self.app)
     self.setUpData()
 def setUp(self):
     super().setUp()
     self.formatter = NITFFormatter()
     self.base_formatter = Formatter()
     init_app(self.app)
Example #34
0
 def setUp(self):
     with self.app.app_context():
         init_app(self.app)