Example #1
0
    def delete_tours():
        print("\n\033[01m## Deletion ##\033[0m")
        make_test(lambda: TourController.delete_tour(3))(GuidedTourTest,
                                                         "existing document",
                                                         False)

        make_test(lambda: TourController.delete_tour(3))(GuidedTourTest,
                                                         "existing document",
                                                         True)
Example #2
0
    def update_tours():
        print("\n\033[01m## Updating ##\033[0m")
        make_test(lambda: TourController.add_document(1, 1))(
            GuidedTourTest, "adding existing document", False)

        make_test(lambda: TourController.add_document(1, 1))(
            GuidedTourTest, "adding twice existing document", False)

        make_test(lambda: TourController.add_document(1, 2))(
            GuidedTourTest, "adding existing document", False)

        make_test(lambda: TourController.add_document(2, 1))(
            GuidedTourTest, "adding existing document", False)

        make_test(lambda: TourController.add_document(1, 3))(
            GuidedTourTest, "adding non existing document", True)

        make_test(lambda: TourController.add_document(-1, 3))(
            GuidedTourTest, "adding non existing document", True)

        make_test(
            lambda: TourController.update(1, {
                'title': 'this is a new title',
                'description': 'new description'
            }))(GuidedTourTest, "updating existing guided tour", False)

        make_test(lambda: TourController.update_document(
            1, 1, {'text1': 'this is a text'}))(
                GuidedTourTest, "updating guided tour document", False)
Example #3
0
    def read_tours():
        print("\n\033[01m## Reading ##\033[0m")

        make_test(lambda: TourController.get_tours())(GuidedTourTest,
                                                      "all tours", False)

        # @TODO: create method to filter docs
        make_test(lambda: TourController.get_tours())(GuidedTourTest,
                                                      "specific tour", False)

        make_test(lambda: TourController.get_tour_by_id(2))(
            GuidedTourTest, "tour with existing id", False)

        make_test(lambda: TourController.get_tour_by_id(-1))(
            GuidedTourTest, "tour with non existing id", True)
Example #4
0
def add_document_to_guided_tour(tour_id):
    doc_id = request.form.get('doc_id')
    if doc_id is None or tour_id is None:
        raise BadRequest("Parameter is missing : 'doc_id'")

    guided_tour = TourController.add_document(tour_id, doc_id)
    return ResponseCreated(guided_tour)
Example #5
0
    def create_tours():
        print("\033[01m## Creation of tours ##\033[0m")
        make_test(lambda: TourController.create_tour(
            "First tour", "This is the first guided tour"))(
                GuidedTourTest, "all needed attributes", False)

        make_test(lambda: TourController.create_tour(
            "Second tour", "This is the second guided tour"))(
                GuidedTourTest, "all needed attributes", False)

        make_test(lambda: TourController.create_tour(
            "Third tour", "This is the third guided tour"))(
                GuidedTourTest, "all needed attributes", False)

        make_test(lambda: TourController.create_tour())(
            GuidedTourTest, "needed argument missing", True)
Example #6
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)
Example #7
0
def create_guided_tour():
    name = request.args.get('name')
    description = request.args.get('description')
    if name is None or description is None:
        return 'parameter is missing', 400

    return send_response(
        lambda: TourController.create_tour(name, description))()
Example #8
0
def add_document_to_guided_tour():
    tour_id = request.args.get("tour_id")
    doc_id = request.args.get('doc_id')
    if doc_id is None or tour_id is None:
        return 'parameter is missing', 400

    return send_response(
        lambda: TourController.add_document(tour_id, doc_id))()
Example #9
0
def create_guided_tour():
    name = request.form.get('name')
    description = request.form.get('description')
    if name is None or description is None:
        raise BadRequest("Parameters are missing : 'name', 'description'")

    guided_tour = TourController.create_tour(name, description)
    return ResponseCreated(guided_tour)
 def test_read_tours_2(self):
     print("tour with existing id")
     expected_response = {
         'extendedDocs': [],
         'name': 'First tour',
         'id': 1,
         'description': 'This is the first guided tour'
     }
     assert expected_response == TourController.get_tour_by_id(1)
 def test_delete_tour_1(self):
     print("existing tour")
     expected = {
         'extendedDocs': [],
         'name': 'Third tour',
         'id': 3,
         'description': 'This is the third guided tour'
     }
     assert TourController.delete_tour(3) == expected
 def test_create_tours_3(self):
     print("all needed attributes")
     expected_response = {
         'extendedDocs': [],
         'name': 'Third tour',
         'id': 3,
         'description': 'This is the third guided tour'
     }
     assert expected_response == TourController.create_tour(
         "Third tour", "This is the third guided tour")
 def test_create_tours_1(self):
     Controller.recreate_tables()
     print("all needed attributes")
     expected_response = {
         'extendedDocs': [],
         'name': 'First tour',
         'id': 1,
         'description': 'This is the first guided tour'
     }
     assert expected_response == TourController.create_tour(
         "First tour", "This is the first guided tour")
