コード例 #1
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testNoRoute(self, mock_req):
    ctx = context.Context('foo.corn', 'foo', 1)
    ctx.ExecuteRequest('GET')

    mock_req.assert_called_once_with(
        'GET', 'https://foo.corn/api/bit9platform/v1', headers=mock.ANY,
        json=None, verify=mock.ANY, timeout=mock.ANY)
コード例 #2
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testEmptyResponse(self, mock_req):
    mock_req.return_value = test_utils.GetTestResponse(status_code=httplib.OK)
    mock_req.return_value.text = None

    ctx = context.Context('foo.corn', 'foo', 1)
    with self.assertRaises(excs.RequestError):
      ctx.ExecuteRequest('GET')
コード例 #3
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testWithPath(self, mock_req):
    ctx = context.Context('foo.corn/other/path', 'foo', 1)
    ctx.ExecuteRequest('GET', api_route='abc')

    mock_req.assert_called_once_with(
        'GET', 'https://foo.corn/other/path/api/bit9platform/v1/abc',
        headers=mock.ANY, json=None, verify=mock.ANY, timeout=mock.ANY)
コード例 #4
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testFailedJsonParse(self, mock_req):
    mock_req.return_value = test_utils.GetTestResponse()
    mock_req.return_value.text = '{"Invalid": "JSON}'

    ctx = context.Context('foo.corn', 'foo', 1)
    with self.assertRaises(excs.RequestError):
      ctx.ExecuteRequest('GET')
コード例 #5
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testNotFound(self, mock_req):
    mock_req.return_value = test_utils.GetTestResponse(
        status_code=httplib.NOT_FOUND)

    ctx = context.Context('foo.corn', 'foo', 1)
    with self.assertRaises(excs.NotFoundError):
      ctx.ExecuteRequest('GET')
コード例 #6
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testServerError(self, mock_req):
    mock_req.return_value = test_utils.GetTestResponse(
        status_code=httplib.INTERNAL_SERVER_ERROR)

    ctx = context.Context('foo.corn', 'foo', 1)
    with self.assertRaises(excs.RequestError):
      ctx.ExecuteRequest('GET')
コード例 #7
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testClientError(self, mock_req):
    mock_req.return_value = test_utils.GetTestResponse(
        status_code=httplib.BAD_REQUEST)

    ctx = context.Context('foo.corn', 'foo', 1)
    with self.assertRaises(excs.RequestError):
      ctx.ExecuteRequest('GET')
コード例 #8
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testHeaders(self, mock_req):
    ctx = context.Context('foo.corn', 'foo', 1)
    ctx.ExecuteRequest('GET')

    expected_headers = {
        'X-Auth-Token': 'foo',
        'Content-Type': 'application/json'}
    mock_req.assert_called_once_with(
        'GET', mock.ANY, headers=expected_headers, json=None, verify=True,
        timeout=1)
コード例 #9
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testBadTimeout(self, _):
    with self.assertRaises(ValueError):
      context.Context('foo.corn', 'foo', -1, version='v2')

    with self.assertRaises(ValueError):
      context.Context('foo.corn', 'foo', 'foo', version='v2')
コード例 #10
0
ファイル: context_test.py プロジェクト: crudbug/upvote
 def testBadVersion(self, _):
   with self.assertRaises(ValueError):
     context.Context('foo.corn', 'foo', 1, version='v2')
コード例 #11
0
ファイル: context_test.py プロジェクト: crudbug/upvote
  def testRequestError(self, mock_req):
    mock_req.side_effect = requests.RequestException

    ctx = context.Context('foo.corn', 'foo', 1)
    with self.assertRaises(excs.RequestError):
      ctx.ExecuteRequest('GET')
コード例 #12
0
    foo = model.StringProperty('foo', allow_update=True, expands_to='AModel')
    bar = model.Int32Property('bar')
    baz = model.StringProperty('baz', allow_update=True, expands_to='AModel')


class OtherTestModel(model.Model):
    ROUTE = 'efgh'

    foo = model.StringProperty('foo',
                               allow_update=True,
                               expands_to='TestModel')
    bar = model.Int32Property('bar')


_TEST_URL = 'https://foo.corn'
_TEST_CTX = context.Context(_TEST_URL, 'abc', 123)
_TEST_API_ADDR = _TEST_URL + '/api/bit9platform/v1/'


class MetaModelTest(absltest.TestCase):
    def testSetPropModelCls(self):
        self.assertEqual('TestModel', TestModel.foo.model_cls_name)
        self.assertEqual('TestModel', TestModel.bar.model_cls_name)

    def testNoRouteProvided(self):
        with self.assertRaises(excs.Error):

            class OtherModel(model.Model):  # pylint: disable=unused-variable
                pass

    def testKindMap(self):