示例#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)
示例#2
0
    def test_simple_fetch_error(self):
        messages = LogBuilder(exception='Fetch Error').get_contents()
        self.conn.set_responses(
            Response.with_json(status_code=500, json=messages))

        with self.assertRaises(sap.rest.gcts.GCTSRequestError) as caught:
            sap.rest.gcts.simple_fetch_repos(self.conn)

        self.assertEqual(str(caught.exception), 'gCTS exception: Fetch Error')
示例#3
0
    def test_str_and_repr(self):
        log_builder = LogBuilder()
        messages = log_builder.log_error(
            make_gcts_log_error('Exists')).log_exception(
                'Message', 'EEXIST').get_contents()
        ex = sap.rest.gcts.GCTSRequestError(messages)

        self.assertEqual(str(ex), 'gCTS exception: Message')
        self.assertEqual(repr(ex), 'gCTS exception: Message')
示例#4
0
    def test_properties_fetch_error(self):
        messages = LogBuilder(exception='Get Repo Error').get_contents()
        self.conn.set_responses(
            Response.with_json(status_code=500, json=messages))

        repo = sap.rest.gcts.Repository(self.conn, self.repo_name)
        with self.assertRaises(sap.rest.gcts.GCTSRequestError) as caught:
            unused = repo.rid

        self.assertEqual(str(caught.exception),
                         'gCTS exception: Get Repo Error')
示例#5
0
    def test_set_config_error(self):
        messages = LogBuilder(exception='Set Config Error').get_contents()

        self.conn.set_responses(
            Response.with_json(status_code=500, json=messages))
        repo = sap.rest.gcts.Repository(self.conn, self.repo_name)

        with self.assertRaises(sap.rest.gcts.GCTSRequestError) as caught:
            repo.set_config('THE_KEY', 'the value')

        self.assertEqual(str(caught.exception),
                         'gCTS exception: Set Config Error')
示例#6
0
    def test_log_error(self):
        messages = LogBuilder(exception='Log Error').get_contents()
        self.conn.set_responses(
            Response.with_json(status_code=500, json=messages))

        repo = sap.rest.gcts.Repository(self.conn,
                                        self.repo_name,
                                        data=self.repo_server_data)
        with self.assertRaises(sap.rest.gcts.GCTSRequestError) as caught:
            repo.log()

        self.assertIsNotNone(repo._data)
        self.assertEqual(str(caught.exception), 'gCTS exception: Log Error')
示例#7
0
    def test_simple_clone_without_params_create_fail(self):
        log_builder = LogBuilder()
        messages = log_builder.log_error(
            make_gcts_log_error('Failure')).log_exception(
                'Message', 'EERROR').get_contents()

        self.conn.set_responses(
            [Response.with_json(status_code=500, json=messages)])

        with self.assertRaises(sap.rest.gcts.GCTSRequestError) as caught:
            sap.rest.gcts.simple_clone(self.conn, self.repo_url,
                                       self.repo_name)

        self.assertEqual(str(caught.exception), 'gCTS exception: Message')
示例#8
0
    def test_simple_clone_without_params_create_exists(self):
        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.conn.set_responses(
            [Response.with_json(status_code=500, json=messages)])

        with self.assertRaises(
                sap.rest.gcts.GCTSRepoAlreadyExistsError) as caught:
            sap.rest.gcts.simple_clone(self.conn, self.repo_url,
                                       self.repo_name)

        self.assertEqual(str(caught.exception),
                         'gCTS exception: Cannot create')