Exemple #1
0
 def tearDown(self):
     city_name = getattr(self.sao_paulo, 'name', None)
     game_score = getattr(self.score, 'score', None)
     if city_name:
         ParseBatcher().batch_delete(City.Query.filter(name=city_name))
     if game_score:
         ParseBatcher().batch_delete(
             GameScore.Query.filter(score=game_score))
Exemple #2
0
 def tearDown(self):
     game_score = getattr(self.score1, 'score', None)
     game_name = getattr(self.game, 'name', None)
     if game_score:
         ParseBatcher().batch_delete(
             GameScore.Query.filter(score=game_score))
     if game_name:
         ParseBatcher().batch_delete(Game.Query.filter(name=game_name))
Exemple #3
0
 def tearDown(self):
     city_name = getattr(self.sao_paulo, 'name', None)
     game_score = getattr(self.score, 'score', None)
     collected_item_type = getattr(self.collected_item, 'type', None)
     if city_name:
         ParseBatcher().batch_delete(City.Query.filter(name=city_name))
     if game_score:
         ParseBatcher().batch_delete(GameScore.Query.filter(score=game_score))
     if collected_item_type:
         ParseBatcher().batch_delete(CollectedItem.Query.filter(type=collected_item_type))
Exemple #4
0
    def setUpClass(cls):
        """save a bunch of GameScore objects with varying scores"""
        # first delete any that exist
        ParseBatcher().batch_delete(GameScore.Query.all())
        ParseBatcher().batch_delete(Game.Query.all())

        cls.game = Game(title="Candyland", creator=None)
        cls.game.save()

        cls.scores = [GameScore(score=s, player_name='John Doe', game=cls.game) for s in range(1, 6)]
        ParseBatcher().batch_save(cls.scores)
Exemple #5
0
 def __init__(self, settings):
     self.settings = settings
     self.fileRestClient = ParseFileRestClient(settings)
     self.galleryService = GalleryService(settings)
     register(self.settings["parse"]["application_id"],
              self.settings["parse"]["rest_api_key"])
     self.batcher = ParseBatcher()
Exemple #6
0
    def testBatch(self):
        """test saving, updating and deleting objects in batches"""
        scores = [
            GameScore(score=s, player_name='Jane', cheat_mode=False)
            for s in range(5)
        ]
        batcher = ParseBatcher()
        batcher.batch_save(scores)
        self.assertEqual(
            GameScore.Query.filter(player_name='Jane').count(), 5,
            "batch_save didn't create objects")
        self.assertTrue(all(s.objectId is not None for s in scores),
                        "batch_save didn't record object IDs")

        # test updating
        for s in scores:
            s.score += 10
        batcher.batch_save(scores)

        updated_scores = GameScore.Query.filter(player_name='Jane')
        self.assertEqual(sorted([s.score for s in updated_scores]),
                         list(range(10, 15)),
                         msg="batch_save didn't update objects")

        # test deletion
        batcher.batch_delete(scores)
        self.assertEqual(
            GameScore.Query.filter(player_name='Jane').count(), 0,
            "batch_delete didn't delete objects")
Exemple #7
0
    def testRelations(self):
        """Make some maps, make a Game Mode that has many maps, find all maps
        given a Game Mode"""
        maps = [GameMap(name="map " + i) for i in ['a', 'b', 'c', 'd']]
        ParseBatcher().batch_save(maps)

        gm = GameMode(name='test mode')
        gm.save()
        gm.addRelation("maps", GameMap.__name__, [m.objectId for m in maps])

        modes = GameMode.Query.all()
        self.assertEqual(len(modes), 1)
        mode = modes[0]
        maps_for_mode = GameMap.Query.filter(maps__relatedTo=mode)
        self.assertEqual(len(maps_for_mode), 4)

        gm.delete()
        ParseBatcher().batch_delete(maps)
Exemple #8
0
    def accept_post(self, post):
        snippet_posts = [Post.get(snip['objectId']) for snip in self.snippets]
        for snippet_post in snippet_posts:
            snippet_post.archived = True
            snippet_post.original_story = self

        batcher = ParseBatcher()
        batcher.batch_save(snippet_posts)

        self.snippets = []
        self.accepted_posts.append(post)
Exemple #9
0
    def testCanBatchUpdate(self):
        user = self._get_logged_user()
        phone_number = "555-0134"

        original_updatedAt = user.updatedAt

        user.phone = phone_number
        batcher = ParseBatcher()
        batcher.batch_save([user])

        self.assertTrue(User.Query.filter(phone=phone_number).exists(),
                        'Failed to batch update user data. New info not on Parse')
        self.assertNotEqual(user.updatedAt, original_updatedAt,
                            'Failed to batch update user data: updatedAt not changed')
