示例#1
0
    def delete_documents():
        print('\n\033[01m## Deletion ##\033[0m')
        make_test(lambda: DocController.delete_documents(2))(
            DocumentTest, 'existing document', False)

        make_test(lambda: DocController.delete_documents(2))(
            DocumentTest, 'non existing document', True)
示例#2
0
 def test_update_tour_1(self):
     DocController.create_document({
         "title": "title",
         "source": "source1",
         "description": "a description",
         "file": "1.gif",
         'user_id': 1,
         'role': {'label': 'admin'}
     }, {
         'user_id': 1
     })
     DocController.create_document({
         "title": "title2",
         "source": "source2",
         "description": "a description",
         "file": "1.gif",
         'user_id': 1,
         'role': {'label': 'admin'}
     }, {
         'user_id': 1
     })
     print("adding existing document")
     expected_response = {
         'extendedDocs': [{
             'id': 1,
             'title': None,
             'tour_id': 1,
             'doc_position': 1,
             'text2': None,
             'doc_id': 1,
             'document': {
                 'id': 1,
                 'validationStatus': {
                     'status': Status.Validated,
                     'doc_id': 1
                 },
                 'user_id': 1,
                 'comments': [],
                 'title': 'title',
                 'publicationDate': None,
                 'file': '1.gif',
                 'description': 'a description',
                 'source': 'source1',
                 'rightsHolder': None,
                 'refDate': None,
                 'visualization': {
                     'positionZ': None,
                     'id': 1,
                     'quaternionW': None,
                     'positionY': None,
                     'quaternionZ': None,
                     'quaternionX': None,
                     'positionX': None,
                     'quaternionY': None}},
             'text1': None}],
         'name': 'First tour',
         'id': 1,
         'description': 'This is the first guided tour'
     }
     assert expected_response == TourController.add_document(1, 1)
示例#3
0
def get_archive(doc_id, auth_info):
    try:
        DocController.get_document_by_id(doc_id, auth_info)
    except NoResultFound:
        raise NotFound("Document does not exist")
    archive = ArchiveController.get_archive(doc_id)
    return ResponseOK(archive)
示例#4
0
 def test_create_document_5(self):
     print('Create document with missing attributes')
     with pytest.raises(KeyError):
         DocController.create_document(
             {
                 'user_id': 2,
                 'title': 'another title'
             }, {'user_id': 2})
示例#5
0
 def test_delete_document_as_contributor(self):
     print('Delete a document as contributor')
     with pytest.raises(AuthError):
         DocController.delete_documents(4, {
             'user_id': 2,
             'role': {
                 'label': 'contributor'
             }
         })
示例#6
0
 def test_validate_document_2(self):
     print('Validate a document as an admin')
     with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
         DocController.validate_document(7, {
             'user_id': 1,
             'role': {
                 'label': 'admin'
             }
         }, {'user_id': 1})
示例#7
0
 def test_validate_document_1(self):
     print('Validate a document as contributor')
     with pytest.raises(AuthError):
         DocController.validate_document(2, {
             'user_id': 2,
             'role': {
                 'label': 'contributor'
             }
         }, {'user_id': 2})
示例#8
0
 def test_delete_document_as_admin(self):
     print('Delete a document as admin')
     try:
         DocController.delete_documents(4, {
             'user_id': 1,
             'role': {
                 'label': 'admin'
             }
         })
     except Exception as e:
         print(e)
示例#9
0
    def creation():
        document = DocController.create_document(
            {key: request.form.get(key)
             for key in request.form.keys()})

        if request.files.get('link'):
            filename = save_file(document["id"], request.files['link'])
            if filename:
                DocController.update_document(document["id"],
                                              {"link": filename})
        return document
示例#10
0
 def test_update_document_as_contributor(self):
     print('Update a document as contributor')
     with pytest.raises(AuthError):
         DocController.update_document(
             {
                 'user_id': 2,
                 'user_position': 'contributor',
                 'role': {
                     'label': 'contributor'
                 }
             }, 1, {
                 'positionX': 12,
                 'description': 'description of a document'
             })
