Пример #1
0
    def test_delete_one_note(self):
        with app.app_context():
            try:
                sqlalchemy_orm.delete_note_and_related_data_from_db(3)
                # Check if result is empty
                note_result = sqlalchemy_orm.get_item_from_db(
                    Notes, {'note_id': 3})
                clauses_result = sqlalchemy_orm.get_item_from_db(
                    Clauses, {'note_id': 3})
                clausePoints_result = sqlalchemy_orm.get_item_from_db(
                    ClausePoints, {'note_id': 3})
                self.assertEqual(note_result, [])
                self.assertEqual(clauses_result, [])
                self.assertEqual(clausePoints_result, [])

            except sqlalchemy.exc.SQLAlchemyError:
                error_message = util.traceback_custom_error()
                error = custom_error.SQLAlchemyError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except AssertionError:
                error_message = util.traceback_custom_error()
                error = custom_error.AssertionError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except:
                error_message = util.traceback_custom_error()
                error = custom_error.UnExpectedError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
Пример #2
0
    def get(self, **args):
        try:
            for key, value in request.args.items():
                args[key] = value
        except HTTPException:
            error_message = util.traceback_custom_error()
            response = custom_error.HTTPRequestError(error_message).to_dict()
            return response, 400
        except:
            error_message = util.traceback_custom_error()
            response = custom_error.UnExpectedError(error_message).to_dict()
            return response, 500

        try:
            result = sqlalchemy_orm.get_item_from_db(
                sqlalchemy_orm.ClausePoints, args)
            if not result:
                raise custom_error.BadRequestError

        except sqlalchemy.exc.SQLAlchemyError:
            error_message = util.traceback_custom_error()
            response = custom_error.SQLAlchemyError(error_message).to_dict()
            return response, 500
        except custom_error.BadRequestError:
            response = custom_error.BadRequestError().to_dict()
            return response, 400
        except:
            error_message = util.traceback_custom_error()
            response = custom_error.UnExpectedError(error_message).to_dict()
            return response, 500
        else:
            return {'note_id': args['note_id'], 'clause_points': result}, 200
Пример #3
0
    def test_update_clauses(self):
        with app.app_context():
            try:
                sqlalchemy_orm.update_data_to_db(Clauses, {'note_id' : 1, 'clause_id' : 2}, {'title': '바뀐 제목', 'contents' : "바뀐 내용"})
                result = sqlalchemy_orm.get_item_from_db(Clauses, {'note_id' : 1, 'clause_id':2})
                result = result[0]
                self.assertEqual(result['title'], '바뀐 제목')
                self.assertEqual(result['contents'], '바뀐 내용')

            except sqlalchemy.exc.SQLAlchemyError:
                error_message = util.traceback_custom_error()
                error = custom_error.SQLAlchemyError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except AssertionError:
                error_message = util.traceback_custom_error()
                error = custom_error.AssertionError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except:
                error_message = util.traceback_custom_error()
                error = custom_error.UnExpectedError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
Пример #4
0
    def test_update_note_name(self):
        with app.app_context():
            try:
                sqlalchemy_orm.update_data_to_db(Notes, {'note_id' : 1}, {'note_name' : '새로운 노트 이름'})
                result = sqlalchemy_orm.get_item_from_db(Notes, {'note_id' : 1})
                result = result[0]
                self.assertEqual(result['note_name'], '새로운 노트 이름')

            except sqlalchemy.exc.SQLAlchemyError:
                error_message = util.traceback_custom_error()
                error = custom_error.SQLAlchemyError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except AssertionError:
                error_message = util.traceback_custom_error()
                error = custom_error.AssertionError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except:
                error_message = util.traceback_custom_error()
                error = custom_error.UnExpectedError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
Пример #5
0
    def test_update_clausePoints(self):
        with app.app_context():
            try:
                sqlalchemy_orm.update_data_to_db(ClausePoints, {'clause_id' : 3}, {'imp' : 1, 'und' : 2})
                result = sqlalchemy_orm.get_item_from_db(ClausePoints, {'clause_id' : 3})
                result = result[0]
                self.assertEqual(result['imp'], 1)
                self.assertEqual(result['und'], 2)

            except sqlalchemy.exc.SQLAlchemyError:
                error_message = util.traceback_custom_error()
                error = custom_error.SQLAlchemyError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except AssertionError:
                error_message = util.traceback_custom_error()
                error = custom_error.AssertionError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except:
                error_message = util.traceback_custom_error()
                error = custom_error.UnExpectedError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
Пример #6
0
    def test_select_clauses_by_note_id(self):
        with app.app_context():
            try:
                result = sqlalchemy_orm.get_item_from_db(
                    Clauses, {'note_id': 1})
                self.assertIsNotNone(result)
                self.assertIsInstance(result, list)
                self.assertNotEqual(len(result), 0)
                self.assertEqual(result[0]['note_id'], 1)

            except sqlalchemy.exc.SQLAlchemyError:
                error_message = util.traceback_custom_error()
                error = custom_error.SQLAlchemyError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except AssertionError:
                error_message = util.traceback_custom_error()
                error = custom_error.AssertionError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
            except:
                error_message = util.traceback_custom_error()
                error = custom_error.UnExpectedError(error_message)
                error.set_logger(logger)
                error.to_dict()
                raise
Пример #7
0
    def get(self, clause_id):
        if isinstance(clause_id, str):
            if not clause_id.isdigit():
                return custom_error.BadRequestError().to_dict(), 400
            clause_id = int(clause_id)

        if clause_id < 1:
            return custom_error.BadRequestError().to_dict(), 400

        try:
            result = sqlalchemy_orm.get_item_from_db(sqlalchemy_orm.Clauses,
                                                     {'clause_id': clause_id})
        except sqlalchemy.exc.SQLAlchemyError:
            error_message = util.traceback_custom_error()
            response = custom_error.SQLAlchemyError(error_message).to_dict()
            return response, 500
        except:
            error_message = util.traceback_custom_error()
            response = custom_error.UnExpectedError(error_message).to_dict()
            return response, 500
        if result:
            return {'clause': result}, 200
        return {'clause': []}, 201