Beispiel #1
0
    def test_should_work(self):
        catalog = Catalog.search()[:1]
        catalog = catalog.execute()[0]
        catalog_id = catalog.meta.id
        new_data = {'count': catalog.count + 10}
        when = datetime.datetime.utcnow() - datetime.timedelta(days=1)
        update_catalog(catalog_id, new_data, when)
        result = Catalog._index.flush()
        catalog_v2 = Catalog.get(catalog_id)

        self.assertEqual(catalog_v2.count, new_data['count'])
Beispiel #2
0
def update_catalog( self, catalog_id, new_data, when ):
    try:
        catalog = Catalog.get( catalog_id )
    except NotFoundError:
        serializer = Catalog_create( data=new_data )
        serializer.is_valid( raise_exception=True )
        serializer.save()
        return

    if 'count' not in new_data:
        raise ValueError( "los nuevos datos no tienen count" )
    catalog.update_count( new_data[ 'count' ] )