示例#11
0
 def test_update_non_existing_document(self):
     print('Update a non existing document')
     with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
         DocController.update_document(
             {
                 'user_position': 'admin',
                 'user_id': 2,
                 'role': {
                     'label': 'admin'
                 }
             }, -1, {
                 'positionX': 12,
                 'description': 'another description'
             })
示例#12
0
 def test_get_all_documents(self):
     print('Get all documents')
     response = DocController.get_documents({})
     assert len(response) == 3
     assert response[0]['id'] == 1
     assert response[1]['id'] == 2
     assert response[2]['id'] == 4
示例#13
0
    def update_documents():
        print('\n\033[01m## Updating ##\033[0m')
        make_test(lambda: DocController.update_document(1, {
            'positionX': 12,
            'description': 'description of a document'
        }))(DocumentTest, 'existing document', False)

        make_test(lambda: DocController.update_document(1, {
            'positionX': 12,
            'description': 'another description'
        }))(DocumentTest, 'existing document', False)

        make_test(lambda: DocController.update_document(-1, {
            'positionX': 12,
            'description': 'description of a document'
        }))(DocumentTest, 'existing document', True)
示例#14
0
    def read_documents():
        print('\n\033[01m## Reading ##\033[0m')

        make_test(lambda: DocController.get_documents({}))(
            DocumentTest, 'all documents', False)

        make_test(lambda: DocController.get_documents({
            'keyword': 'description',
            'refDateStart': '2018-12-03'
        }))(DocumentTest, 'specific documents', False)

        make_test(lambda: DocController.get_document_by_id(1))(
            DocumentTest, 'document with existing id', False)

        make_test(lambda: DocController.get_document_by_id(-1))(
            DocumentTest, 'document with non existing id', True)
示例#15
0
 def test_get_specific_documents(self):
     print('Get specific documents')
     response = DocController.get_documents({
         'keyword': 'description',
         'refDateStart': '2018-12-03'
     })
     assert len(response) == 1
     assert response[0]['id'] == 2
示例#16
0
    def create_documents():
        print("\n\033[01m## Creation of documents ##\033[0m")
        make_test(lambda: DocController.create_document({
            "title": "title",
            "subject": "Subject1",
            "type": "type",
            "description": "a description",
            "link": "1.gif"
        }))(GuidedTourTest, "all needed attributes", False)

        make_test(lambda: DocController.create_document({
            "title": "title2",
            "subject": "Subject2",
            "type": "type",
            "description": "a description",
            "link": "1.gif"
        }))(GuidedTourTest, "all needed attributes", False)
示例#17
0
def upload_file(doc_id, auth_info):
    if request.files.get('file'):
        file = request.files['file']
        filename = save_file(file)
        updated_document = DocController.update_document(
            auth_info, doc_id, {'file': filename})
        return ResponseOK(updated_document)
    else:
        raise BadRequest("Missing 'file' data")
示例#18
0
 def test_get_documents_to_validate_contributor(self):
     print('Get documents to validate as a contributor')
     response = DocController.get_documents_to_validate({
         'user_id': 3,
         'role': {
             'label': 'admin'
         }
     })
     assert len(response) == 1
     assert response[0]['id'] == 3
示例#19
0
 def test_delete_document(self):
     print("delete a document")
     expected_response = None
     assert expected_response == DocController.delete_documents(
         1, {
             'user_id': 1,
             "role": {
                 'label': 'admin'
             }
         })
