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)
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})
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)
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
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)
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
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")
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
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})
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})
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})