コード例 #1
0
    def test_partial_update(self):
        """
        Simiulate a partial update process.
        """
        old_recipe = copy.copy(good_recipe)

        sc = SousChef(**sous_chef)
        db_session.add(sc)
        db_session.commit()

        old_recipe = recipe_schema.validate(old_recipe, sc.to_dict())
        old_id = old_recipe['options']['set_content_items'][0]['id']
        old_recipe['slug'] += "-{}".format(gen_short_uuid())
        r = Recipe(sc, **old_recipe)
        db_session.add(r)
        db_session.commit()
        new_recipe = {
            'owner_screen_name': 'johnoliver',
            'last_job': {
                'foo': 'bar'
            },
            'status': 'stable',
            "set_content_items": [{
                'id': 2,
                'title': 'foobar'
            }]
        }
        new_recipe = recipe_schema.update(r, new_recipe, sc.to_dict())
        assert (new_recipe['options']['owner_screen_name'] == 'johnoliver')
        assert (new_recipe['last_job']['foo'] == 'bar')
        assert (new_recipe['status'] == 'stable')
        assert (new_recipe['options']['set_content_items'][0]['id'] != old_id)
        db_session.delete(r)
        db_session.delete(sc)
        db_session.commit()
コード例 #2
0
    def update_sous_chef_defaults(self):
        """
        Merge in sous chef defaults.
        """
        for key in SOUS_CHEF_DEFAULT_OPTIONS.keys():
            # if the key is in the recipe
            # validate it and add in back in.
            if key in self.recipe:
                self.recipe[key] = self.validate_opt(key, top_level=True)

            # otherwise, merge it in.
            else:
                # if the key should be a slug, fall back on the sous chef
                # slug and add a random hash.
                if key == 'slug':
                    slug = "{}-{}".format(self.sous_chef, gen_short_uuid())
                    self.recipe['slug'] = slug

                # inhert the sous chef's name + description
                elif key == 'name':
                    self.recipe[key] = self.sous_chef_name

                # inhert the sous chef's name + description
                elif key == 'description':
                    self.recipe[key] = self.sous_chef_desc

                # fallback on sous chef defaults.
                else:
                    self.recipe[key] = self.validate_opt(key, top_level=True)
コード例 #3
0
    def update_sous_chef_defaults(self):
        """
        Merge in sous chef defaults.
        """
        for key in SOUS_CHEF_DEFAULT_OPTIONS.keys():
            # if the key is in the recipe
            # validate it and add in back in.
            if key in self.recipe:
                self.recipe[key] = self.validate_opt(key, top_level=True)

            # otherwise, merge it in.
            else:
                # if the key should be a slug, fall back on the sous chef
                # slug and add a random hash.
                if key == 'slug':
                    slug = "{}-{}".format(self.sous_chef, gen_short_uuid())
                    self.recipe['slug'] = slug

                # inhert the sous chef's name + description
                elif key == 'name':
                    self.recipe[key] = self.sous_chef_name

                # inhert the sous chef's name + description
                elif key == 'description':
                    self.recipe[key] = self.sous_chef_desc

                # fallback on sous chef defaults.
                else:
                    self.recipe[key] = self.validate_opt(key, top_level=True)
コード例 #4
0
    def test_partial_update(self):
        """
        Simiulate a partial update process.
        """
        old_recipe = copy.copy(good_recipe)

        sc = SousChef(**sous_chef)
        db_session.add(sc)
        db_session.commit()

        old_recipe = recipe_schema.validate(old_recipe, sc.to_dict())
        old_id = old_recipe['options']['set_content_items'][0]['id']
        old_recipe['slug'] += "-{}".format(gen_short_uuid())
        r = Recipe(sc, **old_recipe)
        db_session.add(r)
        db_session.commit()
        new_recipe = {
            'owner_screen_name': 'johnoliver',
            'last_job': {'foo': 'bar'},
            'status': 'stable',
            "set_content_items": [{'id': 2, 'title': 'foobar'}]
        }
        new_recipe = recipe_schema.update(
            r, new_recipe, sc.to_dict())
        assert(new_recipe['options']['owner_screen_name'] == 'johnoliver')
        assert(new_recipe['last_job']['foo'] == 'bar')
        assert(new_recipe['status'] == 'stable')
        assert(new_recipe['options']['set_content_items'][0]['id'] != old_id)
        db_session.delete(r)
        db_session.delete(sc)
        db_session.commit()