Here are the examples of the python api mock.Request.get_json taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
10 Examples
3
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
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.remote_repo.Repository(self.conn, self.repo_name)
self.assertEqual(repo.status, self.repo_server_data['status'])
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)
def test_properties_fetch_error(self):
3
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
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.remote_repo.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)
def test_get_config_no_key_ok(self):
3
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
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.remote_repo.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)
def test_log_error(self):
0
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
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.remote_repo.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)
def test_get_config_error(self):
0
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
def test_pull(self):
exp_log = {
'fromCommit': '123',
'toCommit': '456'
}
self.conn.set_responses(
Response.with_json(status_code=200, json=exp_log )
)
repo = sap.rest.gcts.remote_repo.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), 1)
self.conn.execs[0].assertEqual(Request.get_json(uri=f'repository/{self.repo_name}/pullByCommit'), self)
def test_pull_error(self):
0
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
def test_set_url_change(self):
CALL_ID_FETCH_REPO_DATA = 0
CALL_ID_SET_URL = 1
NEW_URL = 'https://random.github.org/awesome/success'
self.conn.set_responses(
Response.with_json(status_code=200, json={'result': self.repo_server_data}),
Response.ok()
)
repo = sap.rest.gcts.remote_repo.Repository(self.conn, self.repo_name, data=None)
response = repo.set_url(NEW_URL)
self.conn.execs[CALL_ID_FETCH_REPO_DATA].assertEqual(
Request.get_json(uri=f'repository/{self.repo_name}'),
self
)
request_with_url = dict(self.repo_server_data)
request_with_url['url'] = NEW_URL
self.conn.execs[CALL_ID_SET_URL].assertEqual(
Request.post_json(
uri=f'repository/{self.repo_name}',
body=request_with_url
),
self
)
def test_set_url_nochange(self):
0
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
def test_set_url_nochange(self):
CALL_ID_FETCH_REPO_DATA = 0
NEW_URL = self.repo_server_data['url']
self.conn.set_responses(
Response.with_json(status_code=200, json={'result': self.repo_server_data}),
)
repo = sap.rest.gcts.remote_repo.Repository(self.conn, self.repo_name, data=None)
response = repo.set_url(NEW_URL)
self.conn.execs[CALL_ID_FETCH_REPO_DATA].assertEqual(
Request.get_json(uri=f'repository/{self.repo_name}'),
self
)
self.assertIsNone(response)
class TestgCTSSimpleAPI(GCTSTestSetUp, unittest.TestCase):
0
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
def test_simple_clone_without_params_create_exists_continue(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()
new_repo_data = dict(self.repo_server_data)
new_repo_data['status'] = 'CREATED'
self.conn.set_responses([
Response.with_json(status_code=500, json=messages),
Response.with_json(status_code=200, json={'result': new_repo_data}),
Response.ok()
])
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), 3)
self.conn.execs[CALL_ID_FETCH_REPO_DATA].assertEqual(Request.get_json(uri=f'repository/{self.repo_name}'), self)
def test_simple_clone_without_params_create_exists_continue_cloned(self):
0
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
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)
def test_simple_fetch_no_repo(self):
0
Source : test_sap_rest_gcts.py
with Apache License 2.0
from jfilak
with Apache License 2.0
from jfilak
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)
def test_simple_fetch_error(self):