コード例 #1
0
ファイル: test_search.py プロジェクト: marc1s/META-SHARE
 def test_index_updates_on_import(self):
     """
     Verifies that the index is correctly updated when importing a resource.
     """
     self.assert_index_is_empty()
     # import a single resource and save it in the DB
     resource = test_utils.import_xml(SearchIndexUpdateTests.RES_PATH_1)[0]
     resource.storage_object.publication_status = INGESTED
     resource.storage_object.save()
     # make sure the import has automatically changed the search index
     self.assertEqual(
         SearchQuerySet().count(),
         1,
         "After the import of a resource the index must automatically " "have changed and contain that resource.",
     )
     # import another resource and save it in the DB
     resource = test_utils.import_xml(SearchIndexUpdateTests.RES_PATH_2)[0]
     resource.storage_object.publication_status = INGESTED
     resource.storage_object.save()
     # make sure the import has automatically changed the search index
     self.assertEqual(
         SearchQuerySet().count(),
         2,
         "After the import of a resource the index must automatically " "have changed and contain that resource.",
     )
コード例 #2
0
ファイル: test_model.py プロジェクト: JuliBakagianni/CEF-ELRC
 def setUp(self):
     """
     Imports a few test resources.
     """
     test_utils.setup_test_storage()
     self.test_res_1 = test_utils.import_xml("{0}/repository/fixtures/testfixture.xml".format(ROOT_PATH))
     self.test_res_2 = test_utils.import_xml("{0}/repository/fixtures/ILSP10.xml".format(ROOT_PATH))
コード例 #3
0
    def setUpClass(cls):
        """
        Import a resource to test the workflow changes for
        """
        LOGGER.info("running '{}' tests...".format(cls.__name__))
        test_utils.set_index_active(False)
        test_utils.setup_test_storage()
        _test_editor_group = \
            EditorGroup.objects.create(name='test_editor_group')
        _test_manager_group = \
            EditorGroupManagers.objects.create(name='test_manager_group',
                                               managed_group=_test_editor_group)
        owner = test_utils.create_manager_user(
            'manageruser', '*****@*****.**', 'secret',
            (_test_editor_group, _test_manager_group))

        # load first resource
        _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
        _result = test_utils.import_xml(_fixture)
        _result.editor_groups.add(_test_editor_group)
        _result.owners.add(owner)
        # load second resource
        _fixture = '{0}/repository/test_fixtures/ingested-corpus-AudioVideo-French.xml'.format(
            ROOT_PATH)
        _result = test_utils.import_xml(_fixture)
        _result.editor_groups.add(_test_editor_group)
        _result.owners.add(owner)

        # create a normal user
        test_utils.create_user('user', '*****@*****.**', 'mypasswd')
コード例 #4
0
ファイル: tests.py プロジェクト: MiltosD/ELRC2
    def setUp(self):
        """
        Import a resource to test the workflow changes for
        """
        test_utils.set_index_active(False)
        test_utils.setup_test_storage()
        # create Groups
        trgroup = Group.objects.create(name="technicalReviewers")
        ecgroup = Group.objects.create(name='ecmembers')

        owner = User.objects.create_user('ecuser', '*****@*****.**',
                                         'secret')
        owner.groups.add(ecgroup)
        owner.is_staff = True
        owner.save()

        # create a superuser
        su = User.objects.create_user('su', '*****@*****.**', 'supwd')
        su.is_superuser = True
        su.is_staff = True
        su.save()

        # load first resource
        _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
        _result = test_utils.import_xml(_fixture)
        _result.owners.add(su)
        # load second resource
        _fixture = '{0}/repository/test_fixtures/ingested-corpus-text-French.xml'.format(
            ROOT_PATH)
        _result = test_utils.import_xml(_fixture)
        _result.owners.add(su)
コード例 #5
0
ファイル: tests.py プロジェクト: Atala/META-SHARE
 def setUpClass(cls):
     """
     Import a resource to test the workflow changes for
     """
     LOGGER.info("running '{}' tests...".format(cls.__name__))
     test_utils.set_index_active(False)        
     test_utils.setup_test_storage()
     _test_editor_group = \
         EditorGroup.objects.create(name='test_editor_group')
     _test_manager_group = \
         EditorGroupManagers.objects.create(name='test_manager_group',
                                            managed_group=_test_editor_group)            
     owner = test_utils.create_manager_user(
         'manageruser', '*****@*****.**', 'secret',
         (_test_editor_group, _test_manager_group))       
     
     # load first resource
     _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
     _result = test_utils.import_xml(_fixture)
     _result.editor_groups.add(_test_editor_group)
     _result.owners.add(owner)
     # load second resource
     _fixture = '{0}/repository/test_fixtures/ingested-corpus-AudioVideo-French.xml'.format(ROOT_PATH)
     _result = test_utils.import_xml(_fixture)
     _result.editor_groups.add(_test_editor_group)
     _result.owners.add(owner)
     
     # create a normal user
     test_utils.create_user('user', '*****@*****.**', 'mypasswd')
