示例#1
0
    def test_get_current_pipeline(self):
        CurrentPipeline.drop_collection()
        Project.drop_collection()
        User.drop_collection()

        user = User()
        user.username = "******"
        user.save()

        project = Project()
        project.user_id = user.id
        project.description = "Test project current pipeline"
        project.name = "Test project current pipeline"
        project.web_url = "https://currentpipeline.com"
        project.branches = ["branch1", "branch2"]
        project.save()

        currentpipeline = CurrentPipeline()
        currentpipeline.project = project
        currentpipeline.name = "Test current"
        currentpipeline.pipeline_jobs = [{"Teste": "Testando"}]
        currentpipeline.save()

        generalinfo = GeneralInformationPipelines()
        generalinfo.project = project
        generalinfo.number_of_pipelines = 10
        generalinfo.successful_pipelines = 5
        generalinfo.save()

        pipelines_in_db = CurrentPipeline.get_current_pipeline(project)
        for pipeline in pipelines_in_db:
            self.assertEqual(currentpipeline, pipeline)
示例#2
0
    def test_create_current_pipeline(self):
        CurrentPipeline.drop_collection()
        Project.drop_collection()
        User.drop_collection()

        user = User()
        user.username = "******"
        user.save()

        project = Project()
        project.user_id = user.id
        project.description = "Test project current pipeline"
        project.name = "Test project current pipeline"
        project.web_url = "https://currentpipeline.com"
        project.branches = ["branch1", "branch2"]
        project.save()

        current_pipeline = CurrentPipeline()
        name = "Test current"
        pipeline_jobs = [{"Teste": "Testando"}]
        current_pipeline.create_current_pipeline(name, pipeline_jobs, project)

        current_pipeline2 = CurrentPipeline.objects(name=name).first()

        self.assertEqual(current_pipeline, current_pipeline2)
示例#3
0
    def test_create_user(self):
        User.drop_collection()
        user = User()
        username = "******"
        user.create_user(username)

        user2 = User.objects(username=username).first()
        self.assertEqual(user, user2)
示例#4
0
    def test_save_gitlab_user_data(self):
        gitlab_user = '******'
        chat_id = 'id'
        gitlab_user_id = 'git_id'
        username = '******'
        user = User()
        user.username = username
        user.save()
        user.save_gitlab_user_data(gitlab_user, chat_id, gitlab_user_id)

        user_db = User.objects(username=username).first()
        self.assertEqual(user, user_db)
示例#5
0
 def register_user(self, user_data):
     user = User()
     gitlab_user = user_data["gitlab_user"]
     chat_id = user_data["chat_id"]
     gitlab_user_id = user_data["gitlab_user_id"]
     existing_user = User.objects(chat_id=chat_id).first()
     if existing_user:
         dict_error = {
             "message":
             "Eu vi aqui que você já cadastrou o usuário "
             "do GitLab. Sinto muitos, mas no momento não "
             "é possível cadastrar um novo usuário do GitLab "
             "ou alterá-lo."
         }
         raise HTTPError(json.dumps(dict_error))
     user.save_gitlab_user_data(gitlab_user, chat_id, gitlab_user_id)
示例#6
0
def get_access_token():
    code = request.args.get('code')
    chat_id = request.args.get('state')
    send_message(ACCESS_TOKEN, chat_id)
    existing_user = User.objects(chat_id=chat_id).first()
    if not existing_user:
        GITLAB_TOKEN = authenticate_access_token(code)
        db_user = User()
        db_user.access_token = GITLAB_TOKEN
        db_user.chat_id = str(chat_id)
        db_user.save()
        user = UserUtils(chat_id)
        user_infos = user.get_own_user_data()
        db_user.gitlab_user = user_infos["gitlab_username"]
        db_user.gitlab_user_id = str(user_infos["gitlab_user_id"])
        db_user.save()
        user.send_button_message(user_infos, chat_id)
    redirect_uri = "https://t.me/{bot_name}".format(bot_name=BOT_NAME)
    return redirect(redirect_uri, code=302)
示例#7
0
    def test_save_gitlab_repo_data(self):
        User.drop_collection()
        user = User()
        username = "******"
        user.create_user(username)
        user.save()

        Project.drop_collection()
        project = Project()
        project.user_id = user.id
        project.description = "Test user add project"
        project.name = "Test user add project"
        project.web_url = "https://useraddProject.com"
        project.branches = ["branch1", "branch2"]
        project.save()

        user.save_gitlab_repo_data(project)

        project_user = User.objects(project=project).first()
        self.assertEqual(user, project_user)
示例#8
0
    def setUp(self):
        self.db = init_db()
        self.user = User()
        self.user.username = '******'
        self.user.chat_id = '339847919'
        self.user.gitlab_user = '******'
        self.user.gitlab_user_id = '4047441'
        self.user.access_token = "123456"
        self.user.save()
        self.project = Project()
        self.project_name = 'ada-gitlab'
        self.project_id = '12532279'
        self.project.save_webhook_infos(self.user, self.project_name,
                                        self.project_id)
        self.user.save_gitlab_repo_data(self.project)
        self.GITLAB_API_TOKEN = "12345"

        self.mocked_404_response = Response()
        self.mocked_404_response.status_code = 404
        self.response_unauthorized = Response()
        self.response_unauthorized.status_code = 401
示例#9
0
    def setUp(self):
        super().setUp()
        GeneralInformationPipelines.drop_collection()
        Project.drop_collection()
        self.user = User()
        self.user.username = "******"
        self.user.save()

        self.project = Project()
        self.project.user_id = self.user.id
        self.project.description = "Test project current pipeline"
        self.project.name = "Test project current pipeline"
        self.project.web_url = "https://currentpipeline.com"
        self.project.branches = ["branch1", "branch2"]
        self.project.save()

        self.general_information_pipeline = GeneralInformationPipelines()
        self.number_of_pipelines = 10
        self.successful_pipelines = 5
        self.general_information_pipeline.create_general_information_pipeline(
            self.project, self.number_of_pipelines, self.successful_pipelines)