Exemplo n.º 1
0
def test_lambda_no_tasks(mocker, sns_topic):
    mocker.patch('handler.EcsCluster')
    mocker.patch('handler.logger')
    mocker.patch('handler.Instance')
    mocker.patch('handler.AutoScalingGroup')
    mocker.patch('handler.time.sleep')

    mock_node = mocker.Mock()
    mock_node.drain.side_effect = exc.EcsError('foobar')
    mock_node.__getitem__ = lambda x, y: 0

    mock_cluster = mocker.Mock()
    mock_cluster.get_node.return_value = mock_node

    mock_asg = mocker.Mock()
    handler.AutoScalingGroup.return_value = mock_asg

    handler.EcsCluster.return_value = mock_cluster

    resp = handler.run(fixtures.termination_message_json, sns_topic)

    assert resp == 'ok'
    handler.time.sleep.assert_not_called()
    mock_asg.terminate.assert_called_once_with(
        '86799385-e46d-40b9-a393-6ff3da981d7e',
        'testing-ASGTerminateHook-11414UVQ4RWSR')
Exemplo n.º 2
0
def test_run_not_cluster_node(mocker, sns_topic):
    mocker.patch('handler.EcsCluster')
    mocker.patch('handler.logger')
    mocker.patch('handler.Instance')

    mock = mocker.Mock()
    mock.is_ecs_cluster_node = False
    handler.Instance.return_value = mock

    resp = handler.run(fixtures.termination_message_json, sns_topic)

    assert resp == "error"
    handler.logger.error.assert_called_once()
    assert not handler.EcsCluster.called
Exemplo n.º 3
0
def test_run_has_daemon_tasks(mocker, sns_topic):
    mocker.patch('handler.EcsCluster')
    mocker.patch('handler.logger')
    mocker.patch('handler.Instance')
    mocker.patch('handler.AutoScalingGroup')
    mocker.patch('handler.time.sleep')

    mock_node = mocker.Mock()
    mock_node.drain.side_effect = exc.EcsError('foobar')
    mock_node.__getitem__ = lambda x, y: 1

    mock_cluster = mocker.Mock()
    mock_cluster.get_node.return_value = mock_node
    mock_cluster.only_daemon_tasks_remaining.return_value = True

    handler.EcsCluster.return_value = mock_cluster

    resp = handler.run(fixtures.termination_message_json, sns_topic)

    assert resp == 'ok'
    handler.time.sleep.assert_called_once()
    mock_cluster.stop_daemon_tasks.assert_called_once()
    sns_topic.publish.assert_called_once()
    assert handler.AutoScalingGroup.call_count is 0
Exemplo n.º 4
0
import simplejson

# our modules
import handler

class WriteShapes(handler.Handler):

  def post(self):
    shapes = simplejson.loads(self.request.body)
    updated = []
    for verse_name, shape in shapes.iteritems():
      verse = self.scrollsDS.GetVerse(verse_name)
      if not verse:
        self.WriteJsonError("can't get verse %s" % verse_name)
        #return
      else:
        if int(shape['c']) != verse.columns[0]:
          if int(shape['c']) == verse.chapter:
            self.WriteJsonError("verse c==chapter %s %s %s" % (
                verse_name, shape['c'], verse.columns[0]))
          else:
            self.WriteJsonError("mismatch column for verse %s %s %s" % (
                verse_name, shape['c'], verse.columns[0]))
        verse.shape = simplejson.dumps(shape)
        updated.append(verse)
    self.scrollsDS.UpdateVerses(updated)


if __name__ == '__main__':
  handler.run([('/api/write_shapes', WriteShapes)], debug=True)
Exemplo n.º 5
0
  q = xapian.Query(xapian.Query.OP_OR, l)

  enquire.set_query(q)
  matches = enquire.get_mset(0, 100)

  print '%i results found.' % matches.get_matches_estimated()
  print 'Result - %i:' % matches.size()

  r = []
  for m in matches:
    # print '%i: %i%% docid=%i [%s]' % (m.rank + 1, m.percent, m.docid,\
    # m.document.get_data())
    r.append(m.document.get_data())

  print json.dumps(r)

  return 200, 'OK', json.dumps(r), None 

handlers = { 'GET': get }
logger = helpers.init_logger('search', config.LOG_PATH)

if __name__ == '__main__':
  
  try:
    handler_config = config.HANDLER_CONFIG['search']
    handler.run(handler_config.send_spec, handler_config.recv_spec, handlers)
  except:
    logger.error(helpers.format_exception())
else:
  handler.handlers_registry[__name__] = handlers
Exemplo n.º 6
0
import handler

handler.run()
Exemplo n.º 7
0
class VerseById(handler.Handler):

  def get(self):
    vid = self.request.get('id')
    if vid:
      verse = self.scrollsDS.GetVerse(vid)
      if not verse:
        self.WriteJsonError("can't get verse %s" % vid)
      else:
        self.WriteJson(verse)
    else:
      self.WriteJsonError('id must be given')

class VerseByCol(handler.Handler):

  def get(self):
    col = self.request.get('col')
    if col:
      verse = self.scrollsDS.GetVersesByCol(col)
      if not verse:
        self.WriteJsonError("can't get verses for %s" % col)
      else:
        self.WriteJson(verse)
    else:
      self.WriteJsonError('col must be given')


if __name__ == '__main__':
  handler.run([('/api/get_verse', VerseById),
               ('/api/get_verse_by_column', VerseByCol)], debug=True)
Exemplo n.º 8
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


""" Answer a verse tanslation """

import json
import handler


class Translation(handler.Handler):

  def get(self):
    vid = self.request.get('id')
    lang = self.request.get('lang') or 'en'
    if vid:
      translation = self.scrollsDS.GetVesreTranslation(vid, lang)
      if not translation:
        self.WriteJsonError("can't get verse %s translation to %s" % (vid, lang))
      else:
        self.WriteJson(translation)
    else:
      self.WriteJsonError('id must be given')

if __name__ == '__main__':
  handler.run([('/api/get_translation', Translation)], debug=True)
Exemplo n.º 9
0
def test_run_not_lifecycle_hook(sns_topic):
    result = handler.run(fixtures.non_lifecycle_message_json, sns_topic)
    assert result == 'error'
Exemplo n.º 10
0
def test_run_message_body_bad_json():
    with pytest.raises(exc.JsonDecodeError):
        handler.run({'Message': ''}, None)
Exemplo n.º 11
0
# --*-- coding:utf8 --*--

if __name__ == "__main__":
    from handler import run
    run()
Exemplo n.º 12
0
import handler


class BulkDelete(handler.Handler):

  def get(self):
    self.response.out.write('<html><body><form method="post">\n')
    self.response.out.write('Entity to delete <input type="text" name="entity"/>\n')
    self.response.out.write('<input type="submit" value="Delete" />\n')
    self.response.out.write('</form></body></html>\n')

  def post(self):
    self.response.headers['Content-Type'] = 'text/plain'
    entity = self.request.get('entity')
    try:
      while True:
        q = db.GqlQuery("SELECT __key__ FROM %s" % entity)
        if not q.count():
          self.response.out.write('Done')
          break;
        db.delete(q.fetch(200))
        time.sleep(1)
    except Exception, e:
      self.response.out.write(repr(e)+'\n')
      pass


if __name__ == '__main__':
  handler.run([('/api/drop_table', BulkDelete)], debug=True)