Пример #1
0
 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
Пример #2
0
 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
Пример #3
0
 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
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
 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
Пример #8
0
 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
Пример #9
0
 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
Пример #10
0
 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
Пример #11
0
 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
Пример #12
0
 def test_db_exception_ko(self):
     result = DBException(MSG_UPDATE_NOT_FOUND)
     self.assertNotEqual(result.status_code, CODE_GET_OK)
Пример #13
0
 def test_db_exception_message_ko(self):
     result = DBException(MSG_GET_NOT_FOUND)
     self.assertNotEqual(result.message, MSG_GET_NOT_FOUND)
Пример #14
0
 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
Пример #15
0
 def test_db_exception_ok(self):
     result = DBException(MSG_GET_NOT_FOUND)
     self.assertEqual(result.status_code, CODE_DB_ERROR)
Пример #16
0
 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
Пример #17
0
 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
Пример #18
0
 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
Пример #19
0
 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
Пример #20
0
 def test_db_exception_message_ok(self):
     result = DBException(MSG_GET_NOT_FOUND)
     self.assertEqual(result.message, "DB error: %s" % MSG_GET_NOT_FOUND)
Пример #21
0
 def delete_user_all(cls, db_connection):
     try:
         requirement = db_connection.users.delete_many({})
     except Exception as e:
         raise DBException(e.message)
     return requirement