コード例 #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 init():

    # create the database
    db.configure_mappers()
    db.create_all()

    # create the super user
    u = User(name=settings.SUPER_USER,
             email=settings.SUPER_USER_EMAIL,
             password=settings.SUPER_USER_PASSWORD,
             admin=True,
             super_user=True)

    # optionally add super user apikey
    if getattr(settings, 'SUPER_USER_APIKEY', None):
        u.apikey = settings.SUPER_USER_APIKEY
    db_session.add(u)

    # load sql extensions + functions
    for sql in load_sql():
        db_session.execute(sql)

    # load built-in sous-chefs
    for sc in load_sous_chefs():
        sc = sous_chef_schema.validate(sc)
        s = SousChef(**sc)
        db_session.add(s)

    # commit
    db_session.commit()
コード例 #3
0
    def test_partial_update(self):
        """
        Simiulate a partial update process.
        """
        sc = {
            "name": "Twitter List",
            "slug": "twitter-list",
            "description": "Extracts events from a twitter list.",
            "runs": "newslynx.sc.events.twitter.List",
            "creates": "events",
            "options": {
                "owner_screen_name": {
                    "input_type": "text",
                    "value_types": ["string"],
                    "accepts_list": True,
                    "required": True,
                    "help": {
                        "placeholder": "cspan"
                    },
                },
                "min_followers": {
                    "input_type": "number",
                    "value_types": ["numeric"],
                    "accepts_list": False,
                    "required": False,
                    "default": 0,
                    "help": {
                        "placeholder": 1000
                    }
                }
            }
        }
        sc = sous_chef_schema.validate(sc)
        sc = SousChef(**sc)
        db_session.add(sc)
        db_session.commit()

        new_sc = {
            'name': 'Twitter List to Event',
            'options': {
                'owner_screen_name': {
                    'accepts_list': False
                }
            }
        }
        new_sc = sous_chef_schema.update(sc, new_sc)
        assert (new_sc['name'] == 'Twitter List to Event')
        assert (new_sc['options']['owner_screen_name']['accepts_list'] is
                False)
        db_session.delete(sc)
        db_session.commit()
コード例 #4
0
def create_sous_chef(user):

    req_data = request_data()

    # validate the sous chef
    sc = sous_chef_schema.validate(req_data)

    # add it to the database
    sc = SousChef(**sc)
    db.session.add(sc)
    try:
        db.session.commit()
    except Exception as e:
        raise RequestError(e.message)

    return jsonify(sc)
コード例 #5
0
ファイル: default.py プロジェクト: newslynx/newslynx-core
def sous_chefs(org):
    """
    (Re)load all sous chefs.
    """
    # load all sous-chefs
    for sc, fp in init.load_sous_chefs():
        sc = sous_chef_schema.validate(sc, fp)
        sc['org_id'] = org.id
        sc_obj = db.session.query(SousChef).filter_by(slug=sc['slug']).first()
        if not sc_obj:
            log.info('Creating sous chef: "{slug}"'.format(**sc))
            sc_obj = SousChef(**sc)
        else:
            log.warning('Updating sous chef: "{slug}"'.format(**sc))
            sc = sous_chef_schema.update(sc_obj.to_dict(), sc)
            for name, value in sc.items():
                setattr(sc_obj, name, value)
        db.session.add(sc_obj)
    db.session.commit()
    return org