def update_score_build(self, job, build): if self.is_connected() is False: return False for culprit in self.jenkins.get_culprits(build): username = culprit["fullName"] user = User.objects(name=username).first() if user is None: user = User(name=username) user.save() user_score = user.score total_bonus = self.jenkins.get_bonus_per_build(job) if total_bonus > 5: total_bonus = 5 points = total_bonus + 1 if build.is_running(): return False else: if build.get_status() == 'FAILURE': user_score += points * -5 elif build.get_status() == 'SUCCESS': user_score += points logging.log( logging.DEBUG, user.name + " " + str(user.score) + " " + str(user_score)) user.update(set__score=user_score) user.reload() return True
def update_score_build(self, job, build): if self.is_connected() is False: return False for culprit in self.jenkins.get_culprits(build): username = culprit["fullName"] user = User.objects(name=username).first() if user is None: user = User(name=username) user.save() user_score = user.score total_bonus = self.jenkins.get_bonus_per_build(job) if total_bonus > 5: total_bonus = 5 points = total_bonus + 1 if build.is_running(): return False else: if build.get_status() == 'FAILURE': user_score += points * -5 elif build.get_status() == 'SUCCESS': user_score += points logging.log(logging.DEBUG, user.name + " " + str(user.score) + " " + str(user_score)) user.update(set__score=user_score) user.reload() return True
def setUp(self): self.funnycats = FunnyCats(self.jenkins, "Score", "funnycats_tests") self.funnycats.connect_db() self.funnycats.clear_db() self.user1 = User() self.user1.name = "User1" self.user1.score = 3 self.user1.save() self.user2 = User() self.user2.name = "User2" self.user2.score = 10 self.user2.save() self.user3 = User() self.user3.name = "User3" self.user3.score = 9 self.user3.save()
class TestsUser(unittest.TestCase): @classmethod def setUpClass(cls): cls.jenkins = mock.Mock() def setUp(self): self.funnycats = FunnyCats(self.jenkins, "Score", "funnycats_tests") self.funnycats.connect_db() self.funnycats.clear_db() self.user1 = User() self.user1.name = "User1" self.user1.score = 3 self.user1.save() self.user2 = User() self.user2.name = "User2" self.user2.score = 10 self.user2.save() self.user3 = User() self.user3.name = "User3" self.user3.score = 9 self.user3.save() def tearDown(self): self.funnycats.disconnect_db() def test_get_user_list_score(self): users = get_user_list_score() self.assertTrue(3, len(users)) self.assertEquals(self.user2.name, users[0]["name"]) self.assertEquals(self.user3.name, users[1]["name"]) self.assertEquals(self.user1.name, users[2]["name"])
def insert_users_from_server(self): for user in self.jenkins.get_user_list(): users = User.objects(name=user["name"]) if users.count() == 0: new_user = User(name=user["name"]) new_user.save()
def clear_db(self): if self.is_connected(): User.drop_collection() ScoreJob.drop_collection() Config.drop_collection()