Beispiel #1
0
    def test_parser(self):
        r = helpers.parser(test_data.RAW_HTML)
        self.assertEqual(r, test_data.PARSED_HTML)

        with self.assertRaises(ValueError):
            helpers.parser(test_data.MULTIPLE_YEAR_HTML)

        with self.assertRaises(ValueError):
            helpers.parser(test_data.MULTIPLE_MONTH_HTML)
Beispiel #2
0
def valid_proto(one, two, three, four, five, six, seven):

    # Ensures user provided 6 + 1 numbers
    if (not one or not two or not three or not four or not five or not six
            or not seven):
        flash("Must provide 7 numbers", 'danger')
        return False

    numbers = (int(one), int(two), int(three), int(four), int(five), int(six),
               int(seven))
    # Ensures each number is in valid range
    for number in numbers:
        if number < 0 or number > 9:
            flash("Each number must be within 0 to 9", 'danger')
            return False

    # Checks users funds
    cash = db.execute("SELECT cash FROM users WHERE id = :id",
                      id=session["user_id"])[0]['cash']
    if cash < 0.5:
        flash("Insufficient funds", 'danger')
        return False

    # Ensures that participation is still open
    game = parser(2101, 'active')
    draw_time_limit = game['drawTime'] + timedelta(hours=-1)
    if datetime.now() > draw_time_limit:
        flash("Participation is now closed, draw in less than 1 hour",
              'danger')
        return False

    return {'game_id': game['game_id'], "drawTime": game['drawTime']}
Beispiel #3
0
    def test_parser_descricao_vazia(self):
        """Teste para nota sem descricao"""
        json = dict(self.json)
        del json['descricao']
        data = parser(json)

        self.assertEqual('-', data[4])
        self.assertFalse(data[0])
Beispiel #4
0
    def test_parser_valor_vazio(self):
        """Teste para nota sem valor"""
        json = dict(self.json)
        del json['valor']
        data = parser(json)

        self.assertEqual(0, data[3])
        self.assertFalse(data[0])
Beispiel #5
0
    def test_parser_cliente_vazio(self):
        """Teste para nota sem cliente"""
        json = dict(self.json)
        del json['cliente']
        data = parser(json)

        self.assertEqual('-', data[2])
        self.assertFalse(data[0])
Beispiel #6
0
    def test_parser_estabelecimento_vazio(self):
        """Teste para nota sem estabelecimento"""
        json = dict(self.json)
        del json['estabelecimento']
        data = parser(json)

        self.assertEqual('-', data[1])
        self.assertFalse(data[0])
Beispiel #7
0
    def test_parser_valor_invalido(self):
        """Teste para valor invalido"""
        json = dict(self.json)
        json['valor'] = self.valor_invalido
        data = parser(json)

        self.assertEqual(0, data[3])
        self.assertFalse(data[0])
Beispiel #8
0
    def test_parser_cliente_invalido(self):
        """Teste para cliente invalido"""
        json = dict(self.json)
        json['cliente'] = self.cliente_invalido
        data = parser(json)

        self.assertEqual(self.cliente_invalido, data[2])
        self.assertFalse(data[0])
Beispiel #9
0
    def test_parser_estabelecimento_invalido(self):
        """Teste para estabelecimento invalido"""
        json = dict(self.json)
        json['estabelecimento'] = self.estabelecimento_invalido
        data = parser(json)

        self.assertEqual(self.estabelecimento_invalido, data[1])
        self.assertFalse(data[0])
Beispiel #10
0
def more():
    page = int(request.form.get("page"))

    #testing
    if request.form.get("test"):
        session["page"] = request.form.get("test")
        if request.form.get("query"):
            if request.form.get("test") == "search":
                session_data["query"] = request.form.get("query")   
            if request.form.get("test") == "cat-search":
                session_data["query"] = request.form.get("query").split(",")

    try:
        #render home json route
        if session["page"] == "home":
            render = Products.query.paginate(page=page, per_page=2)
            products = parser(render)
            return jsonify(products)

        #render category json route
        if session["page"] in ["computing", "electronics", "fashion", "health-and-beauty", "home-and-office", "phones-and-tablets"]:
            categ = session["page"].replace("-", " ").lower()
            render = Products.query.filter_by(category=categ).paginate(page=page, per_page=2)
            products = parser(render)
            categ = categ.replace(" ", "-").lower()
            return jsonify(products)

        #render search json route
        if session["page"] == "search":
            query = session_data["query"]
            render = Products.query.filter(Products.name.ilike(f"%{query}%")).paginate(page=page, per_page=2)
            products = parser(render)
            return jsonify(products)

        #render category search json route
        if session["page"] == "cat-search":
            query = session_data["query"][0]
            cat_checks = session_data["query"][1]
            render = Products.query.filter_by(category=cat_checks).filter(Products.name.ilike(f"%{query}%")).paginate(page=page, per_page=2)
            products = parser(render)
            return jsonify(products)

    except Exception as e:
        return jsonify([{'success': False}])

    return jsonify([{'success': False}])