示例#20
0
    def create_documents():
        print('\033[01m## Creation ##\033[0m')

        make_test(lambda: DocController.create_document({
            'title': 'title',
            'subject': 'Subject1',
            'type': 'type',
            'description': 'a description',
            'link': '1.gif'
        }))(DocumentTest, 'all needed attributes', False)

        make_test(lambda: DocController.create_document({
            'title': 'title',
            'subject': 'Subject1',
            'type': 'type',
            'description': 'a description',
            'link': '1.gif'}))(
            DocumentTest, 'all needed attributes', False)

        make_test(lambda: DocController.create_document({
            'title': 'title',
            'subject': 'Subject2',
            'type': 'type',
            'description': 'a description',
            'link': '2.gif',
            'refDate': '2019-02-05'
        }))(DocumentTest, 'all needed attributes', False)

        make_test(lambda: DocController.create_document({
            'title': 'another title',
            'subject': 'Subject3',
            'type': 'type',
            'non_attr': 'non_value',
            'refDate': '2018-12-03',
            'description': 'an other description',
            'link': '3.png'
        }))(DocumentTest, 'needed + nonexistent attributes', False)

        make_test(lambda: DocController.create_document({
            'title': 'another title'
        }))(DocumentTest, 'needed argument missing', True)
示例#21
0
 def test_update_document_as_admin(self):
     print('Update a document as admin')
     response = DocController.update_document(
         {
             'user_id': 2,
             'user_position': 'admin',
             'role': {
                 'label': 'admin'
             }
         }, 1, {
             'positionX': 12,
             'description': 'another description'
         })
     assert response['visualization']['positionX'] == 12
     assert response['description'] == 'another description'
示例#22
0
 def test_create_document_4(self):
     print('Create document with all needed and non existent '
           'attributes as an admin')
     assert DocController.create_document(
         {
             'user_id': 1,
             'title': 'another title',
             'source': 'source3',
             'non_attr': 'non_value',
             'refDate': FAKE_REF_DATE,
             'description': 'details',
             'file': '3.png',
             'role': {
                 'label': 'admin'
             }
         }, {'user_id': 1}) is not None
示例#23
0
def create_document(auth_info):
    args = {key: request.form.get(key) for key in request.form.keys()}
    args.update(auth_info)
    if request.files.get('file'):
        filename = save_file(request.files['file'])
        if filename is not None:
            args['file'] = filename
            try:
                document = DocController.create_document(args, auth_info)
            except Exception as e:
                delete_file(f'{UPLOAD_FOLDER}/{filename}')
                raise e
            return ResponseCreated(document)
        else:
            raise FormatError("Invalid file format")
    else:
        raise BadRequest("Missing 'file' parameter")
示例#24
0
 def test_create_document_3(self):
     print('Create document with all needed and non existent '
           'attributes as a contributor')
     assert DocController.create_document(
         {
             'user_id': 2,
             'title': 'another title',
             'subject': 'Subject3',
             'type': 'type',
             'non_attr': 'non_value',
             'refDate': FAKE_REF_DATE,
             'description': 'an other description',
             'file': '3.png',
             'role': {
                 'label': 'contributor'
             }
         }, {'user_id': 2}) is not None
示例#25
0
 def test_create_document_2(self):
     print('create extended document with all document with all '
           'needed attributes')
     expected_response = {
         'id': 2,
         'publicationDate': None,
         'refDate': FAKE_REF_DATE,
         'subject': 'Subject2',
         'file': '2.gif',
         'description': 'a description',
         'type': 'type',
         'originalName': None,
         'title': 'title',
         'validationStatus': {
             'doc_id': 2,
             'status': Status.Validated
         },
         'user_id': 2,
         'comments': [],
         'visualization': {
             'id': 2,
             'quaternionW': None,
             'positionZ': None,
             'quaternionZ': None,
             'positionX': None,
             'positionY': None,
             'quaternionY': None,
             'quaternionX': None
         }
     }
     assert expected_response == DocController.create_document(
         {
             'user_id': 2,
             'title': 'title',
             'subject': 'Subject2',
             'type': 'type',
             'description': 'a description',
             'file': '2.gif',
             'refDate': FAKE_REF_DATE,
             'role': {
                 'label': 'admin'
             }
         }, {'user_id': 2})
