Exemplo n.º 1
0
 def testAddingNewItems(self):
     new_item1 = {KEY: 'one', 'name': 'foo'}
     new_item2 = {KEY: 'two', 'name': 'bar'}
     new_item3 = {KEY: 'three', 'name': 'baz'}
     cached_list_logic.setCacheItems('foo_list',
                                     [new_item1, new_item2, new_item3])
     cached_list = cached_list_model.CachedList.query().get()
     self.assertIn(new_item1, cached_list.list_data)
     self.assertIn(new_item2, cached_list.list_data)
Exemplo n.º 2
0
 def testAddingNewItems(self):
   new_item1 = {KEY: 'one', 'name': 'foo'}
   new_item2 = {KEY: 'two', 'name': 'bar'}
   new_item3 = {KEY: 'three', 'name': 'baz'}
   cached_list_logic.setCacheItems(
       'foo_list', [new_item1, new_item2, new_item3])
   cached_list = cached_list_model.CachedList.query().get()
   self.assertIn(new_item1, cached_list.list_data)
   self.assertIn(new_item2, cached_list.list_data)
Exemplo n.º 3
0
 def testAddingNewCachedList(self):
     cached_list_logic.setCacheItems('foo_list', [{
         KEY: 'one',
         'foo': 'bar'
     }, {
         KEY: 'two',
         'baz': 'qux'
     }])
     cached_list = cached_list_model.CachedList.query().get()
     self.assertIsNotNone(cached_list)
Exemplo n.º 4
0
  def testUpdatingAfterCaching(self):
    """Tests whether cached list state is updated."""
    valid_period = datetime.timedelta(2, 4, 6)
    cached_list_logic.setCacheItems(
        'test_list', [{KEY: 'foo'}, {KEY: 'bar'}], valid_period)
    cached_list = cached_list_model.CachedList.get_by_id('test_list')

    self.assertAlmostEqual(cached_list.valid_through,
                           datetime.datetime.now() + valid_period,
                           delta=datetime.timedelta(seconds=5))

    self.assertFalse(cached_list.is_processing)
Exemplo n.º 5
0
    def testUpdatingAfterCaching(self):
        """Tests whether cached list state is updated."""
        valid_period = datetime.timedelta(2, 4, 6)
        cached_list_logic.setCacheItems('test_list', [{
            KEY: 'foo'
        }, {
            KEY: 'bar'
        }], valid_period)
        cached_list = cached_list_model.CachedList.get_by_id('test_list')

        self.assertAlmostEqual(cached_list.valid_through,
                               datetime.datetime.now() + valid_period,
                               delta=datetime.timedelta(seconds=5))

        self.assertFalse(cached_list.is_processing)
Exemplo n.º 6
0
    def testRemovingDuplicates(self):
        """Tests whether the duplicate list items are removed upon saving."""

        item1 = {KEY: 'one', 'name': 'foo'}
        item2 = {KEY: 'two', 'name': 'bar'}
        item3 = {KEY: 'three', 'name': 'baz'}
        dup_item1 = {KEY: 'one', 'name': 'foo'}
        dup_item2 = {KEY: 'two', 'name': 'qux'}

        list_with_duplicates = [item1, item2, item3, dup_item1, dup_item2]
        # duplicate items should not be present in the cached list
        expected_list = [item1, item2, item3]

        cached_list_logic.setCacheItems('test_list', list_with_duplicates)
        cached_list = cached_list_model.CachedList.get_by_id('test_list')
        self.assertListEqual(cached_list.list_data, expected_list)
Exemplo n.º 7
0
  def testRemovingDuplicates(self):
    """Tests whether the duplicate list items are removed upon saving."""

    item1 = {KEY: 'one', 'name': 'foo'}
    item2 = {KEY: 'two', 'name': 'bar'}
    item3 = {KEY: 'three', 'name': 'baz'}
    dup_item1 = {KEY: 'one', 'name': 'foo'}
    dup_item2 = {KEY: 'two', 'name': 'qux'}

    list_with_duplicates = [item1, item2, item3, dup_item1, dup_item2]
    # duplicate items should not be present in the cached list
    expected_list = [item1, item2, item3]

    cached_list_logic.setCacheItems('test_list', list_with_duplicates)
    cached_list = cached_list_model.CachedList.get_by_id('test_list')
    self.assertListEqual(cached_list.list_data, expected_list)
Exemplo n.º 8
0
def reduceProcess(data_id, entities):
  # TODO: (Aruna) Fix these import
  from melange.logic import cached_list
  from melange.utils import lists

  ctx = context.get()
  params = ctx.mapreduce_spec.mapper.params

  list_id = params['list_id']

  ndb.transaction(lambda: cached_list.setCacheItems(
      data_id, map(json.loads, entities), lists.getList(list_id).valid_period))
Exemplo n.º 9
0
def reduceProcess(data_id, entities):
    # TODO: (Aruna) Fix these import
    from melange.logic import cached_list
    from melange.utils import lists

    ctx = context.get()
    params = ctx.mapreduce_spec.mapper.params

    list_id = params['list_id']

    ndb.transaction(
        lambda: cached_list.setCacheItems(data_id, map(json.loads, entities),
                                          lists.getList(list_id).valid_period))
Exemplo n.º 10
0
 def testAddingNewCachedList(self):
   cached_list_logic.setCacheItems(
       'foo_list', [{KEY: 'one', 'foo': 'bar'}, {KEY: 'two', 'baz': 'qux'}])
   cached_list = cached_list_model.CachedList.query().get()
   self.assertIsNotNone(cached_list)