Exemple #1
0
    def test_publish_non_ninjs_item_assoc(self, ftp_connect_mock, *args):
        service = FTPPublishService()
        queue_item = {
            'item_id': 'someid',
            'item_version': 3,
            'formatted_item': '<?xml ...>',  # something json won't handle
            'destination': {
                'config': {
                    'push_associated': True
                }
            },
        }

        ftp_mock = create_autospec(ftplib.FTP)()
        context_mock = mock.Mock()
        context_mock.__enter__ = mock.Mock(return_value=ftp_mock)
        context_mock.__exit__ = mock.Mock(return_value=None)
        ftp_connect_mock.return_value = context_mock

        self.app.data.insert('published', [{
            'item_id': 'someid',
            '_current_version': 3,
            'associations': ASSOCIATIONS,
        }])

        subscriber = {}
        service._transmit(queue_item, subscriber)

        ftp_mock.storbinary.assert_any_call(
            'STOR 5e448e47016d1f63a92f03b8.jpg', b'binary')
        ftp_mock.storbinary.assert_any_call(
            'STOR 5e448dd1016d1f63a92f0393.png', b'binary')
Exemple #2
0
    def test_publish_non_ninjs_item_assoc(self, ftp_connect_mock, *args):
        service = FTPPublishService()
        queue_item = {
            "item_id": "someid",
            "item_version": 3,
            "formatted_item": "<?xml ...>",  # something json won't handle
            "destination": {
                "config": {
                    "push_associated": True
                }
            },
        }

        ftp_mock = create_autospec(ftplib.FTP)()
        context_mock = mock.Mock()
        context_mock.__enter__ = mock.Mock(return_value=ftp_mock)
        context_mock.__exit__ = mock.Mock(return_value=None)
        ftp_connect_mock.return_value = context_mock

        self.app.data.insert(
            "published",
            [{
                "item_id": "someid",
                "_current_version": 3,
                "associations": ASSOCIATIONS,
            }],
        )

        subscriber = {}
        service._transmit(queue_item, subscriber)

        ftp_mock.storbinary.assert_any_call(
            "STOR 5e448e47016d1f63a92f03b8.jpg", b"binary")
        ftp_mock.storbinary.assert_any_call(
            "STOR 5e448dd1016d1f63a92f0393.png", b"binary")
Exemple #3
0
    def test_it_can_connect(self):
        service = FTPPublishService()

        if 'FTP_URL' not in os.environ:
            return

        config = service.config_from_url(os.environ['FTP_URL'])
        self.item['destination'] = {'config': config}

        self.assertEqual('test', config['path'])
        self.assertEqual('localhost', config['host'])

        service._transmit(self.item, subscriber={'config': config})
        self.assertTrue(self.is_item_loaded(config, 'abc.ntf'))
Exemple #4
0
    def test_it_can_connect(self):
        service = FTPPublishService()

        if "FTP_URL" not in os.environ:
            return

        config = service.config_from_url(os.environ["FTP_URL"])
        self.item["destination"] = {"config": config}

        self.assertEqual("test", config["path"])
        self.assertEqual("localhost", config["host"])

        service._transmit(self.item, subscriber={"config": config})
        self.assertTrue(self.is_item_loaded(config, "abc.ntf"))
Exemple #5
0
    def test_it_can_connect(self):
        service = FTPPublishService()

        if 'FTP_URL' not in os.environ:
            return

        config = service.config_from_url(os.environ['FTP_URL'])
        self.item['destination'] = {'config': config}

        self.assertEqual('test', config['path'])
        self.assertEqual('localhost', config['host'])

        service._transmit(self.item, destination={'config': config})
        self.assertTrue(self.is_item_loaded(config, 'abc.ntf'))
Exemple #6
0
    def test_with_associations(self, mock_ftp_constructor, *args):
        item = {
            'associations': {
                'featuremedia': ASSOCIATIONS['featuremedia'],
            }
        }

        service = FTPPublishService()

        service._copy_published_media_files(item, mock_ftp_constructor)

        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448e47016d1f63a92f03b8.jpg', b'binary')
        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448ee8016d1f63a92f0408.jpg', b'binary')
        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448ee9016d1f63a92f040b.jpg', b'binary')
Exemple #7
0
    def test_with_associations(self, mock_ftp_constructor, *args):
        item = {
            "associations": {
                "featuremedia": ASSOCIATIONS["featuremedia"],
            }
        }

        service = FTPPublishService()

        service._copy_published_media_files(item, mock_ftp_constructor)

        mock_ftp_constructor.storbinary.assert_any_call(
            "STOR 5e448e47016d1f63a92f03b8.jpg", b"binary")
        mock_ftp_constructor.storbinary.assert_any_call(
            "STOR 5e448ee8016d1f63a92f0408.jpg", b"binary")
        mock_ftp_constructor.storbinary.assert_any_call(
            "STOR 5e448ee9016d1f63a92f040b.jpg", b"binary")
Exemple #8
0
    def test_with_association_and_embed(self, mock_ftp_constructor, *args):
        item = {'associations': ASSOCIATIONS}

        service = FTPPublishService()
        service._copy_published_media_files(item, mock_ftp_constructor)

        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448e47016d1f63a92f03b8.jpg', b'binary')
        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448ee8016d1f63a92f0408.jpg', b'binary')
        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448ee9016d1f63a92f040b.jpg', b'binary')
        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448dd1016d1f63a92f0393.png', b'binary')
        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448dd1016d1f63a92f0398.png', b'binary')
        mock_ftp_constructor.storbinary.assert_any_call(
            'STOR 5e448dd1016d1f63a92f039e.png', b'binary')
Exemple #9
0
    def is_item_loaded(self, url, uploaded_filename):
        config = FTPPublishService().config_from_url(url)
        with ftplib.FTP(config.get('host')) as ftp:
            ftp.login(config.get('username'), config.get('password'))
            ftp.cwd(config.get('path', ''))
            ftp.set_pasv(config.get('passive', False))

            for filename, facts in ftp.mlsd():
                if filename == uploaded_filename:
                    return True
            return False
Exemple #10
0
    def is_item_loaded(self, url, uploaded_filename):
        config = FTPPublishService().config_from_url(url)
        with ftplib.FTP(config.get('host')) as ftp:
            ftp.login(config.get('username'), config.get('password'))
            ftp.cwd(config.get('path', ''))
            ftp.set_pasv(config.get('passive', False))

            for filename, facts in ftp.mlsd():
                if filename == uploaded_filename:
                    return True
            return False