コード例 #1
0
ファイル: test_nightly.py プロジェクト: jvivaldi/META-SHARE
    def deactivated_testSingleResourceViewAll(self):
        """
        Checks that each resource's single view is displayed correctly.
        """
        
        # disable indexing; we don't need stat updates for this test
        test_utils.set_index_active(False)
        
        count = 0
        error_atts = []
        for _res in resourceInfoType_model.objects.all():
            parent_dict = {}
            _res.export_to_elementtree(pretty=True, parent_dict=parent_dict)       

            count += 1
            LOGGER.info("calling {}. resource at {}".format(
              count, _res.get_absolute_url()))
            # always create a new client to force a new session
            client = Client()
            response = client.get(_res.get_absolute_url(), follow = True)
            self.assertEquals(200, response.status_code)
            self.assertTemplateUsed(response, 'repository/lr_view.html')
            for _ele in parent_dict:
                if not _ele.text:
                    continue
                text = smart_str(xml_utils.html_escape(_ele.text), response._charset)
                real_count = response.content.count(text)
                if real_count == 0:
                    path = self.path_to_root(_ele, parent_dict)
                    if "email" in path \
                      or "metaShareId" in path:
                        continue
                    LOGGER.error(u"missing {}: {}".format(path, _ele.text))
                    error_atts.append(path)
                # TODO activate when single resource view is complete
                #self.assertContains(response, xml_utils.html_escape(_ele.text))

        if LOGGER.isEnabledFor(logging.WARN):
            LOGGER.warn("missing paths:")
            for path in sorted(set(error_atts)):
                LOGGER.warn(path)
        # enable indexing 
        test_utils.set_index_active(True)
コード例 #2
0
ファイル: test_nightly.py プロジェクト: Atala/META-SHARE
    def testSingleResourceView(self):
        """
        Checks that each resource's single view is displayed correctly.
        """
        
        # disable indexing; we don't need stat updates for this test
        test_utils.set_index_active(False)
        
        count = 0
        for _res in resourceInfoType_model.objects.all():
            count += 1
            LOGGER.info("calling {}. resource at {}".format(count, _res.get_absolute_url()))
            # always create a new client to force a new session
            client = Client()
            response = client.get(_res.get_absolute_url(), follow = True)
            self.assertEquals(200, response.status_code)
            self.assertTemplateUsed(response, 'repository/resource_view/lr_view.html')
            self.assertContains(response, xml_utils.html_escape(_res.real_unicode_()))

        # enable indexing 
        test_utils.set_index_active(True)
コード例 #3
0
ファイル: test_nightly.py プロジェクト: MiltosD/ELRC2
    def test_single_resource_view(self):
        """
        Checks that each resource's single view is displayed correctly.
        """
        
        # disable indexing; we don't need stat updates for this test
        test_utils.set_index_active(False)
        
        count = 0
        for _res in resourceInfoType_model.objects.all():
            count += 1
            LOGGER.info("calling {}. resource at {}".format(count, _res.get_absolute_url()))
            # always create a new client to force a new session
            client = Client()
            response = client.get(_res.get_absolute_url(), follow = True)
            self.assertEquals(200, response.status_code)
            self.assertTemplateUsed(response, 'repository/resource_view/lr_view.html')
            self.assertContains(response, xml_utils.html_escape(_res.real_unicode_()))

        # enable indexing 
        test_utils.set_index_active(True)
コード例 #4
0
ファイル: test_view.py プロジェクト: JuliBakagianni/CEF-ELRC
def check_resource_view(queryset, test_case):
    
    # paths elemenets for which the path is skipped
    skip_path_elements = (
      'email',
      'metaShareId',
      'downloadLocation',
      'executionLocation',
    )

    # path suffixes where to apply a URL transformation on the value
    url_paths = (
        '/url',
        '/downloadLocation',
        '/executionLocation',
        '/samplesLocation',
        '/targetResourceNameURI',
        '/documentation',
    )

    # path suffixes where to apply a number transformation on the value
    number_paths = (
      '/size',
      '/fee',
    )

    # path suffixes where to apply data transformation on the value
    date_paths = (
      '/metadataCreationDate',
      '/annotationStartDate',
      '/annotationEndDate',
      '/availabilityStartDate',
      '/availabilityEndDate',
      '/creationStartDate',
      '/creationEndDate',
      '/projectStartDate',
      '/projectEndDate',
      '/lastDateUpdated',
      '/metadataLastDateUpdated',
    )

    count = 0
    for _res in queryset:
        parent_dict = {}
        _res.export_to_elementtree(pretty=True, parent_dict=parent_dict)       

        count += 1
        LOGGER.info("calling {}. resource at {}".format(
          count, _res.get_absolute_url()))
        # always create a new client to force a new session
        client = Client()
        response = client.get(_res.get_absolute_url(), follow = True)
        test_case.assertEquals(200, response.status_code)
        test_case.assertTemplateUsed(response, 'repository/resource_view/lr_view.html')
        
        for _ele in parent_dict:
        
            if not _ele.text:
                continue
        
            path = path_to_root(_ele, parent_dict)
            text = smart_str(xml_utils.html_escape(_ele.text.strip()),
                response._charset)

            # skip boolean values, as they cannot reasonably be verified
            if text.lower() in ("true", "false"):
                continue

            # check if path should be skipped
            skip = False
            for path_ele in skip_path_elements:
                if path_ele in path:
                    skip = True
                    break
            if skip:
                continue    

            # apply number transformation if required
            for _np in number_paths:        
                if path.endswith(_np):
                    text = unicode(humanize.intcomma(text)).encode("utf-8")
                    if text == '0':
                        skip = True
                    break
            if skip:
                continue

            # apply URL transformation if required
            for _up in url_paths:
                if path.endswith(_up) and not path.endswith('identificationInfo/url'):
                    text = unicode(urlizetrunc(text, 23)).encode("utf-8")

            # apply date transformation if required
            for _dp in date_paths:
                if path.endswith(_dp):
                    date_object = datetime.strptime(text, '%Y-%m-%d')
                    text = unicode(
                      date_format(date_object, format='SHORT_DATE_FORMAT', use_l10n=True)).encode("utf-8")

            real_count = response.content.count(text)
            if real_count == 0:
                # try with beautified string
                beauty_real_count = response.content.count(
                  prettify_camel_case_string(text))
            if real_count == 0 and beauty_real_count == 0:
                test_case.fail(u"missing {}: {}".format(path, _ele.text))