Exemple #10
0
def push():
    old_recipes = get_recipes() if not force_override else []
    raw_recipes = yaml.safe_load(open(recipes_filename).read())
    recipes = []
    ingredients = []
    for recipe in raw_recipes:
        if recipe not in old_recipes:
            recipes.append(Recipe(dictionary=recipe))
            for ingredient in recipe["ingredients"]:
                ingredient.update({"recipe": recipe['name']})
                ingredients.append(Ingredient(dictionary=ingredient))

    print "Found {} new recipes.".format(len(recipes))
    print "Found {} new ingredients.".format(len(ingredients))

    if add_cocktaildb_url:
        filename = "cocktaildb.csv"
        cocktaildb_data = open(filename).readlines()
        cocktaildb_data = [line.split(",") for line in cocktaildb_data]
        cocktaildb_data = {
            line[0].lower(): line[1].strip()
            for line in cocktaildb_data
        }

    old_bases = get_bases() if not force_override else []
    raw_bases = yaml.load(open(bases_filename).read())
    bases = []
    brands = []
    for base in raw_bases:
        if base not in old_bases:
            base_object = IngredientBase(dictionary=base)
            bases.append(base_object)
            for brand in base["brands"]:
                brand.update({"base": base["name"]})
                brands.append(Brand(dictionary=brand))
            if add_cocktaildb_url:
                base_object.cocktaildb = cocktaildb_data.get(
                    base_object.name.lower(), "")

    print "Found {} new bases.".format(len(bases))
    print "Found {} new brands.".format(len(brands))

    print "Pushing data."

    max_batch_size = 50
    for chunk in chunks(recipes + bases + ingredients + brands,
                        max_batch_size):
        ParseBatcher().batch_save(chunk)
        print "Pushed {} objects.".format(len(chunk))
Exemple #11
0
def storeMonthlyPrices():
    all_scores = Crop.Query.all()
    data = retrieveMonthly("", 12, 2014)
    #length = 0
    crops = []
    #batches = []
    #batches.append(batcher)
    if data and len(data) > 0:
        for x in range(0, 49):
            crop = Crop(name=data[x]['commodity'],
                        price=data[x]['mean'],
                        size=random.randint(1, 5),
                        soil="all")
            crops.append(crop)
    batcher = ParseBatcher()
    batcher.batch_save(crops)
def load_spell_data(db):
    conn = get_db_connection(db)
    curs = conn.cursor()
    find_central_index(curs, **{"type": "spell"})
    index_lines = curs.fetchall()
    batch = []
    batcher = ParseBatcher()
    count = 0
    for line in index_lines:
        spell = get_parse_spell(line['url'])
        if spell:
            batch.append(make_spell(conn, line, spell))
        else:
            batch.append(make_spell(conn, line))
        if len(batch) >= 50:
            batcher.batch_save(batch)
            batch = []
            count += 50
            print "Saving through %s" % count
    batcher.batch_save(batch)
Exemple #13
0
def postEvents(events):
    batcher = ParseBatcher()
    batcher.batch_save(events)
Exemple #14
0
 def tearDown(self):
     ParseBatcher().batch_delete(Review.Query.all())
Exemple #15
0
 def __init__(self, delay):
     self.batcher = ParseBatcher()
     self.objects_to_save = []
     self.delay = delay
     self.save_count = 0
Exemple #16
0
 def tearDown(self):
     '''delete additional helper objects created in perticular tests'''
     if self.test_objects:
         ParseBatcher().batch_delete(self.test_objects)
         self.test_objects = []
Exemple #17
0
 def tearDownClass(cls):
     '''delete all GameScore and Game objects'''
     ParseBatcher().batch_delete(chain(cls.scores, [cls.game]))
    'data/2014-2 UNLOCODE CodeListPart3.csv'
]
for file_name in file_names:
    with open(file_name, 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quotechar='"')
        for row in reader:
            country_codes.add(row[1])

# Create regions for countries that have subdivisions
regions = []
with open('data/2014-2 SubdivisionCodes.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in reader:
        region = Region(countryISOCode=row[0], regionISOCode=row[1])
        regions.append(region)
        country_codes.discard(row[0])

# Create regions for countries that dont have subdivisions
for country_code in country_codes:
    region = Region(countryISOCode=country_code)
    regions.append(region)

# Save all the created regions to parse
batcher = ParseBatcher()
if len(regions) > 0:
    for index, chunk in enumerate(chunks(regions, 50)):
        print "Saving", index * 50, "-", min((index + 1) * 50 - 1,
                                             len(regions))
        # batcher.batch_save(chunk)
        time.sleep(args.delay)