Exemplo n.º 1
0
    def test_simple_clone_without_params_create_exists_continue_cloned(self):
        CALL_ID_FETCH_REPO_DATA = 1

        log_builder = LogBuilder()
        log_builder.log_error(
            make_gcts_log_error(
                '20200923111743: Error action CREATE_REPOSITORY Repository already exists'
            ))
        log_builder.log_exception('Cannot create', 'EEXIST').get_contents()
        messages = log_builder.get_contents()

        self.assertEqual(self.repo_server_data['status'], 'READY')

        self.conn.set_responses([
            Response.with_json(status_code=500, json=messages),
            Response.with_json(status_code=200,
                               json={'result': self.repo_server_data}),
        ])

        repo = sap.rest.gcts.simple_clone(self.conn,
                                          self.repo_url,
                                          self.repo_name,
                                          error_exists=False)
        self.assertIsNotNone(repo)

        self.assertEqual(len(self.conn.execs), 2)
        self.conn.execs[CALL_ID_FETCH_REPO_DATA].assertEqual(
            Request.get_json(uri=f'repository/{self.repo_name}'), self)
Exemplo n.º 2
0
    def test_get_config_no_key_ok(self):
        self.conn.set_responses(
            Response.with_json(status_code=200,
                               json={'result': {
                                   'value': 'the value'
                               }}))

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

        # This will fetch the configruation key value from the server
        value = repo.get_config('THE_KEY')
        self.assertEqual(value, 'the value')

        # The second request does not causes an HTTP request
        value = repo.get_config('THE_KEY')
        self.assertEqual(value, 'the value')

        # The update of keys did not break the cache
        value = repo.get_config('VCS_CONNECTION')
        self.assertEqual(value, 'SSL')

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(
            Request.get_json(
                uri=f'repository/{self.repo_name}/config/THE_KEY'), self)
Exemplo n.º 3
0
    def test_properties_fetch(self):
        response = {'result': self.repo_server_data}

        self.conn.set_responses(
            [Response.with_json(json=response, status_code=200)])

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

        self.assertEqual(repo.rid, self.repo_server_data['rid'])
        self.assertEqual(repo.url, self.repo_server_data['url'])
        self.assertEqual(repo.branch, self.repo_server_data['branch'])

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(
            Request.get_json(uri=f'repository/{self.repo_name}'), self)
Exemplo n.º 4
0
    def test_log_ok(self):
        exp_commits = [{'id': '123'}]

        self.conn.set_responses(
            Response.with_json(status_code=200, json={'commits': exp_commits}))

        repo = sap.rest.gcts.Repository(self.conn,
                                        self.repo_name,
                                        data=self.repo_server_data)
        act_commits = repo.log()

        self.assertIsNotNone(repo._data)
        self.assertEqual(act_commits, exp_commits)

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(
            Request.get_json(uri=f'repository/{self.repo_name}/getCommit'),
            self)
Exemplo n.º 5
0
    def test_get_config_no_config_ok(self):
        self.conn.set_responses(
            Response.with_json(status_code=200,
                               json={'result': self.repo_server_data}))

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

        # This will fetch repo data from the server
        value = repo.get_config('VCS_CONNECTION')
        self.assertEqual(value, 'SSL')

        # The second request does not causes an HTTP request
        value = repo.get_config('VCS_CONNECTION')
        self.assertEqual(value, 'SSL')

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(
            Request.get_json(uri=f'repository/{self.repo_name}'), self)
Exemplo n.º 6
0
    def test_pull_no_log_commits(self):
        exp_log = {'fromCommit': '123', 'toCommit': '456'}

        self.conn.set_responses(
            Response.with_json(status_code=200, json={'commits': []}),
            Response.with_json(status_code=200, json=exp_log))

        repo = sap.rest.gcts.Repository(self.conn,
                                        self.repo_name,
                                        data=self.repo_server_data)
        act_log = repo.pull()

        self.assertIsNone(repo._data)
        self.assertEqual(act_log, exp_log)

        self.assertEqual(len(self.conn.execs), 2)
        self.conn.execs[1].assertEqual(
            Request.get_json(uri=f'repository/{self.repo_name}/pullByCommit'),
            self)
Exemplo n.º 7
0
    def test_simple_fetch_ok(self):
        REPO_ONE_ID = 0
        repo_one = dict(self.repo_server_data)
        repo_one['name'] = repo_one['rid'] = 'one'

        REPO_TWO_ID = 1
        repo_two = dict(self.repo_server_data)
        repo_two['name'] = repo_two['rid'] = 'two'

        self.conn.set_responses(
            Response.with_json(status_code=200,
                               json={'result': [repo_one, repo_two]}))

        repos = sap.rest.gcts.simple_fetch_repos(self.conn)

        self.assertEqual(len(repos), 2)
        self.assertEqual(repos[REPO_ONE_ID].name, 'one')
        self.assertEqual(repos[REPO_TWO_ID].name, 'two')

        self.assertEqual(len(self.conn.execs), 1)
        self.conn.execs[0].assertEqual(Request.get_json(uri=f'repository'),
                                       self)