def get_user(cls, database, username): user=None try: user = database.users.find_one({'username': username}) except Exception as e: raise DBException(e.message) return user
def insert_requirement(cls, database, data): try: requirement = database.Requirements.insert_one(data) except NetworkTimeout as e: raise except Exception as e: raise DBException(e.message) return requirement
def insert_comment(cls, database, data): try: comment = database.comments.insert_one(data) except NetworkTimeout as e: raise except Exception as e: raise DBException(e.message) return comment
def get_requirement(cls, database, requirement_id): try: requirement = database.Requirements.find_one({'strid': requirement_id}) except Exception as e: raise DBException(e.message) if requirement is None: raise EpepinException(CODE_DB_NOT_FOUND_ERROR, MSG_GET_NOT_FOUND) return requirement
def connection(self): try: client = MongoClient(self.endpoint, self.port, serverSelectionTimeoutMS=2000) db = client.Requirement except Exception as e: DBException(e.message) current_app.logger.info('..Database.connection...' + str(db)) return db
def update_requirement(cls, database, requirement_id, data): try: requirement = database.Requirements.update_one({'_id':ObjectId(requirement_id)}, {'$set': data}) except Exception as e: raise DBException(e.message) if not requirement.raw_result["updatedExisting"]: raise EpepinException(CODE_DB_NOT_FOUND_ERROR, MSG_UPDATE_NOT_FOUND) return requirement
def insert_color(cls, database, data): try: color = database.colors.find_one({"strid": data.getID()}) if (color is None): color = database.colors.insert_one(data.toJSON()) except NetworkTimeout as e: raise except Exception as e: raise DBException(e.message) return color
def insert_jenkins_tc(cls, db_connection, data): try: jenkins_tc = db_connection.jenkins_tc.insert_one(data) except DuplicateKeyError: jenkins_tc=None pass except NetworkTimeout as e: raise except Exception as e: raise DBException(e.message) return jenkins_tc
def insert_user(cls, db_connection, data): try: user = cls.get_user(db_connection,data['username']) if user is None: user = db_connection.users.insert_one(data) except DuplicateKeyError: user=None pass except NetworkTimeout as e: raise except Exception as e: raise DBException(e.message) return user
def updateReviewer(cls, db_connection, requirement_id, user,action): try: requirement = db_connection.reviewers.find_one({'req': requirement_id}) pos_user=requirement['reviewers'].index(user) requirement['actions'][pos_user]=action db_connection.reviewers.update_one({'_id':requirement['_id']}, {"$set": requirement}, upsert=False) except DuplicateKeyError: requirement=None pass except NetworkTimeout as e: raise except Exception as e: raise DBException(e.message) return requirement
def setReviewers(cls, db_connection, requirements, users): try: actions = [None] * len(users) for s in requirements: db_connection.reviewers.delete_one({'req':s}) jenkins_tc = db_connection.reviewers.insert_one({'req':s,'reviewers':users,'actions':actions}) except DuplicateKeyError: jenkins_tc=None pass except NetworkTimeout as e: raise except Exception as e: raise DBException(e.message) return jenkins_tc
def test_db_exception_ko(self): result = DBException(MSG_UPDATE_NOT_FOUND) self.assertNotEqual(result.status_code, CODE_GET_OK)
def test_db_exception_message_ko(self): result = DBException(MSG_GET_NOT_FOUND) self.assertNotEqual(result.message, MSG_GET_NOT_FOUND)
def get_color(cls, database, item_id): try: color = database.colors.find_one({'strid': item_id}) except Exception as e: raise DBException(e.message) return color
def test_db_exception_ok(self): result = DBException(MSG_GET_NOT_FOUND) self.assertEqual(result.status_code, CODE_DB_ERROR)
def delete_requirement(cls, database, requirement_id): try: requirement = database.Requirements.delete_one({'_id': ObjectId(requirement_id)}) except Exception as e: raise DBException(e.message) return requirement
def get_jenkins_tc(cls, db_connection,jenkins_tc_id): try: element = db_connection.jenkins_tc.find_one({'strid': jenkins_tc_id}) except Exception as e: raise DBException(e.message) return element
def delete_jenkins_tc(cls, db_connection, jenkins_tc_id): try: jenkins_tc = db_connection.jenkins_tc.delete_one({'strid': jenkins_tc_id}) except Exception as e: raise DBException(e.message) return jenkins_tc
def delete_jenkins_tc_all(cls, db_connection): try: jenkins_tc = db_connection.jenkins_tc.delete_many({}) except Exception as e: raise DBException(e.message) return jenkins_tc
def test_db_exception_message_ok(self): result = DBException(MSG_GET_NOT_FOUND) self.assertEqual(result.message, "DB error: %s" % MSG_GET_NOT_FOUND)
def delete_user_all(cls, db_connection): try: requirement = db_connection.users.delete_many({}) except Exception as e: raise DBException(e.message) return requirement