Пример #1
0
    def test_simple_clone_success(self):
        CALL_ID_CREATE = 0
        CALL_ID_CLONE = 1

        repository = dict(self.repo_server_data)
        repository['status'] = 'CREATED'

        self.conn.set_responses(
            Response.with_json(status_code=201,
                               json={'repository': repository}), Response.ok())

        sap.rest.gcts.simple_clone(self.conn,
                                   self.repo_url,
                                   self.repo_name,
                                   vcs_token='THE_TOKEN')

        data = dict(self.repo_data)
        data['config'] = [{
            'key': 'VCS_TARGET_DIR',
            'value': 'src/'
        }, {
            'key': 'CLIENT_VCS_AUTH_TOKEN',
            'value': 'THE_TOKEN'
        }]

        request_load = {'repository': self.repo_name, 'data': data}

        self.assertEqual(len(self.conn.execs), 2)

        self.conn.execs[CALL_ID_CREATE].assertEqual(Request.post_json(
            uri='repository', body=request_load, accept='application/json'),
                                                    self,
                                                    json_body=True)
        self.conn.execs[CALL_ID_CLONE].assertEqual(
            Request.post(uri=f'repository/{self.repo_name}/clone'), self)
Пример #2
0
    def test_commit_transport_full(self):
        repo_name = 'the_repo'
        corrnr = 'CORRNR'
        message = 'Message'
        description = 'Description'

        commit_cmd = self.commit_cmd(repo_name, corrnr, '-m', message,
                                     '--description', description)
        commit_cmd.execute(self.fake_connection, commit_cmd)

        self.fake_connection.execs[0].assertEqual(
            Request.post_json(uri=f'repository/{repo_name}/commit',
                              body={
                                  'message':
                                  message,
                                  'autoPush':
                                  'true',
                                  'objects': [{
                                      'object': corrnr,
                                      'type': 'TRANSPORT'
                                  }],
                                  'description':
                                  description
                              }), self)

        self.assertConsoleContents(
            self.console,
            stdout=f'''The transport "{corrnr}" has been committed\n''')
Пример #3
0
    def test_set_config_success(self):
        repo = sap.rest.gcts.Repository(self.conn, self.repo_name)
        repo.set_config('THE_KEY', 'the value')
        self.assertEqual(repo.get_config('THE_KEY'), 'the value')

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(Request.post_json(
            uri=f'repository/{self.repo_name}/config',
            body={
                'key': 'THE_KEY',
                'value': 'the value'
            }),
                                       self,
                                       json_body=True)
Пример #4
0
    def test_create_no_self_data_no_config(self):
        self.conn.set_responses(
            Response.with_json(status_code=201,
                               json={'repository': self.repo_server_data}))

        repo = sap.rest.gcts.Repository(self.conn, self.repo_name)
        repo.create(self.repo_url, self.repo_vsid)

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(Request.post_json(
            uri=f'repository',
            body=self.repo_request,
            accept='application/json'),
                                       self,
                                       json_body=True)
Пример #5
0
    def test_set_config_success_overwrite(self):
        repo = sap.rest.gcts.Repository(self.conn,
                                        self.repo_name,
                                        data=self.repo_server_data)
        repo.set_config('VCS_CONNECTION', 'git')
        self.assertEqual(repo.get_config('VCS_CONNECTION'), 'git')

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(Request.post_json(
            uri=f'repository/{self.repo_name}/config',
            body={
                'key': 'VCS_CONNECTION',
                'value': 'git'
            }),
                                       self,
                                       json_body=True)
Пример #6
0
    def test_create_with_config_update_instance(self):
        self.conn.set_responses(
            Response.with_json(status_code=201,
                               json={'repository': self.repo_server_data}))

        repo = sap.rest.gcts.Repository(self.conn,
                                        self.repo_name,
                                        data={
                                            'config': [{
                                                'key': 'first_key',
                                                'value': 'first_value'
                                            }, {
                                                'key': 'third_key',
                                                'value': 'third_value'
                                            }]
                                        })

        repo.create(self.repo_url,
                    self.repo_vsid,
                    config={
                        'second_key': 'second_value',
                        'third_key': 'fourth_value'
                    })

        repo_request = dict(self.repo_request)
        repo_request['data']['config'] = [
            {
                'key': 'first_key',
                'value': 'first_value'
            },
            {
                'key': 'third_key',
                'value': 'fourth_value'
            },
            {
                'key': 'second_key',
                'value': 'second_value'
            },
        ]

        self.maxDiff = None
        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(Request.post_json(
            uri=f'repository', body=repo_request, accept='application/json'),
                                       self,
                                       json_body=True)
Пример #7
0
    def test_create_with_role_and_type(self):
        self.conn.set_responses(
            Response.with_json(status_code=201,
                               json={'repository': self.repo_server_data}))

        repo = sap.rest.gcts.Repository(self.conn, self.repo_name)

        repo.create(self.repo_url, self.repo_vsid, role='TARGET', typ='GIT')

        repo_request = dict(self.repo_request)
        repo_request['data']['role'] = 'TARGET'
        repo_request['data']['type'] = 'GIT'

        self.maxDiff = None
        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(Request.post_json(
            uri=f'repository', body=repo_request, accept='application/json'),
                                       self,
                                       json_body=True)
Пример #8
0
    def test_create_with_config_instance_none(self):
        self.conn.set_responses(
            Response.with_json(status_code=201,
                               json={'repository': self.repo_server_data}))

        repo = sap.rest.gcts.Repository(self.conn, self.repo_name)
        repo.create(self.repo_url,
                    self.repo_vsid,
                    config={'THE_KEY': 'THE_VALUE'})

        repo_request = dict(self.repo_request)
        repo_request['data']['config'] = [{
            'key': 'THE_KEY',
            'value': 'THE_VALUE'
        }]

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(Request.post_json(
            uri=f'repository', body=repo_request, accept='application/json'),
                                       self,
                                       json_body=True)