Пример #1
0
    def test_project_created_with_correct_details(self, mock_importer):
        """Test that a project is created with the correct details."""
        self.register(name=Fixtures.name)
        self.signin()
        vol = dict(id='123abc', name='My Volume')
        category = CategoryFactory()
        tmpl_fixtures = TemplateFixtures(category)
        select_task = tmpl_fixtures.iiif_select_tmpl
        tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        category.info = dict(presenter='iiif-annotation',
                             volumes=[vol],
                             templates=[tmpl])
        project_repo.update_category(category)

        endpoint = '/lc/projects/{}/new'.format(category.short_name)
        form_data = dict(name='foo',
                         short_name='bar',
                         template_id=tmpl['id'],
                         volume_id=vol['id'])
        res = self.app_post_json(endpoint, data=form_data)
        project = project_repo.get(1)

        # Check project details
        assert_equal(project.name, form_data['name'])
        assert_equal(project.short_name, form_data['short_name'])
        assert_equal(project.webhook, 'http://localhost/lc/analysis')
        assert_equal(project.published, True)
        assert_equal(project.description, tmpl['description'])
        assert_dict_equal(project.info, {
            'template_id': tmpl['id'],
            'volume_id': vol['id']
        })
Пример #2
0
    def test_new_project_task_redundancy_updated(self, mock_importer,
                                                 mock_update_redundancy):
        """Test task redundancy updated for new projects."""
        self.register(name=Fixtures.name)
        self.signin()
        min_answers = 10
        vol = dict(id='123abc', name='My Volume')
        category = CategoryFactory()
        tmpl_fixtures = TemplateFixtures(category)
        select_task = tmpl_fixtures.iiif_select_tmpl
        tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        tmpl['min_answers'] = min_answers
        category.info = dict(presenter='iiif-annotation',
                             volumes=[vol],
                             templates=[tmpl])
        project_repo.update_category(category)

        endpoint = '/lc/projects/{}/new'.format(category.short_name)
        form_data = dict(name='foo',
                         short_name='bar',
                         template_id=tmpl['id'],
                         volume_id=vol['id'])
        self.app_post_json(endpoint, data=form_data)
        project = project_repo.get(1)
        mock_update_redundancy.assert_called_once_with(project, min_answers)
Пример #3
0
    def test_child_projects_not_built_from_non_iiif_templates(self):
        """Test that only IIIF projects can be built from parents."""
        self.register()
        user = user_repo.get(1)
        vol = dict(id='123abc', name='My Volume', importer='foo')
        category = CategoryFactory()
        tmpl_fixtures = TemplateFixtures(category)
        select_task = tmpl_fixtures.iiif_select_tmpl
        parent_tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        child_tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        child_tmpl['parent_template_id'] = parent_tmpl['id']

        category.info = dict(presenter='iiif-annotation',
                             volumes=[vol],
                             templates=[parent_tmpl, child_tmpl])
        project_repo.update_category(category)
        parent = ProjectFactory(owner=user,
                                category=category,
                                info=dict(template_id=parent_tmpl['id'],
                                          volume_id=vol['id']))

        endpoint = '/lc/projects/{}/new'.format(category.short_name)
        form_data = dict(name='foo',
                         short_name='bar',
                         template_id=child_tmpl['id'],
                         volume_id=vol['id'])
        res = self.app_post_json(endpoint, data=form_data)
        res_data = json.loads(res.data)
        msg = 'Only IIIF projects can be built from parents.'
        assert_equal(res_data['flash'], msg)
Пример #4
0
    def test_project_created_with_volume_avatar(self, mock_importer):
        """Test that a project is created with the volume's avatar."""
        self.register()
        self.signin()
        vol = dict(id='123abc',
                   name='My Volume',
                   container='foo',
                   thumbnail='bar.png',
                   thumbnail_url='/foo/bar.png')
        category = CategoryFactory()
        tmpl_fixtures = TemplateFixtures(category)
        select_task = tmpl_fixtures.iiif_select_tmpl
        tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        category.info = dict(presenter='iiif-annotation',
                             volumes=[vol],
                             templates=[tmpl])
        project_repo.update_category(category)

        endpoint = '/lc/projects/{}/new'.format(category.short_name)
        form_data = dict(name='foo',
                         short_name='bar',
                         template_id=tmpl['id'],
                         volume_id=vol['id'])
        res = self.app_post_json(endpoint, data=form_data)
        project = project_repo.get(1)

        # Check project avatar details
        assert_equal(project.info['container'], vol['container'])
        assert_equal(project.info['thumbnail'], vol['thumbnail'])
        assert_equal(project.info['thumbnail_url'], vol['thumbnail_url'])