コード例 #6
0
 def setUp(self):
     """
     Imports a few test resources.
     """
     self.test_res_1 = test_utils.import_xml(
         '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH))[0]
     self.test_res_2 = test_utils.import_xml(
         '{0}/repository/fixtures/ILSP10.xml'.format(ROOT_PATH))[0]
コード例 #7
0
 def setUp(self):
     """
     Imports a few test resources.
     """
     test_utils.setup_test_storage()
     self.test_res_1 = test_utils.import_xml(
         '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH))
     self.test_res_2 = test_utils.import_xml(
         '{0}/repository/fixtures/ILSP10.xml'.format(ROOT_PATH))
コード例 #8
0
 def setUp(self):
     
     test_utils.setup_test_storage()
     _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
     _result = test_utils.import_xml(_fixture)
     self.resource_id = _result[0].id
     resource = resourceInfoType_model.objects.get(pk=self.resource_id)
     resource.storage_object.published = True
     resource.storage_object.save()
     # set up test users with and without staff permissions.
     # These will live in the test database only, so will not
     # pollute the "normal" development db or the production db.
     # As a consequence, they need no valuable password.
     staffuser = User.objects.create_user('staffuser', '*****@*****.**',
       'secret')
     staffuser.is_staff = True
     staffuser.save()
     User.objects.create_user('normaluser', '*****@*****.**', 'secret')
     
     # init Selenium
     driver = getattr(webdriver, settings.SELENIUM_DRIVER, None)
     assert driver, "settings.SELENIUM_DRIVER contains non-existing driver"
     self.driver = driver()
     self.driver.implicitly_wait(30)
     host = getattr(settings, 'SELENIUM_TESTSERVER_HOST', 'localhost')
     port = getattr(settings, 'SELENIUM_TESTSERVER_PORT', 8011)
     self.base_url = 'http://{0}:{1}/{2}'.format(host, port, DJANGO_BASE)
     self.verification_errors = []
コード例 #9
0
ファイル: test_search.py プロジェクト: marc1s/META-SHARE
 def test_case_insensitive_search(self):
     """
     Asserts that case-insensitive searching is done.
     """
     imported_res = test_utils.import_xml(
         "{}/repository/test_fixtures/" "internal-corpus-Text-EngPers.xml".format(ROOT_PATH)
     )[0]
     imported_res.storage_object.published = True
     imported_res.storage_object.save()
     client = Client()
     # assert that a lower case search for an upper case term succeeds:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "fixture"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that an upper case search for a lower case term succeeds:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "ORIGINALLY"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a lower case search for a mixed case term succeeds:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "unicode"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a mixed case search for an upper case term succeeds:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "FiXTuRe"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a camelCase search for an upper case term succeeds:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "fixTure"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that an all lower case search finds a camelCase term:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "speechsynthesis"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
コード例 #10
0
 def testRollbackOnImportError(self):
     """
     Checks that a complete rollback is performed on import error.
     """
     _database = {}
     _models = [x for x in dir(sys.modules['metashare.repository.models'])
       if x.endswith('_model')]
     
     for _model in _models:
         if hasattr(sys.modules['metashare.repository.models'], _model):
             _inst = getattr(sys.modules['metashare.repository.models'], _model)
             _database[_model] = _inst.objects.count()
     
     _broken_fixture = '{0}/repository/fixtures/broken.xml'.format(ROOT_PATH)
     result = test_utils.import_xml(_broken_fixture)
     
     self.assertEqual(result[:2], (None, []))
     
     errors = []
     for _model in _models:
         if hasattr(sys.modules['metashare.repository.models'], _model):
             _inst = getattr(sys.modules['metashare.repository.models'], _model)
             print "Testing rollback for {}...".format(_model)
             if _database[_model] != _inst.objects.count():
                 errors.append(_model)
     
     self.assertEqual(errors, [])
コード例 #11
0
 def test_download_count_visible_and_updated_in_search_results(self):
     """
     Verifies that the download count of a resource is visible and updated in
     the search results list.
     """
     test_res = test_utils.import_xml('{}/repository/fixtures/'
             'downloadable_1_license.xml'.format(ROOT_PATH))
     test_res.storage_object.published = True
     test_res.storage_object.save()
     client = Client()
     client.login(username='******', password='******')
     # to be on the safe side, clear any existing stats
     LRStats.objects.all().delete()
     # assert that the download/view counts are both zero at first:
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 0')
     # view the resource, download it, go back to the browse page and then
     # assert that both view and download counts have changed:
     client.get(test_res.get_absolute_url())
     client.post(
         reverse(views.download, args=(test_res.storage_object.identifier,)),
         { 'in_licence_agree_form': 'True', 'licence_agree': 'True',
           'licence': 'CC-BY-NC-SA' })
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 1')
     self.assertContains(response, 'title="Number of views" /> 1')
コード例 #12
0
 def test_cannot_change_publication_status_of_remote_copies(self):
     # not even a superuser must change the publication status of a remote
     # resource copy
     superuser = User.objects.create_superuser(
         "superuser", "*****@*****.**", "secret")
     client = Client()
     client.login(username=superuser.username, password='******')
     # import a temporary resource to not mess with the other tests and set
     # the copy status to remote
     resource = test_utils.import_xml(
         '{0}/repository/fixtures/ILSP10.xml'.format(ROOT_PATH))
     resource.storage_object.copy_status = REMOTE
     # (1) verify that a status change from published is not possible:
     resource.storage_object.publication_status = PUBLISHED
     resource.storage_object.save()
     client.post(ADMINROOT,
         {"action": "unpublish_action", ACTION_CHECKBOX_NAME: resource.id},
         follow=True)
     # fetch the resource from DB as our object is not up-to-date anymore
     resource = resourceInfoType_model.objects.get(pk=resource.id)
     self.assertEquals('published', resource.publication_status())
     # (2) verify that a status change from ingested is not possible:
     resource.storage_object.publication_status = INGESTED
     resource.storage_object.save()
     client.post(ADMINROOT,
         {"action": "publish_action", ACTION_CHECKBOX_NAME: resource.id},
         follow=True)
     # fetch the resource from DB as our object is not up-to-date anymore
     resource = resourceInfoType_model.objects.get(pk=resource.id)
     self.assertEquals('ingested', resource.publication_status())
コード例 #13
0
 def test_download_count_visible_and_updated_in_search_results(self):
     """
     Verifies that the download count of a resource is visible and updated in
     the search results list.
     """
     test_res = test_utils.import_xml('{}/repository/fixtures/'
             'downloadable_1_license.xml'.format(ROOT_PATH))
     test_res.storage_object.published = True
     test_res.storage_object.save()
     client = Client()
     client.login(username='******', password='******')
     # to be on the safe side, clear any existing stats
     LRStats.objects.all().delete()
     # assert that the download/view counts are both zero at first:
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 0')
     # view the resource, download it, go back to the browse page and then
     # assert that both view and download counts have changed:
     client.get(test_res.get_absolute_url())
     client.post(
         reverse(views.download, args=(test_res.storage_object.identifier,)),
         { 'in_licence_agree_form': 'True', 'licence_agree': 'True',
           'licence': 'CC-BY-NC-SA' })
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 1')
     self.assertContains(response, 'title="Number of views" /> 1')
コード例 #14
0
ファイル: test_status_workflow.py プロジェクト: MiltosD/ELRC2
 def test_cannot_change_publication_status_of_remote_copies(self):
     # not even a superuser must change the publication status of a remote
     # resource copy
     superuser = User.objects.create_superuser("superuser",
                                               "*****@*****.**", "secret")
     client = Client()
     client.login(username=superuser.username, password='******')
     # import a temporary resource to not mess with the other tests and set
     # the copy status to remote
     resource = test_utils.import_xml(
         '{0}/repository/fixtures/ILSP10.xml'.format(ROOT_PATH))
     resource.storage_object.copy_status = REMOTE
     # (1) verify that a status change from published is not possible:
     resource.storage_object.publication_status = PUBLISHED
     resource.storage_object.save()
     client.post(ADMINROOT, {
         "action": "unpublish_action",
         ACTION_CHECKBOX_NAME: resource.id
     },
                 follow=True)
     # fetch the resource from DB as our object is not up-to-date anymore
     resource = resourceInfoType_model.objects.get(pk=resource.id)
     self.assertEquals('published', resource.publication_status())
     # (2) verify that a status change from ingested is not possible:
     resource.storage_object.publication_status = INGESTED
     resource.storage_object.save()
     client.post(ADMINROOT, {
         "action": "publish_action",
         ACTION_CHECKBOX_NAME: resource.id
     },
                 follow=True)
     # fetch the resource from DB as our object is not up-to-date anymore
     resource = resourceInfoType_model.objects.get(pk=resource.id)
     self.assertEquals('ingested', resource.publication_status())
コード例 #15
0
 def test_view_count_visible_and_updated_in_search_results(self):
     """
     Verifies that the view count of a resource is visible and updated in
     the search results list.
     """
     test_res = test_utils.import_xml(
         '{}/repository/test_fixtures/'
         'internal-corpus-Text-EngPers.xml'.format(ROOT_PATH))
     test_res.storage_object.published = True
     test_res.storage_object.save()
     client = Client()
     # to be on the safe side, clear any existing stats
     LRStats.objects.all().delete()
     # assert that the download/view counts are both zero at first:
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 0')
     # view the resource, then go back to the browse page and assert that the
     # view count has changed:
     client.get(test_res.get_absolute_url())
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 1')
     # log in, view the resource again, go back to the browse page and then
     # assert that the view count has changed again:
     client.login(username='******', password='******')
     client.get(test_res.get_absolute_url())
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 2')
コード例 #16
0
 def test_view_count_visible_and_updated_in_search_results(self):
     """
     Verifies that the view count of a resource is visible and updated in
     the search results list.
     """
     test_res = test_utils.import_xml('{}/repository/test_fixtures/'
                     'internal-corpus-Text-EngPers.xml'.format(ROOT_PATH))
     test_res.storage_object.published = True
     test_res.storage_object.save()
     client = Client()
     # to be on the safe side, clear any existing stats
     LRStats.objects.all().delete()
     # assert that the download/view counts are both zero at first:
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 0')
     # view the resource, then go back to the browse page and assert that the
     # view count has changed:
     client.get(test_res.get_absolute_url())
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 1')
     # log in, view the resource again, go back to the browse page and then
     # assert that the view count has changed again:
     client.login(username='******', password='******')
     client.get(test_res.get_absolute_url())
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" /> 0')
     self.assertContains(response, 'title="Number of views" /> 2')
コード例 #17
0
ファイル: tests.py プロジェクト: portulanclarin/repository
def import_test_resource(filename, publication_status, deleted=False):
    _fixture = '{0}/repository/fixtures/{1}'.format(settings.ROOT_PATH, filename)
    resource = test_utils.import_xml(_fixture)
    resource.storage_object.publication_status = publication_status
    resource.storage_object.deleted = deleted
    resource.storage_object.save()
    resource.storage_object.update_storage()
    return resource
コード例 #18
0
 def test_ingested_LRs_are_not_indexed(self):
     test_res = test_utils.import_xml('{}/repository/test_fixtures/ingested/'
         'ingested-corpus-AudioVideo-French.xml'.format(ROOT_PATH))
     test_res.storage_object.publication_status = INGESTED
     test_res.storage_object.save()
     response = Client().get(_SEARCH_PAGE_PATH, data={'q': 'INGESTED'})
     self.assertTemplateUsed(response, 'repository/search.html')
     self.assertContains(response, "No results were found for search query")
コード例 #19
0
 def setUp(self):
     """
     Set up the email test
     """
     test_utils.setup_test_storage()
     _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
     _result = test_utils.import_xml(_fixture)
     self.resource_id = _result[0].id
コード例 #20
0
ファイル: test_editor.py プロジェクト: marc1s/META-SHARE
 def import_test_resource(cls, editor_group=None, path=TESTFIXTURE_XML):
     test_utils.setup_test_storage()
     result = test_utils.import_xml(path)
     resource = result[0]
     if not editor_group is None:
         resource.editor_groups.add(editor_group)
         resource.save()
     return resource
コード例 #21
0
 def setUp(self):
     """
     Import a resource to test the workflow changes for
     """
     test_utils.setup_test_storage()
     _fixture = '{0}/repo2/fixtures/testfixture.xml'.format(ROOT_PATH)
     _result = test_utils.import_xml(_fixture)
     self.resource_id = _result[0].id
コード例 #22
0
 def test_ingested_LRs_are_not_indexed(self):
     test_res = test_utils.import_xml('{}/repository/test_fixtures/ingested/'
         'ingested-corpus-AudioVideo-French.xml'.format(ROOT_PATH))
     test_res.storage_object.publication_status = INGESTED
     test_res.storage_object.save()
     response = Client().get(_SEARCH_PAGE_PATH, data={'q': 'INGESTED'})
     self.assertTemplateUsed(response, 'repository/search.html')
     self.assertContains(response, "No results were found for search query")
コード例 #23
0
 def setUp(self):
     """
     Set up the email test
     """
     test_utils.setup_test_storage()
     _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
     _result = test_utils.import_xml(_fixture)
     self.resource_id = _result.id
コード例 #24
0
 def import_test_resource(cls, filename, status):
     test_utils.setup_test_storage()
     _fixture = '{0}/repository/fixtures/{1}'.format(settings.ROOT_PATH, filename)
     result = test_utils.import_xml(_fixture)
     resource = result[0]
     resource.storage_object.publication_status = status
     resource.storage_object.save()
     resource.storage_object.update_storage()
     return resource
コード例 #25
0
ファイル: tests.py プロジェクト: jvivaldi/META-SHARE
 def import_test_resource(cls, filename, pub_status, copy_status=MASTER, url=settings.DJANGO_URL):
     _fixture = '{0}/repository/fixtures/{1}'.format(settings.ROOT_PATH, filename)
     resource = test_utils.import_xml(_fixture)
     resource.storage_object.publication_status = pub_status
     resource.storage_object.copy_status = copy_status
     resource.storage_object.source_url = url
     resource.storage_object.save()
     resource.storage_object.update_storage()
     return resource
コード例 #26
0
ファイル: test_email.py プロジェクト: Atala/META-SHARE
 def setUp(self):
     """
     Set up the email test
     """
     test_utils.setup_test_storage()
     _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
     self.resource = test_utils.import_xml(_fixture)
     self.resource.storage_object.published = True
     self.resource.storage_object.save()
コード例 #27
0
ファイル: test_email.py プロジェクト: MiltosD/ELRC2
 def setUp(self):
     """
     Set up the email test
     """
     test_utils.setup_test_storage()
     _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
     self.resource = test_utils.import_xml(_fixture)
     self.resource.storage_object.published = True
     self.resource.storage_object.save()
コード例 #28
0
def _import_resource(fixture_name):
    """
    Imports the XML resource description with the given file name.
    
    The new resource is published and returned.
    """
    result = test_utils.import_xml('{0}/repository/fixtures/{1}'
                                    .format(ROOT_PATH, fixture_name))[0]
    result.storage_object.published = True
    result.storage_object.save()
    return result
コード例 #29
0
ファイル: test_import.py プロジェクト: kperi/META-SHARE
 def testImportELRA(self):      
     """
     run tests on ELRA resources
     """
     _path = '{0}/../misc/testdata/ELRAResources/'.format(ROOT_PATH)
     
     _files = os.listdir(_path)
     for _file in _files:
         _currfile =  "%s%s" % (_path, _file)
         _result = test_utils.import_xml(_currfile)            
         self.assertNotEqual(_result[:2], (None, []))
コード例 #30
0
ファイル: tests.py プロジェクト: MiltosD/CEFELRC
def _import_resource(res_file_name):
    """
    Imports the resource with the given file name; looks for the file in
    the folder recommendations/fixtures/; sets publication status to
    PUBLISHED; returns the resource
    """
    res = test_utils.import_xml(
      '{0}/recommendations/fixtures/{1}'.format(ROOT_PATH, res_file_name))
    res.storage_object.publication_status = PUBLISHED
    res.storage_object.save()
    res.storage_object.update_storage()
    return res
コード例 #31
0
ファイル: tests.py プロジェクト: themiszamani/META-SHARE
 def import_test_resource(cls, filename, pub_status, \
   copy_status=MASTER, url=settings.DJANGO_URL, source_node=None):
     _fixture = '{0}/repository/fixtures/{1}'.format(
         settings.ROOT_PATH, filename)
     resource = test_utils.import_xml(_fixture)
     resource.storage_object.publication_status = pub_status
     resource.storage_object.copy_status = copy_status
     resource.storage_object.source_url = url
     resource.storage_object.source_node = source_node
     resource.storage_object.save()
     resource.storage_object.update_storage()
     return resource
コード例 #32
0
 def test_index_updates_on_import(self):
     """
     Verifies that the index is correctly updated when importing a resource.
     """
     self.assert_index_is_empty()
     # import a single resource and save it in the DB
     resource = test_utils.import_xml(SearchIndexUpdateTests.RES_PATH_1)
     resource.storage_object.publication_status = PUBLISHED
     resource.storage_object.save()
     # make sure the import has automatically changed the search index
     self.assertEqual(SearchQuerySet().count(), 1,
         "After the import of a resource the index must automatically " \
         "have changed and contain that resource.")
     # import another resource and save it in the DB
     resource = test_utils.import_xml(SearchIndexUpdateTests.RES_PATH_2)
     resource.storage_object.publication_status = PUBLISHED
     resource.storage_object.save()
     # make sure the import has automatically changed the search index
     self.assertEqual(SearchQuerySet().count(), 2,
         "After the import of a resource the index must automatically " \
         "have changed and contain that resource.")
コード例 #33
0
def _import_resource(res_file_name):
    """
    Imports the resource with the given file name; looks for the file in
    the folder recommendations/fixtures/; sets publication status to
    PUBLISHED; returns the resource
    """
    res = test_utils.import_xml(
      '{0}/recommendations/fixtures/{1}'.format(ROOT_PATH, res_file_name))
    res.storage_object.publication_status = PUBLISHED
    res.storage_object.save()
    res.storage_object.update_storage()
    return res
コード例 #34
0
 def test_status_after_saving(self):
     
     # load test fixture and set its status to 'published'
     test_utils.setup_test_storage()
     _result = test_utils.import_xml(TESTFIXTURE_XML)
     resource = resourceInfoType_model.objects.get(pk=_result[0].id)
     resource.editor_groups.add(self.test_editor_group)
     resource.storage_object.published = True
     # this also saves the storage object:
     resource.save()
 
     driver = self.driver
     driver.get(self.base_url)
     # login user
     login_user(driver, "manageruser", "secret")
     # make sure login was successful
     self.assertEqual("Logout", driver.find_element_by_xpath("//div[@id='inner']/div[2]/a[3]/div").text)
     # go to Editor
     driver.find_element_by_css_selector("div.button.middle_button").click()
     # go to Update->Resource
     mouse_over(driver, driver.find_element_by_link_text("Update"))
     #driver.find_element_by_link_text("Resource").click()        
     click_menu_item(driver, driver.find_element_by_link_text("Resource"))
     # make sure we are on the right site
     self.assertEqual("Select Resource to change | META-SHARE backend", driver.title)
     # check if LR entry is available and that its status is published
     try: 
         self.assertEqual("REVEAL-THIS Corpus",
             driver.find_element_by_link_text("REVEAL-THIS Corpus").text)
     except AssertionError as e: 
         self.verification_errors.append(str(e))
     try: 
         self.assertEqual(
           "published", 
           driver.find_element_by_xpath("//table[@id='result_list']/tbody/tr/td[3]").text)
     except AssertionError as e: 
         self.verification_errors.append(str(e))
     # click LR to edit it
     driver.find_element_by_link_text("REVEAL-THIS Corpus").click()
     # change the short name and save the LR
     driver.find_element_by_name("key_form-0-resourceShortName_0").clear()
     driver.find_element_by_name("key_form-0-resourceShortName_0").send_keys("en")
     driver.find_element_by_name("val_form-0-resourceShortName_0").clear()
     driver.find_element_by_name("val_form-0-resourceShortName_0").send_keys("a random short name")
     driver.find_element_by_name("_save").click()
     # make sure that the LR status is still published after saving
     try: 
         self.assertEqual(
           "published", 
           driver.find_element_by_xpath("//table[@id='result_list']/tbody/tr/td[3]").text)
     except AssertionError as e: 
         self.verification_errors.append(str(e))
コード例 #35
0
ファイル: test_view.py プロジェクト: ljo/META-SHARE
def _import_resource(fixture_name):
    """
    Imports the XML resource description with the given file name.
    
    The new resource is published and the ID is returned.
    """
    _result = test_utils.import_xml('{0}/repository/fixtures/{1}'
                                    .format(ROOT_PATH, fixture_name))
    result = _result[0].id
    resource = resourceInfoType_model.objects.get(pk=result)
    resource.storage_object.published = True
    resource.storage_object.save()
    return result
コード例 #36
0
 def test_save_metadata(self):
     """
     Tests that the metadata XML is not written to the storage folder for internal
     resources but only when the resource is ingested
     """
     # load test fixture; its initial status is 'internal'
     _result = test_utils.import_xml(TESTFIXTURE_XML)
     resource = resourceInfoType_model.objects.get(pk=_result.id)
     _storage_object = resource.storage_object
     _storage_object.update_storage()
     # initial status is 'internal'
     self.assertTrue(_storage_object.publication_status == INTERNAL)
     # internal resource has no metadata XML stored in storage folder
     self.assertFalse(
       os.path.isfile('{0}/metadata-{1:04d}.xml'.format(
               _storage_object._storage_folder(), _storage_object.revision)))
     # set status to ingested
     _storage_object.publication_status = INGESTED
     _storage_object.update_storage()
     # ingested resource has metadata XML stored in storage folder
     self.assertTrue(
       os.path.isfile('{0}/metadata-{1:04d}.xml'.format(
         _storage_object._storage_folder(), _storage_object.revision)))
     # ingested resource has global part of storage object in storage folder
     self.assertTrue(
       os.path.isfile('{0}/storage-global.json'.format(
         _storage_object._storage_folder())))
     # ingested resource has local part of storage object in storage folder
     self.assertTrue(
       os.path.isfile('{0}/storage-local.json'.format(
         _storage_object._storage_folder())))
     # ingested resource has digest zip in storage folder
     self.assertTrue(
       os.path.isfile('{0}/resource.zip'.format(
         _storage_object._storage_folder())))
     # digest zip contains metadata.xml and storage-global.json
     _zf_name = '{0}/resource.zip'.format( _storage_object._storage_folder())
     _zf = zipfile.ZipFile(_zf_name, mode='r')
     self.assertTrue('metadata.xml' in _zf.namelist())
     self.assertTrue('storage-global.json' in _zf.namelist())
     # md5 of digest zip is stored in storage object
     with ZipFile(_zf_name, 'r') as inzip:
         with inzip.open('metadata.xml') as resource_xml:
             resource_xml_string = resource_xml.read()
         with inzip.open('storage-global.json') as storage_file:
             # read json string
             storage_json_string = storage_file.read() 
         _checksum = compute_digest_checksum(
           resource_xml_string, storage_json_string)
         self.assertEqual(_checksum, _storage_object.digest_checksum)
コード例 #37
0
ファイル: test_view.py プロジェクト: hpusset/ELRI
def _import_resource(fixture_name, editor_group=None):
    """
    Imports the XML resource description with the given file name.
    
    The new resource is published and returned.
    """
    result = test_utils.import_xml('{0}/repository/fixtures/{1}'
                                    .format(ROOT_PATH, fixture_name))
    result.storage_object.published = True
    if not editor_group is None:
        result.editor_groups.add(editor_group)
        result.save()
    result.storage_object.save()
    return result
コード例 #38
0
ファイル: test_seo.py プロジェクト: JuliBakagianni/CEF-ELRC
    def test_sitemap(self):
        """
        Tests the correct appearance of the sitemap
        """

        imported_res = test_utils.import_xml("{}/repository/fixtures/" "testfixture.xml".format(ROOT_PATH))
        imported_res.storage_object.published = True
        imported_res.storage_object.save()
        client = Client()

        # Assert that the sitemap page contains the xmlsn and the entry
        # of the imported resource.
        response = client.get(SITEMAP_URL)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
        self.assertContains(response, "{}/repository/browse/italian-tts-speech-corpus-appen/".format(DJANGO_URL))
コード例 #39
0
ファイル: test_search.py プロジェクト: kperi/META-SHARE
 def init_index_with_a_resource(self):
     """
     Initializes an empty search index with a single resource.
     
     The imported resource is returned. Asserts that the index really only
     contains a single resource.
     """
     self.assert_index_is_empty()
     # import a single resource and save it in the DB
     resource = test_utils.import_xml(SearchIndexUpdateTests.RES_PATH_1)[0]
     resource.storage_object.save()
     # make sure the import has automatically changed the search index
     self.assertEqual(SearchQuerySet().count(), 1,
         "After the import of a resource the index must automatically " \
         "have changed and contain that resource.")
     return resource
コード例 #40
0
 def test_case_insensitive_search(self):
     """
     Asserts that case-insensitive searching is done.
     """
     imported_res = test_utils.import_xml(
         '{}/repository/test_fixtures/'
         'internal-corpus-Text-EngPers.xml'.format(ROOT_PATH))
     imported_res.storage_object.published = True
     imported_res.storage_object.save()
     client = Client()
     # assert that a lower case search for an upper case term succeeds:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True,
                           data={'q': 'fixture'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that an upper case search for a lower case term succeeds:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True,
                           data={'q': 'ORIGINALLY'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a lower case search for a mixed case term succeeds:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True,
                           data={'q': 'unicode'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a mixed case search for an upper case term succeeds:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True,
                           data={'q': 'FiXTuRe'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a camelCase search for an upper case term succeeds:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True,
                           data={'q': 'fixTure'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that an all lower case search finds a camelCase term:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True,
                           data={'q': 'camelcasetest'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
コード例 #41
0
 def init_index_with_a_resource(self):
     """
     Initializes an empty search index with a single resource.
     
     The imported resource is returned. Asserts that the index really only
     contains a single resource.
     """
     self.assert_index_is_empty()
     # import a single resource and save it in the DB
     resource = test_utils.import_xml(SearchIndexUpdateTests.RES_PATH_1)
     resource.storage_object.publication_status = PUBLISHED
     resource.storage_object.save()
     # make sure the import has automatically changed the search index
     self.assertEqual(SearchQuerySet().count(), 1,
       "After the import of a resource the index must automatically " \
       "have changed and contain that resource.")
     return resource
コード例 #42
0
ファイル: test_model.py プロジェクト: JuliBakagianni/CEF-ELRC
 def assert_import_equals_export(self, _roundtrip):
     _result = test_utils.import_xml(_roundtrip)
     with open(_roundtrip) as _import_file:
         _import_xml = _import_file.read()
         register_namespace("", SCHEMA_NAMESPACE)
         _import_xml = to_xml_string(fromstring(_import_xml), encoding="utf-8")
     _export_xml = to_xml_string(_result.export_to_elementtree(), encoding="utf-8")
     # cfedermann: uncomment these lines to dump import/export XML to file.
     #
     # with open('/tmp/_import.xml', 'wb') as _out:
     #    _out.write(_import_xml.encode('utf-8'))
     # with open('/tmp/_export.xml', 'wb') as _out:
     #    _out.write(_export_xml.encode('utf-8'))
     diff = "\n".join(unified_diff(_import_xml.split("\n"), _export_xml.split("\n")))
     self.assertEqual(
         _import_xml, _export_xml, msg="For file {0}, export differs from import:\n{1}".format(_roundtrip, diff)
     )
コード例 #43
0
 def test_download_count_visible_and_updated_in_search_results(self):
     """
     Verifies that the download count of a resource is visible and updated in
     the search results list.
     """
     test_res = test_utils.import_xml(
         '{}/repository/fixtures/'
         'downloadable_1_license.xml'.format(ROOT_PATH))
     test_res.storage_object.published = True
     test_res.storage_object.save()
     client = Client()
     client.login(username='******', password='******')
     # to be on the safe side, clear any existing stats
     LRStats.objects.all().delete()
     # assert that the download/view counts are both zero at first:
     response = client.get(_SEARCH_PAGE_PATH)
     self.assertContains(response, 'title="Number of downloads" />&nbsp;0')
     self.assertContains(response, 'title="Number of views" />&nbsp;0')
コード例 #44
0
 def assert_import_equals_export(self, _roundtrip):
     _result = test_utils.import_xml(_roundtrip)
     with open(_roundtrip) as _import_file:
         _import_xml = _import_file.read()
         register_namespace('', SCHEMA_NAMESPACE)
         _import_xml = tostring(fromstring(_import_xml))
     _export_xml = tostring(_result[0].export_to_elementtree())
 # cfedermann: uncomment these lines to dump import/export XML to file.
 #
 #with open('/tmp/_import.xml', 'w') as _out:
 #    _out.write(pretty_xml(_import_xml).encode('utf-8'))
 #with open('/tmp/_export.xml', 'w') as _out:
 #    _out.write(pretty_xml(_export_xml).encode('utf-8'))
     _pretty_import = pretty_xml(_import_xml).strip().encode('utf-8')
     _pretty_export = pretty_xml(_export_xml).strip().encode('utf-8')
     diff = '\n'.join(unified_diff(_pretty_import.split('\n'), _pretty_export.split('\n')))
     self.assertEqual(_pretty_import, _pretty_export,
          msg='For file {0}, export differs from import:\n{1}'.format(_roundtrip, diff))
コード例 #45
0
ファイル: test_search.py プロジェクト: marc1s/META-SHARE
 def test_camel_case_aware_search(self):
     """
     Asserts that the search engine is camelCase-aware.
     """
     imported_res = test_utils.import_xml(
         "{}/repository/test_fixtures/" "internal-corpus-Text-EngPers.xml".format(ROOT_PATH)
     )[0]
     imported_res.storage_object.published = True
     imported_res.storage_object.save()
     client = Client()
     # assert that a two-token search finds a camelCase term:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "speech synthesis"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a camelCase search term also finds the camelCase term:
     response = client.get("/{0}repository/search/".format(DJANGO_BASE), follow=True, data={"q": "speechSynthesis"})
     self.assertEqual("repository/search.html", response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
コード例 #46
0
ファイル: test_persistence.py プロジェクト: marc1s/META-SHARE
 def test_update(self):
     # define a maximum age of 4 seconds; this means that a resource is
     # checked for an update if it's older than 2 seconds
     settings.MAX_DIGEST_AGE = 6
     # import resource
     _result = test_utils.import_xml(TESTFIXTURE_XML)
     _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object
     self.assertIsNone(_so.digest_last_checked)
     # set status to ingested
     _so.publication_status = INGESTED
     _so.update_storage()
     _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object
     self.assertIsNotNone(_so.digest_last_checked)
     # remember 'last_checked' and 'modified' to compare against it later
     _last_checked = _so.digest_last_checked
     _modified = _so.digest_modified
     # check if an update is required; this is not the case
     update_digests()
     _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object
     # check that digest was not updated
     self.assertEquals(_modified, _so.digest_modified)
     self.assertEquals(_last_checked, _so.digest_last_checked)
     # wait 3 seconds and check again
     time.sleep(3)
     update_digests()
     _so = resourceInfoType_model.objects.get(pk=_result[0].id).storage_object
     # now an update should have happened, but the underlying data has not 
     # changed, so digest_modified is not changed
     self.assertEquals(_modified, _so.digest_modified)
     # but it HAS been checked that the digest is still up-to-date
     self.assertNotEqual(_last_checked, _so.digest_last_checked)
     _last_checked = _so.digest_last_checked
     _modified = _so.digest_modified
     _checksum = _so.digest_checksum
     # get digest checksum; since not enough time has passed yet, the
     # digest is not updated
     _so.get_digest_checksum()
     self.assertEquals(_last_checked, _so.digest_last_checked) 
     # again, wait 3 seconds so the digest requires another check
     time.sleep(3)
     self.assertEquals(_checksum, _so.get_digest_checksum())
     self.assertEquals(_modified, _so.digest_modified)
     self.assertNotEqual(_last_checked, _so.digest_last_checked)
コード例 #47
0
 def test_camel_case_aware_search(self):
     """
     Asserts that the search engine is camelCase-aware.
     """
     imported_res = test_utils.import_xml('{}/repository/test_fixtures/'
                     'internal-corpus-Text-EngPers.xml'.format(ROOT_PATH))
     imported_res.storage_object.published = True
     imported_res.storage_object.save()
     client = Client()
     # assert that a three-token search finds a camelCase term:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True, data={'q': 'camel case test'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a camelCase search term also finds the camelCase term:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True, data={'q': 'camelCaseTest'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
コード例 #48
0
 def test_camel_case_aware_search(self):
     """
     Asserts that the search engine is camelCase-aware.
     """
     imported_res = test_utils.import_xml('{}/repository/test_fixtures/'
                     'internal-corpus-Text-EngPers.xml'.format(ROOT_PATH))
     imported_res.storage_object.published = True
     imported_res.storage_object.save()
     client = Client()
     # assert that a three-token search finds a camelCase term:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True, data={'q': 'camel case test'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
     # assert that a camelCase search term also finds the camelCase term:
     response = client.get(_SEARCH_PAGE_PATH,
                           follow=True, data={'q': 'camelCaseTest'})
     self.assertEqual('repository/search.html', response.templates[0].name)
     self.assertContains(response, "1 Language Resource", status_code=200)
コード例 #49
0
 def test_update(self):
     # define a maximum age of 4 seconds; this means that a resource is
     # checked for an update if it's older than 2 seconds
     settings.MAX_DIGEST_AGE = 6
     # import resource
     _result = test_utils.import_xml(TESTFIXTURE_XML)
     _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object
     self.assertIsNone(_so.digest_last_checked)
     # set status to ingested
     _so.publication_status = INGESTED
     _so.update_storage()
     _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object
     self.assertIsNotNone(_so.digest_last_checked)
     # remember 'last_checked' and 'modified' to compare against it later
     _last_checked = _so.digest_last_checked
     _modified = _so.digest_modified
     # check if an update is required; this is not the case
     update_digests()
     _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object
     # check that digest was not updated
     self.assertEquals(_modified, _so.digest_modified)
     self.assertEquals(_last_checked, _so.digest_last_checked)
     # wait 3 seconds and check again
     time.sleep(3)
     update_digests()
     _so = resourceInfoType_model.objects.get(pk=_result.id).storage_object
     # now an update should have happened, but the underlying data has not 
     # changed, so digest_modified is not changed
     self.assertEquals(_modified, _so.digest_modified)
     # but it HAS been checked that the digest is still up-to-date
     self.assertNotEqual(_last_checked, _so.digest_last_checked)
     _last_checked = _so.digest_last_checked
     _modified = _so.digest_modified
     _checksum = _so.digest_checksum
     # get digest checksum; since not enough time has passed yet, the
     # digest is not updated
     _so.get_digest_checksum()
     self.assertEquals(_last_checked, _so.digest_last_checked) 
     # again, wait 3 seconds so the digest requires another check
     time.sleep(3)
     self.assertEquals(_checksum, _so.get_digest_checksum())
     self.assertEquals(_modified, _so.digest_modified)
     self.assertNotEqual(_last_checked, _so.digest_last_checked)
コード例 #50
0
ファイル: test_status_workflow.py プロジェクト: MiltosD/ELRC2
    def setUp(self):
        """
        Import a resource to test the workflow changes for
        """
        test_utils.set_index_active(False)
        test_utils.setup_test_storage()
        _test_editor_group = \
            EditorGroup.objects.create(name='test_editor_group')
        _test_manager_group = \
            EditorGroupManagers.objects.create(name='test_manager_group',
                                               managed_group=_test_editor_group)
        test_utils.create_manager_user(
            'manageruser', '*****@*****.**', 'secret',
            (_test_editor_group, _test_manager_group))

        _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
        _result = test_utils.import_xml(_fixture)
        _result.editor_groups.add(_test_editor_group)
        StatusWorkflowTest.resource_id = _result.id
コード例 #51
0
ファイル: test_seo.py プロジェクト: MiltosD/ELRC2
 def test_sitemap(self):
     """
     Tests the correct appearance of the sitemap
     """
    
     imported_res = test_utils.import_xml('{}/repository/fixtures/'
       'testfixture.xml'.format(ROOT_PATH))
     imported_res.storage_object.published = True
     imported_res.storage_object.save()
     client = Client()
     
     # Assert that the sitemap page contains the xmlsn and the entry
     # of the imported resource.
     response = client.get(SITEMAP_URL)
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 
       '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
     self.assertContains(response, 
       '{}/repository/browse/italian-tts-speech-corpus-appen/' \
       .format(DJANGO_URL))
コード例 #52
0
ファイル: test_example.py プロジェクト: MiltosD/ELRC2
    def setUp(self):

        test_utils.setup_test_storage()
        _fixture = '{0}/repository/fixtures/testfixture.xml'.format(ROOT_PATH)
        _result = test_utils.import_xml(_fixture)
        self.resource_id = _result.id
        resource = resourceInfoType_model.objects.get(pk=self.resource_id)
        resource.storage_object.published = True
        resource.storage_object.save()
        # set up test users with and without staff permissions.
        # These will live in the test database only, so will not
        # pollute the "normal" development db or the production db.
        # As a consequence, they need no valuable password.
        staffuser = User.objects.create_user('staffuser', '*****@*****.**',
                                             'secret')
        staffuser.is_staff = True
        staffuser.save()
        User.objects.create_user('normaluser', '*****@*****.**', 'secret')

        super(ExampleSeleniumTest, self).setUp()
        self.base_url = '{0}/{1}'.format(DJANGO_URL, DJANGO_BASE)
コード例 #53
0
 def assert_import_equals_export(self, _roundtrip):
     _result = test_utils.import_xml(_roundtrip)
     with open(_roundtrip) as _import_file:
         _import_xml = _import_file.read()
         register_namespace('', SCHEMA_NAMESPACE)
         _import_xml = to_xml_string(fromstring(_import_xml),
                                     encoding="utf-8")
     _export_xml = to_xml_string(_result.export_to_elementtree(),
                                 encoding="utf-8")
     # cfedermann: uncomment these lines to dump import/export XML to file.
     #
     #with open('/tmp/_import.xml', 'wb') as _out:
     #    _out.write(_import_xml.encode('utf-8'))
     #with open('/tmp/_export.xml', 'wb') as _out:
     #    _out.write(_export_xml.encode('utf-8'))
     diff = '\n'.join(
         unified_diff(_import_xml.split('\n'), _export_xml.split('\n')))
     self.assertEqual(
         _import_xml,
         _export_xml,
         msg='For file {0}, export differs from import:\n{1}'.format(
             _roundtrip, diff.encode('utf-8')))