コード例 #1
0
 def test_get_entity_fields_missing_value_and_date_creation(self):
     entity_from_db = {'time_to_live': '10'}
     try:
         KeyStoreService.get_entity_fields(entity_from_db)
         self.fail('shall fail')
     except Exception as e:
         self.assertEqual(
             e.message,
             'Corrupted data: missing value, date_creation from entity in DB'
         )
コード例 #2
0
 def test_get_entity_fields_nominal_case(self):
     entity_from_db = {
         'date_creation': '2019-03-06 22:44:32',
         'value': 'my value',
         'time_to_live': '10'
     }
     date_creation, time_to_live, value = KeyStoreService.get_entity_fields(
         entity_from_db)
     self.assertEqual(
         date_creation,
         datetime.strptime('2019-03-06 22:44:32', "%Y-%m-%d %H:%M:%S"))
     self.assertEqual(value, 'my value')
     self.assertEqual(time_to_live, 10)
コード例 #3
0
from flask import jsonify, request, abort, make_response, Blueprint

from appplication.metrics.metrics_handler import INTERNAL_ERROR_COUNT
from appplication.services.key_store_service import KeyStoreService
import sys

store_service = KeyStoreService()

views = Blueprint('views', __name__, url_prefix='/')


@views.route('/keys/<id>', methods=['GET'])
def get(id):
    if not store_service.exists(id):
        abort(404)
    value_entity = store_service.get_entity(id)
    if value_entity.is_expired:
        abort(410)
    return jsonify({'response': value_entity.value})


@views.route('/keys', methods=['GET'])
def get_all():
    filter = request.args.get('filter')
    all_available_values = store_service.get_values(filter)
    return jsonify({'response': all_available_values})


@views.route('/keys', methods=['PUT'])
def put():
    expire_in = request.args.get('expire_in')
コード例 #4
0
 def test_filter_keys_with_empty_list(self):
     all_keys = []
     filter = 'test'
     filtered_keys = KeyStoreService.filter_keys(all_keys, filter)
     self.assertEqual(filtered_keys, [])
コード例 #5
0
 def test_filter_keys_with_empty_filter(self):
     all_keys = ['wod', 'world', 'word', 'test', 'toto']
     filter = None
     filtered_keys = KeyStoreService.filter_keys(all_keys, filter)
     self.assertEqual(filtered_keys,
                      ['wod', 'world', 'word', 'test', 'toto'])
コード例 #6
0
 def test_filter_keys_with_wildcard(self):
     all_keys = ['wod', 'world', 'word', 'test', 'toto']
     filter = 'wo$d'
     filtered_keys = KeyStoreService.filter_keys(all_keys, filter)
     self.assertEqual(filtered_keys, ['wod', 'world', 'word'])