Beispiel #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)
Beispiel #2
0
class BaseTestCase(TestCase):
    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

    def create_app(self):
        app = create_app()
        app.config.from_object("gitlab.config.TestingConfig")
        return app

    def tearDown(self):
        self.db.drop_database('api')
Beispiel #3
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)
Beispiel #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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
class TestGeneralInformationPipeline(BaseTestCase):

    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)

    def test_create_general_information_pipeline(self):
        general_info_db = GeneralInformationPipelines.objects(
            project=self.project).first()
        self.assertEqual(self.general_information_pipeline, general_info_db)

    def get_test_general_information_pipeline(self):
        general_info = GeneralInformationPipelines.\
            get_general_information_pipeline(self.project)
        self.assertEqual(self.general_information_pipeline, general_info)

    def test_add_pipeline_fail(self):
        current_pipeline = CurrentPipeline()
        name = "Test current2"
        pipeline_jobs = [{"duration": 9.8,
                          'date': '03/04/2019',
                          'name': 'nome',
                          'stage': 'flake8',
                          'status': False,
                          'web_url': 'http://teste.com'}]
        current_pipeline.create_current_pipeline(name,
                                                 pipeline_jobs, self.project)

        self.general_information_pipeline.add_pipeline(current_pipeline,
                                                       self.project)
        general_info = GeneralInformationPipelines.\
            get_general_information_pipeline(self.project)
        self.assertEqual(self.number_of_pipelines + 1,
                         general_info.number_of_pipelines)
        self.assertEqual(self.successful_pipelines,
                         general_info.successful_pipelines)

    def test_add_pipeline_sucess(self):
        current_pipeline = CurrentPipeline()
        name = "Test current"
        pipeline_jobs = [{'duration': 9.8,
                          'date': '03/04/2019',
                          'name': 'nome',
                          'stage': 'flake8',
                          'status': True,
                          'web_url': 'http://teste.com'}]
        current_pipeline.create_current_pipeline(name,
                                                 pipeline_jobs, self.project)

        self.general_information_pipeline.add_pipeline(current_pipeline,
                                                       self.project)
        general_info = GeneralInformationPipelines.\
            get_general_information_pipeline(self.project)
        self.assertEqual(self.number_of_pipelines + 1,
                         general_info.number_of_pipelines)
        self.assertEqual(self.successful_pipelines + 1,
                         general_info.successful_pipelines)