示例#26
0
 def test_create_document(self):
     Controller.recreate_tables()
     print("Create a valid document")
     expected_response = {
         'id': 1,
         'comments': [],
         'user_id': 1,
         'publicationDate': None,
         'subject': 'Subject1',
         'title': 'title',
         'refDate': None,
         'file': '1.gif',
         'originalName': None,
         'description': 'a description',
         'type': 'type',
         'validationStatus': {
             'status': Status.Validated,
             'doc_id': 1
         },
         'visualization': {
             'quaternionZ': None,
             'positionZ': None,
             'positionX': None,
             'id': 1,
             'quaternionY': None,
             'quaternionW': None,
             'positionY': None,
             'quaternionX': None
         }
     }
     assert expected_response == DocController.create_document(
         {
             'title': 'title',
             'subject': 'Subject1',
             'type': 'type',
             'description': 'a description',
             'file': '1.gif',
             'user_id': 1,
             "role": {
                 'label': 'admin'
             }
         }, {'user_id': 1})
示例#27
0
    def test_create_document_1(self):
        print('create document to validate with all needed attributes')
        expected_response = {
            'file': '1.gif',
            'description': 'a description',
            'subject': 'Subject1',
            'title': 'title',
            'originalName': None,
            'type': 'type',
            'publicationDate': None,
            'refDate': None,
            'visualization': {
                'positionX': None,
                'quaternionY': None,
                'positionZ': None,
                'quaternionZ': None,
                'quaternionX': None,
                'id': 1,
                'positionY': None,
                'quaternionW': None
            },
            'user_id': 1,
            'validationStatus': {
                'doc_id': 1,
                'status': Status.Validated
            },
            'comments': [],
            'id': 1
        }

        assert expected_response == DocController.create_document(
            {
                'user_id': 1,
                'title': 'title',
                'subject': 'Subject1',
                'type': 'type',
                'description': 'a description',
                'file': '1.gif',
                'role': {
                    'label': 'admin'
                }
            }, {'user_id': 1})
示例#28
0
 def test_update_document_2(self):
     print("update a document")
     expected_response = {
         'user_id': 1,
         'refDate': None,
         'file': '1.gif',
         'publicationDate': None,
         'description': 'a new description',
         'originalName': None,
         'subject': 'Subject1',
         'type': 'type',
         'title': 'title',
         'visualization': {
             'positionZ': None,
             'quaternionX': None,
             'id': 1,
             'quaternionZ': None,
             'positionX': 12.0,
             'positionY': 15.0,
             'quaternionY': None,
             'quaternionW': None
         },
         'id': 1,
         'validationStatus': {
             'status': Status.Validated,
             'doc_id': 1
         },
         'comments': []
     }
     assert expected_response == DocController.update_document(
         {
             'user_id': 1,
             'role': {
                 'label': 'admin'
             }
         }, 1, {
             'positionY': 15,
             'description': 'a new description'
         })
示例#29
0
 def test_update_document_1(self):
     print("update a document")
     expected_response = {
         'user_id': 1,
         'publicationDate': None,
         'description': 'description of a document',
         'source': 'source1',
         'file': '1.gif',
         'refDate': None,
         'title': 'title',
         'rightsHolder': None,
         'id': 1,
         'visualization': {
             'quaternionY': None,
             'quaternionZ': None,
             'quaternionX': None,
             'id': 1,
             'positionY': None,
             'positionX': 12.0,
             'quaternionW': None,
             'positionZ': None
         },
         'validationStatus': {
             'status': Status.Validated,
             'doc_id': 1
         },
         'comments': [],
     }
     assert expected_response == DocController.update_document(
         {
             'user_id': 1,
             "role": {
                 'label': 'admin'
             }
         }, 1, {
             'positionX': 12,
             'description': 'description of a document'
         })
示例#30
0
def delete_member_image(doc_id, auth_info):
    filename = DocController.get_document_file_location(doc_id, auth_info)
    document = DocController.delete_document_file(auth_info, doc_id)
    delete_file(filename)
    return ResponseOK(document)