Пример #5
0
    def test_z3950_project_creation(self, mock_importer):
        """Test that a Z39.50 project is created."""
        mock_importer.count_tasks_to_import.return_value = 1
        self.register()
        self.signin()
        vol = dict(id='123abc',
                   name='My Volume',
                   importer='z3950',
                   data=dict(album_id=self.flickr_album_id))
        category = CategoryFactory()
        tmpl_fixtures = TemplateFixtures(category)
        z3950_task = tmpl_fixtures.z3950_tmpl
        tmpl = tmpl_fixtures.create(task_tmpl=z3950_task)
        category.info = dict(presenter='z3950',
                             volumes=[vol],
                             templates=[tmpl])
        project_repo.update_category(category)

        endpoint = '/lc/projects/{}/new'.format(category.short_name)
        form_data = dict(name='foo',
                         short_name='bar',
                         template_id=tmpl['id'],
                         volume_id=vol['id'])
        res = self.app_post_json(endpoint, data=form_data)
        res_data = json.loads(res.data)
        msg = 'The project was generated with 1 task.'
        assert_equal(res_data['flash'], msg)
        project = project_repo.get(1)

        # Check correct task data imported
        expected = call(task_repo,
                        project.id,
                        type='z3950',
                        album_id=self.flickr_album_id)
        assert_equal(mock_importer.create_tasks.call_args_list, [expected])
Пример #6
0
 def test_get_project_template(self):
     """Test that the correct template is returned."""
     category = CategoryFactory()
     tmpl_fixtures = TemplateFixtures(category)
     tmpl1 = tmpl_fixtures.create()
     tmpl2 = tmpl_fixtures.create()
     fake_templates = [tmpl1, tmpl2]
     category.info = dict(templates=fake_templates)
     self.project_repo.update_category(category)
     project_info = dict(template_id=tmpl1['id'])
     project = ProjectFactory(category=category, info=project_info)
     ret_tmpl = self.base_analyst.get_project_template(project)
     assert_equal(ret_tmpl, tmpl1)
Пример #7
0
    def test_project_built_from_valid_parent_template(self, mock_count,
                                                      mock_create_tasks):
        """Test that import data modified for IIIF child projects."""
        self.register()
        user = user_repo.get(1)
        vol = dict(id='123abc',
                   name='My Volume',
                   importer='iiif',
                   data=dict(manifest_uri=self.manifest_uri))
        category = CategoryFactory()
        tmpl_fixtures = TemplateFixtures(category)
        select_task = tmpl_fixtures.iiif_select_tmpl
        parent_tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        child_tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        child_tmpl['parent_template_id'] = parent_tmpl['id']

        category.info = dict(presenter='iiif-annotation',
                             volumes=[vol],
                             templates=[parent_tmpl, child_tmpl])
        project_repo.update_category(category)

        parent = ProjectFactory(id=42,
                                owner=user,
                                category=category,
                                info=dict(template_id=parent_tmpl['id'],
                                          volume_id=vol['id']))

        n_tasks = 3
        tasks = TaskFactory.create_batch(n_tasks, n_answers=1, project=parent)
        for task in tasks:
            TaskRunFactory.create(user=user, project=parent, task=task)
        results = result_repo.filter_by(project_id=parent.id)
        for result in results:
            result.info = 'foo'
            result_repo.update(result)

        endpoint = '/lc/projects/{}/new'.format(category.short_name)
        form_data = dict(name='foo',
                         short_name='bar',
                         template_id=child_tmpl['id'],
                         volume_id=vol['id'])

        self.app_post_json(endpoint, data=form_data)

        expected_call = call(task_repo,
                             1,
                             type='iiif-enhanced',
                             manifest_uri=self.manifest_uri,
                             parent_id=parent.id)
        assert_equal(mock_create_tasks.call_args_list, [expected_call])
Пример #8
0
    def test_child_projects_not_built_from_incomplete_parents(self):
        """Test that child projects are not built from incomplete parents."""
        self.register()
        user = user_repo.get(1)
        vol = dict(id='123abc', name='My Volume', importer='iiif')
        category = CategoryFactory()
        tmpl_fixtures = TemplateFixtures(category)
        select_task = tmpl_fixtures.iiif_select_tmpl
        parent_tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        child_tmpl = tmpl_fixtures.create(task_tmpl=select_task)
        child_tmpl['parent_template_id'] = parent_tmpl['id']

        category.info = dict(presenter='iiif-annotation',
                             volumes=[vol],
                             templates=[parent_tmpl, child_tmpl])
        project_repo.update_category(category)

        parent = ProjectFactory(owner=user,
                                category=category,
                                info=dict(template_id=parent_tmpl['id'],
                                          volume_id=vol['id']))

        n_tasks = 3
        tasks = TaskFactory.create_batch(n_tasks, n_answers=1, project=parent)

        endpoint = '/lc/projects/{}/new'.format(category.short_name)
        form_data = dict(name='foo',
                         short_name='bar',
                         template_id=child_tmpl['id'],
                         volume_id=vol['id'])

        # Check parent with incomplete tasks and results
        res = self.app_post_json(endpoint, data=form_data)
        res_data = json.loads(res.data)
        msg = 'There is no valid parent for this template and volume.'
        assert_equal(res_data['flash'], msg)

        # Check parent with incomplete results
        for task in tasks:
            TaskRunFactory.create(user=user, project=parent, task=task)
        res = self.app_post_json(endpoint, data=form_data)
        res_data = json.loads(res.data)
        msg = 'There is no valid parent for this template and volume.'
        assert_equal(res_data['flash'], msg)