Exemplo n.º 1
0
 def test_publish(self):
     doc = self.articles[3].copy()
     get_resource_service(ARCHIVE_PUBLISH).patch(id=doc['_id'], updates={ITEM_STATE: CONTENT_STATE.PUBLISHED})
     published_doc = get_resource_service(ARCHIVE).find_one(req=None, _id=doc['_id'])
     self.assertIsNotNone(published_doc)
     self.assertEqual(published_doc[config.VERSION], doc[config.VERSION] + 1)
     self.assertEqual(published_doc[ITEM_STATE], ArchivePublishService().published_state)
Exemplo n.º 2
0
    def test_publish_associations(self):
        item = {
            'associations': {
                'sidebar': {
                    'headline': 'foo',
                    'pubstatus': 'canceled',
                },
                'image': {
                    'pubstatus': 'usable',
                    'headline': 'bar',
                    'fetch_endpoint': 'paimg',
                    'renditions': {
                        'original': {
                            'href': 'https://c2.staticflickr.com/4/3665/9203816834_3329fac058_t.jpg',
                            'width': 100,
                            'height': 67,
                            'mimetype': 'image/jpeg'
                        },
                        'thumbnail': {
                            'CropLeft': 10,
                            'CropRight': 50,
                            'CropTop': 10,
                            'CropBottom': 40,
                        }
                    }
                }
            }
        }

        thumbnail_crop = {'width': 40, 'height': 30}
        with patch.object(CropService, 'get_crop_by_name', return_value=thumbnail_crop):
            ArchivePublishService()._publish_associations(item, 'baz')

        self.assertNotIn('sidebar', item['associations'])
        self.assertIn('image', item['associations'])

        image = item['associations']['image']
        renditions = image['renditions']
        print(renditions)
        self.assertEqual(40, renditions['thumbnail']['width'])
        self.assertEqual(30, renditions['thumbnail']['height'])
        self.assertEqual('image/jpeg', renditions['thumbnail']['mimetype'])
        self.assertEqual('url_for_media', renditions['thumbnail']['href'])
Exemplo n.º 3
0
    def test_added_removed_in_a_package(self):
        package = {"groups": [{"id": "root", "refs": [{"idRef": "main"}], "role": "grpRole:NEP"},
                              {"id": "main", "refs": [
                                  {
                                      "renditions": {},
                                      "slugline": "Boat",
                                      "guid": "123",
                                      "headline": "item-1 headline",
                                      "location": "archive",
                                      "type": "text",
                                      "itemClass": "icls:text",
                                      "residRef": "123"
                                  },
                                  {
                                      "renditions": {},
                                      "slugline": "Boat",
                                      "guid": "456",
                                      "headline": "item-2 headline",
                                      "location": "archive",
                                      "type": "text",
                                      "itemClass": "icls:text",
                                      "residRef": "456"
                                  },
                                  {
                                      "renditions": {},
                                      "slugline": "Boat",
                                      "guid": "789",
                                      "headline": "item-3 headline",
                                      "location": "archive",
                                      "type": "text",
                                      "itemClass": "icls:text",
                                      "residRef": "789"
                                  }], "role": "grpRole:main"}],
                   "task": {
                       "user": "******",
                       "status": "todo",
                       "stage": "#desks.incoming_stage#",
                       "desk": "#desks._id#"},
                   "guid": "compositeitem",
                   "headline": "test package",
                   "state": "submitted",
                   "type": "composite"}

        updates = {"groups": [{"id": "root", "refs": [{"idRef": "main"}], "role": "grpRole:NEP"},
                              {"id": "main", "refs": [
                                  {
                                      "renditions": {},
                                      "slugline": "Boat",
                                      "guid": "123",
                                      "headline": "item-1 headline",
                                      "location": "archive",
                                      "type": "text",
                                      "itemClass": "icls:text",
                                      "residRef": "123"
                                  },
                                  {
                                      "renditions": {},
                                      "slugline": "Boat",
                                      "guid": "555",
                                      "headline": "item-2 headline",
                                      "location": "archive",
                                      "type": "text",
                                      "itemClass": "icls:text",
                                      "residRef": "555"
                                  },
                                  {
                                      "renditions": {},
                                      "slugline": "Boat",
                                      "guid": "456",
                                      "headline": "item-2 headline",
                                      "location": "archive",
                                      "type": "text",
                                      "itemClass": "icls:text",
                                      "residRef": "456"
                                  }], "role": "grpRole:main"}],
                   "task": {
                       "user": "******",
                       "status": "todo",
                       "stage": "#desks.incoming_stage#",
                       "desk": "#desks._id#"},
                   "guid": "compositeitem",
                   "headline": "test package",
                   "state": "submitted",
                   "type": "composite"}

        items = PackageService().get_residrefs(package)
        removed_items, added_items = ArchivePublishService()._get_changed_items(items, updates)
        self.assertEqual(len(removed_items), 1)
        self.assertEqual(len(added_items), 1)