コード例 #5
0
ファイル: test_view.py プロジェクト: hpusset/ELRI
        count += 1
        LOGGER.info("calling {}. resource at {}".format(
          count, _res.get_absolute_url()))
        # always create a new client to force a new session
        client = Client()
        response = client.get(_res.get_absolute_url(), follow = True)
        test_case.assertEquals(200, response.status_code)
        test_case.assertTemplateUsed(response, 'repository/resource_view/lr_view.html')
        
        for _ele in parent_dict:
        
            if not _ele.text:
                continue
        
            path = path_to_root(_ele, parent_dict)
            text = smart_str(xml_utils.html_escape(_ele.text.strip()),
                response._charset)

            # skip boolean values, as they cannot reasonably be verified
            if text.lower() in ("true", "false"):
                continue

            # check if path should be skipped
            skip = False
            for path_ele in skip_path_elements:
                if path_ele in path:
                    skip = True
                    break
            if skip:
                continue    
コード例 #6
0
def check_resource_view(queryset, test_case):

    # paths elemenets for which the path is skipped
    skip_path_elements = (
        'email',
        'metaShareId',
        'downloadLocation',
        'executionLocation',
    )

    # path suffixes where to apply a URL transformation on the value
    url_paths = (
        '/url',
        '/downloadLocation',
        '/executionLocation',
        '/samplesLocation',
        '/targetResourceNameURI',
        '/documentation',
    )

    # path suffixes where to apply a number transformation on the value
    number_paths = (
        '/size',
        '/fee',
    )

    # path suffixes where to apply data transformation on the value
    date_paths = (
        '/metadataCreationDate',
        '/annotationStartDate',
        '/annotationEndDate',
        '/availabilityStartDate',
        '/availabilityEndDate',
        '/creationStartDate',
        '/creationEndDate',
        '/projectStartDate',
        '/projectEndDate',
        '/lastDateUpdated',
        '/metadataLastDateUpdated',
    )

    count = 0
    for _res in queryset:
        parent_dict = {}
        _res.export_to_elementtree(pretty=True, parent_dict=parent_dict)

        count += 1
        LOGGER.info("calling {}. resource at {}".format(
            count, _res.get_absolute_url()))
        # always create a new client to force a new session
        client = Client()
        response = client.get(_res.get_absolute_url(), follow=True)
        test_case.assertEquals(200, response.status_code)
        test_case.assertTemplateUsed(response,
                                     'repository/resource_view/lr_view.html')

        for _ele in parent_dict:

            if not _ele.text:
                continue

            path = path_to_root(_ele, parent_dict)
            text = smart_str(xml_utils.html_escape(_ele.text.strip()),
                             response._charset)

            # skip boolean values, as they cannot reasonably be verified
            if text.lower() in ("true", "false"):
                continue

            # check if path should be skipped
            skip = False
            for path_ele in skip_path_elements:
                if path_ele in path:
                    skip = True
                    break
            if skip:
                continue

            # apply number transformation if required
            for _np in number_paths:
                if path.endswith(_np):
                    text = unicode(humanize.intcomma(text)).encode("utf-8")
                    if text == '0':
                        skip = True
                    break
            if skip:
                continue

            # apply URL transformation if required
            for _up in url_paths:
                if path.endswith(
                        _up) and not path.endswith('identificationInfo/url'):
                    text = unicode(urlizetrunc(text, 23)).encode("utf-8")

            # apply date transformation if required
            for _dp in date_paths:
                if path.endswith(_dp):
                    date_object = datetime.strptime(text, '%Y-%m-%d')
                    text = unicode(
                        date_format(date_object,
                                    format='SHORT_DATE_FORMAT',
                                    use_l10n=True)).encode("utf-8")

            real_count = response.content.count(text)
            if real_count == 0:
                # try with beautified string
                beauty_real_count = response.content.count(
                    prettify_camel_case_string(text))
            if real_count == 0 and beauty_real_count == 0:
                test_case.fail(u"missing {}: {}".format(path, _ele.text))