def test_get_structmap_text(self, mock_deepharvest, mock_boto):
     '''Mock test s3 structmap_text getting'''
     media_json = open(DIR_FIXTURES + '/nuxeo_media_structmap.json').read()
     deepharvest_mocker(mock_deepharvest)
     mock_boto.return_value.get_bucket.return_value.\
         get_key.return_value.\
         get_contents_as_string.return_value = media_json
     h = fetcher.NuxeoFetcher('https://example.edu/api/v1/',
                              'path-to-asset/here')
     mock_deepharvest.assert_called_with(
         'path-to-asset/here',
         '',
         conf_pynux={'api': 'https://example.edu/api/v1/'})
     structmap_text = h._get_structmap_text(
         's3://static.ucldc.cdlib.org/media_json/'
         '81249b9c-5a87-43af-877c-fb161325b1a0-media.json')
     mock_boto.assert_called_with()
     mock_boto().get_bucket.assert_called_with('static.ucldc.cdlib.org')
     mock_boto().get_bucket().get_key.assert_called_with(
         '/media_json/81249b9c-5a87-43af-877c-fb161325b1a0-media.json')
     self.assertEqual(
         structmap_text, "Angela Davis socializing with "
         "students at UC Irvine AS-061_A69-013_001.tif "
         "AS-061_A69-013_002.tif AS-061_A69-013_003.tif "
         "AS-061_A69-013_004.tif AS-061_A69-013_005.tif "
         "AS-061_A69-013_006.tif AS-061_A69-013_007.tif")
    def test_get_isShownBy_video(self, mock_deepharvest, mock_boto):
        ''' test getting correct isShownBy value for Nuxeo video object
        '''
        deepharvest_mocker(mock_deepharvest)

        httpretty.register_uri(
            httpretty.GET,
            'https://example.edu/api/v1/path/@search?query=SELECT+%2A+FROM+'
            'Document+WHERE+ecm%3AparentId+%3D+'
            '%274c80e254-6def-4230-9f28-bc48878568d4%27+'
            'AND+ecm%3AcurrentLifeCycleState+%21%3D+%27deleted%27+ORDER+BY+'
            'ecm%3Apos&currentPageIndex=0&pageSize=100',
            responses=[
                httpretty.Response(body=open(DIR_FIXTURES +
                                             '/nuxeo_no_children.json').read(),
                                   status=200),
            ])

        h = fetcher.NuxeoFetcher('https://example.edu/api/v1',
                                 'path-to-asset/here')

        nuxeo_metadata = open(DIR_FIXTURES + '/nuxeo_doc_video.json').read()
        nuxeo_metadata = json.loads(nuxeo_metadata)
        isShownBy = h._get_isShownBy(nuxeo_metadata)

        self.assertEqual(
            isShownBy, 'https://s3.amazonaws.com/static.ucldc.cdlib.org/'
            'ucldc-nuxeo-thumb-media/4c80e254-6def-4230-9f28-bc48878568d4')
    def test_get_isShownBy_pdf(self, mock_deepharvest, mock_boto):
        ''' test getting correct isShownBy value for Nuxeo doc
            with no images and PDF at parent level
        '''
        deepharvest_mocker(mock_deepharvest)

        httpretty.register_uri(
            httpretty.GET,
            'https://example.edu/api/v1/path/@search?query=SELECT+%2A+FROM+'
            'Document+WHERE+ecm%3AparentId+%3D+'
            '%2700d55837-01b6-4211-80d8-b966a15c257e%27+ORDER+BY+'
            'ecm%3Apos&currentPageIndex=0&pageSize=100',
            responses=[
                httpretty.Response(body=open(DIR_FIXTURES +
                                             '/nuxeo_no_children.json').read(),
                                   status=200),
            ])

        h = fetcher.NuxeoFetcher('https://example.edu/api/v1',
                                 'path-to-asset/here')

        nuxeo_metadata = open(DIR_FIXTURES +
                              '/nuxeo_doc_pdf_parent.json').read()
        nuxeo_metadata = json.loads(nuxeo_metadata)
        isShownBy = h._get_isShownBy(nuxeo_metadata)
        self.assertEqual(
            isShownBy, 'https://s3.amazonaws.com/static.ucldc.cdlib.org/'
            'ucldc-nuxeo-thumb-media/00d55837-01b6-4211-80d8-b966a15c257e')
    def testFetch(self, mock_deepharvest, mock_boto):
        '''Test the httpretty mocked fetching of documents'''
        media_json = open(DIR_FIXTURES + '/nuxeo_media_structmap.json').read()
        deepharvest_mocker(mock_deepharvest)
        mock_boto.return_value.get_bucket.return_value.\
            get_key.return_value.\
            get_contents_as_string.return_value = media_json
        httpretty.register_uri(
            httpretty.GET,
            'https://example.edu/api/v1/path/path-to-asset/here/@children',
            responses=[
                httpretty.Response(body=open(DIR_FIXTURES +
                                             '/nuxeo_folder.json').read(),
                                   status=200),
                httpretty.Response(body=open(DIR_FIXTURES +
                                             '/nuxeo_folder-1.json').read(),
                                   status=200),
            ])
        httpretty.register_uri(httpretty.GET,
                               re.compile('https://example.edu/api/v1/id/.*'),
                               body=open(DIR_FIXTURES +
                                         '/nuxeo_doc.json').read())

        httpretty.register_uri(
            httpretty.GET,
            'https://example.edu/api/v1/path/asset-library/UCI/Cochems'
            '/MS-R016_1092.tif/@children?currentPageIndex=0',
            responses=[
                httpretty.Response(body=open(DIR_FIXTURES +
                                             '/nuxeo_no_children.json').read(),
                                   status=200),
            ])
        h = fetcher.NuxeoFetcher('https://example.edu/api/v1',
                                 'path-to-asset/here')
        mock_deepharvest.assert_called_with(
            'path-to-asset/here',
            '',
            conf_pynux={'api': 'https://example.edu/api/v1'})
        docs = []
        for d in h:
            docs.append(d)
        self.assertEqual(3, len(docs))
        self.assertIn('picture:views', docs[0]['properties'])
        self.assertIn('dc:subjects', docs[0]['properties'])
        self.assertIn('structmap_url', docs[0])
        self.assertIn('structmap_text', docs[0])
        self.assertEqual(
            docs[0]['structmap_text'],
            "Angela Davis socializing with students at UC Irvine "
            "AS-061_A69-013_001.tif AS-061_A69-013_002.tif "
            "AS-061_A69-013_003.tif AS-061_A69-013_004.tif "
            "AS-061_A69-013_005.tif AS-061_A69-013_006.tif "
            "AS-061_A69-013_007.tif")
        self.assertEqual(
            docs[0]['isShownBy'],
            'https://nuxeo.cdlib.org/Nuxeo/nxpicsfile/default/'
            '40677ed1-f7c2-476f-886d-bf79c3fec8c4/Medium:content/')
 def testInit(self, mock_deepharvest, mock_boto):
     '''Basic tdd start'''
     httpretty.register_uri(
         httpretty.GET,
         'https://example.edu/api/v1/path/path-to-asset/here/@children',
         body=open(DIR_FIXTURES + '/nuxeo_folder.json').read())
     deepharvest_mocker(mock_deepharvest)
     h = fetcher.NuxeoFetcher('https://example.edu/api/v1/',
                              'path-to-asset/here')
     mock_deepharvest.assert_called_with(
         'path-to-asset/here',
         '',
         conf_pynux={'api': 'https://example.edu/api/v1/'})
     self.assertTrue(hasattr(h, '_url'))  # assert in called next repeatedly
     self.assertEqual(h.url, 'https://example.edu/api/v1/')
     self.assertTrue(hasattr(h, '_nx'))
     self.assertIsInstance(h._nx, pynux.utils.Nuxeo)
     self.assertTrue(hasattr(h, '_children'))
     self.assertTrue(hasattr(h, 'next'))
     self.assertTrue(hasattr(h, '_structmap_bucket'))
 def testFetch_missing_media_json(self, mock_deepharvest, mock_boto):
     '''Test the httpretty mocked fetching of documents'''
     deepharvest_mocker(mock_deepharvest)
     mock_boto.return_value.get_bucket.return_value.\
         get_key.return_value = None
     httpretty.register_uri(
         httpretty.GET,
         'https://example.edu/api/v1/path/path-to-asset/here/@children',
         responses=[
             httpretty.Response(body=open(DIR_FIXTURES +
                                          '/nuxeo_folder.json').read(),
                                status=200),
             httpretty.Response(body=open(DIR_FIXTURES +
                                          '/nuxeo_folder-1.json').read(),
                                status=200),
         ])
     httpretty.register_uri(httpretty.GET,
                            re.compile('https://example.edu/api/v1/id/.*'),
                            body=open(DIR_FIXTURES +
                                      '/nuxeo_doc.json').read())
     httpretty.register_uri(
         httpretty.GET,
         'https://example.edu/api/v1/path/asset-library/UCI/Cochems/'
         'MS-R016_1092.tif/@children?currentPageIndex=0',
         responses=[
             httpretty.Response(body=open(DIR_FIXTURES +
                                          '/nuxeo_no_children.json').read(),
                                status=200),
         ])
     h = fetcher.NuxeoFetcher('https://example.edu/api/v1',
                              'path-to-asset/here')
     mock_deepharvest.assert_called_with(
         'path-to-asset/here',
         '',
         conf_pynux={'api': 'https://example.edu/api/v1'})
     docs = []
     for d in h:
         docs.append(d)
     self.assertEqual(docs[0]['structmap_text'], '')
     self.assertEqual(docs[1]['structmap_text'], '')
     self.assertEqual(docs[2]['structmap_text'], '')