def get_gists():
    ''' Get the github public gists of given username. '''
    username = request.form['username']
    headers = {'Accept': 'application/vnd.github.v3+json'}
    url_endpoint = 'https://api.github.com/users/' + username + '/gists'
    # call github api to fetch gists
    response = requests.get(url_endpoint, headers=headers)
    # check api response status
    if response.status_code != 200:
        raise Exception('Server error: Cannot fetch all gists: {}'.format(
            response.status_code))
    # parse response json
    parsed_response = parser(response.json())
    return render_template("index.html", available_gists=parsed_response)
Beispiel #12
0
def valid_lotto(one, two, three, four, five, six, seven):

    # Ensures user provided 6 + 1 numbers
    if (not one or not two or not three or not four or not five or not six
            or not seven):
        flash("Must provide 6 numbers and a Bonus number", 'danger')
        return False

    # Ensures user provided 7 unique numbers by creating a set
    set_Numbers = {
        int(one),
        int(two),
        int(three),
        int(four),
        int(five),
        int(six),
        int(seven)
    }
    if len(set_Numbers) != 7:
        flash("Each number must be unique & from 1 to 49", 'danger')
        return False

    # Ensures each number is in valid range
    for number in set_Numbers:
        if number < 1 or number > 49:
            flash("Each number must be within 1 to 49", 'danger')
            return False

    # Checks users funds
    cash = db.execute("SELECT cash FROM users WHERE id = :id",
                      id=session["user_id"])[0]['cash']
    if cash < 0.5:
        flash("Insufficient funds", 'danger')
        return False

    # Ensures that participation is still open
    game = parser(5103, 'active')
    draw_time_limit = game['drawTime'] + timedelta(hours=-1)
    if datetime.now() > draw_time_limit:
        flash("Participation is now closed, draw in less than 1 hour",
              'danger')
        return False

    return {'game_id': game['game_id'], "drawTime": game['drawTime']}
def transaction_api():
    """Returns a JSON response when accessed by a POST method
    with the structure:
        # JSON POST:
        {
        "estabelecimento": "45.283.163/0001-67",
        "cliente": "094.214.930-01",
        "valor": 590.01,
        "descricao": "Almoço em restaurante chique pago via Shipay!"
        }
    
    The response is:
        {
        "aceito": true
        }

    All the informations about this transaction will be persisted in the
    database from the db variable.
    """
    if request.method != "POST":
        return jsonify({'error': "HTTP method not supported!"}), 400

    # Handle empty requests
    if not request.json:
        return jsonify({'error': 'no request received'}), 401


    parsed_data = parser(request.json)  

    aceito, estabelecimento, cliente, valor, descricao = parsed_data

    transaction_db = Transaction(
        estabelecimento=estabelecimento,
        cliente=cliente,
        valor=valor,
        descricao=descricao,
        aceito=aceito
    )

    db.add(transaction_db)
    db.commit()

    return jsonify({'aceito': aceito}), 201
def scenario(params=None, m=2):
    # use argparse object as default template
    p = parser()
    args = p.parse_args()
    if args.log in c.ACCEPTED_LOG_LEVELS:
        logging.basicConfig(level=eval('logging.' + args.log))
    if params is not None:
        args = update_args(args, params)
    print args

    SO = True if args.model == 'SO' else False
    # N0, N1, scale, regions, res, margin
    config = (args.NB, args.NL, 0.2, [((3.5, 0.5, 6.5, 3.0), args.NS)], (6, 3),
              2.0)
    data, graph = generate_data_UE(data=config, SO=SO, NLP=args.NLP, m=m)

    if 'error' in data:
        return {'error': data['error']}

    return args, data, graph
def lastproto():
    global last_proto_game
    last_proto_game = parser(2101, 'last')
    flash("Last lotto game updated!", 'success')
    return render_template('/proto.html', draw=last_proto_game)
def lastjoker():
    global last_joker_game
    last_joker_game = parser(5104, 'last')
    flash("Last joker game updated!", 'success')
    return render_template('/joker.html', draw=last_joker_game)