Example #14
0
def get_guided_tour(tour_id):
    guided_tour = TourController.get_tour_by_id(tour_id)
    return ResponseOK(guided_tour)
 def test_delete_tour_2(self):
     print("non existing tour")
     with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
         TourController.delete_tour(3)
Example #16
0
def update_guided_tour(tour_id):
    return send_response(
        lambda: TourController.update(tour_id, request.form))()
 def test_update_tour_4(self):
     print("updating existing guided tour")
     response = TourController.update(1, {'description': 'new description'})
     assert response['description'] == 'new description'
 def test_update_tour_3(self):
     print("adding non existing document")
     with pytest.raises(sqlalchemy.exc.IntegrityError):
         TourController.add_document(1, 3)
 def test_update_tour_2(self):
     print("adding twice existing document")
     expected_response = {
         'extendedDocs': [{
             'id': 1,
             'title': None,
             'tour_id': 1,
             'doc_position': 1,
             'text2': None,
             'doc_id': 1,
             'document': {
                 'id': 1,
                 'comments': [],
                 'validationStatus': {
                     'status': Status.Validated,
                     'doc_id': 1
                 },
                 'user_id': 1,
                 'title': 'title',
                 'type': 'type',
                 'publicationDate': None,
                 'file': '1.gif',
                 'description': 'a description',
                 'subject': 'Subject1',
                 'originalName': None,
                 'refDate': None,
                 'visualization': {
                     'positionZ': None,
                     'id': 1,
                     'quaternionW': None,
                     'positionY': None,
                     'quaternionZ': None,
                     'quaternionX': None,
                     'positionX': None,
                     'quaternionY': None
                 },
             },
             'text1': None
         }, {
             'id': 2,
             'title': None,
             'tour_id': 1,
             'doc_position': 2,
             'text2': None,
             'doc_id': 1,
             'document': {
                 'id': 1,
                 'comments': [],
                 'validationStatus': {
                     'status': Status.Validated,
                     'doc_id': 1
                 },
                 'user_id': 1,
                 'title': 'title',
                 'type': 'type',
                 'publicationDate': None,
                 'file': '1.gif',
                 'description': 'a description',
                 'subject': 'Subject1',
                 'originalName': 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)
Example #20
0
def update_guided_tour_document(tour_id, doc_position):
    updated_tour = TourController.update_document(tour_id, doc_position,
                                                  request.form)
    return ResponseOK(updated_tour)
Example #21
0
def delete_guided_tour_document(tour_id, doc_position):
    updated_tour = TourController.remove_document(tour_id, doc_position)
    return ResponseOK(updated_tour)
Example #22
0
def update_guided_tour_document(tour_id):
    doc_position = int(request.form.get('doc_position'))
    return send_response(lambda: TourController.update_document(
        tour_id, doc_position, request.form))()
Example #23
0
def delete_tour(doc_id):
    return send_response(lambda: TourController.delete_tour(doc_id))()
Example #24
0
def get_guided_tour(tour_id):
    return send_response(lambda: TourController.get_tour_by_id(tour_id))()
 def test_create_tours_4(self):
     print("needed argument missing")
     with pytest.raises(IndexError):
         TourController.create_tour()
Example #26
0
def get_all_guided_tours():
    guided_tours = TourController.get_tours()
    return ResponseOK(guided_tours)
 def test_read_tours_1(self):
     print("all tours")
     expected_response = 3
     assert expected_response == len(TourController.get_tours())
Example #28
0
def update_guided_tour(tour_id):
    updated_tour = TourController.update(tour_id, request.form)
    return ResponseOK(updated_tour)
 def test_read_tours_3(self):
     print("tour with non existing id")
     with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
         TourController.get_tour_by_id(-1)
Example #30
0
def delete_tour(doc_id):
    deleted_tour = TourController.delete_tour(doc_id)
    return ResponseOK(deleted_tour)