Exemple #7
0
    def test_get_isShownBy_component_image(self, mock_deepharvest, mock_boto):
        ''' test getting correct isShownBy value for Nuxeo doc
            with no image at parent level, but an image at the component level
        '''
        deepharvest_mocker(mock_deepharvest)

        httpretty.register_uri(
            httpretty.GET,
            'https://example.edu/api/v1/path/@search?query='
            'SELECT+%2A+FROM+Document+WHERE+ecm%3AparentId+%3D+'
            '%27d400bb29-98d4-429c-a0b8-119acdb92006%27+ORDER+BY+'
            'ecm%3Apos&currentPageIndex=0&pageSize=100',
            responses=[
                httpretty.Response(
                    body=open(DIR_FIXTURES + '/nuxeo_image_components.json')
                    .read(),
                    status=200),
            ])

        httpretty.register_uri(
            httpretty.GET,
            'https://example.edu/api/v1/id/'
            'e8af2d74-0c8b-4d18-b86c-4067b9e16159',
            responses=[
                httpretty.Response(
                    body=open(DIR_FIXTURES +
                              '/nuxeo_first_image_component.json').read(),
                    status=200),
            ])

        h = fetcher.NuxeoFetcher('https://example.edu/api/v1',
                                 'path-to-asset/here')

        nuxeo_metadata = open(DIR_FIXTURES +
                              '/nuxeo_doc_imageless_parent.json').read()
        nuxeo_metadata = json.loads(nuxeo_metadata)
        isShownBy = h._get_isShownBy(nuxeo_metadata)
        self.assertEqual(
            isShownBy, 'https://nuxeo.cdlib.org/Nuxeo/nxpicsfile/default/'
            'e8af2d74-0c8b-4d18-b86c-4067b9e16159/Medium:content/')