Exemplo n.º 1
0
    def test_unknown_type_filter(self):
        unknown_type_filter = Mock()
        obj = object()
        assert jsonify(obj, unknown_type_filter=unknown_type_filter) is unknown_type_filter.return_value
        unknown_type_filter.assert_called_with(obj)

        with pytest.raises(ValueError):
            jsonify(obj)
Exemplo n.º 2
0
    def test_unknown_type_filter(self):
        unknown_type_filter = Mock()
        obj = object()
        assert (jsonify(obj, unknown_type_filter=unknown_type_filter) is
                unknown_type_filter.return_value)
        unknown_type_filter.assert_called_with(obj)

        with pytest.raises(ValueError):
            jsonify(obj)
Exemplo n.º 3
0
def conf(state, with_defaults=False, **kwargs):
    """List configuration."""
    return jsonify(
        state.app.conf.table(with_defaults=with_defaults),
        keyfilter=_wanted_config_key,
        unknown_type_filter=safe_repr,
    )
Exemplo n.º 4
0
def test_task():
    """
    Task used for testing the setup
        :return: json string with a timestamp field
    """
    time.sleep(0.1)
    return jsonify({"timestamp": datetime.now()})
Exemplo n.º 5
0
 def get(self):
     sets = get_online_uids()
     if sets is None:
         return {}, 200
     result = []
     for uid in sets:
         result.append(UserModel.find_by_id(uid).to_json())
     return jsonify(result), 200
Exemplo n.º 6
0
 def get(self):
     params = _user_parser.parse_args()
     page = params['page']
     per_page = params['per_page']
     print('Accounts--get----{}----{}'.format(page, per_page))
     items = UserModel.find_paginate(**params).items
     result = []
     for item in items:
         result.append(item.to_json())
     return jsonify(result), 200
Exemplo n.º 7
0
def get_avg_exch_rate(exch_rates):
    """
    Task that takes in an json object with array of rates from a provider and computes the average rate
        :param exch_rates: json object containing an array of rates from a provider
        :return: json string with the average rate from the provider
    """
    acc = 0.0
    for elem in exch_rates:
        acc += elem['rate']
    avg = acc / len(exch_rates)
    time.sleep(0.5)

    return jsonify({'provider': exch_rates[0]['provider'], 'crypto': exch_rates[0]['crypto'], 'average': avg})
Exemplo n.º 8
0
def get_exch_rate(exch, crypto):
    """
    Task to get the current rate for a given fictitious exchange and fictitious crypto coin
        :param exch: string with one of the values 'CAT', 'DOG', or 'FOX'
        :param crypto: string with value 'BLU' or 'RED'
        :return: json string with the rate from the provider
    """
    if datetime.today().second % 2 == 0:
        rate = crypto_fx[crypto] - random.choice(exchange_diff[exch + '-' + crypto])
    else:
        rate = crypto_fx[crypto] + random.choice(exchange_diff[exch + '-' + crypto])
    time.sleep(0.5)

    return jsonify({'provider': exch, 'crypto': crypto, 'rate': rate})
Exemplo n.º 9
0
def get_rate(crypto):
    """
    Task used to get the lowest rate of two fictitious crypto coins - BLU and RED from the fictitious market
    providers - CAT, DOG, and FOX
        :param crypto: string with value 'BLU' or 'RED'
        :return: json string with the rate from the provider
    """
    rb = crypto_fx[crypto] - random.choice(exchange_diff['CAT-' + crypto])
    time.sleep(0.05)
    rf = crypto_fx[crypto] - random.choice(exchange_diff['DOG-' + crypto])
    time.sleep(0.05)
    rl = crypto_fx[crypto] - random.choice(exchange_diff['FOX-' + crypto])
    time.sleep(0.05)

    val, idx = min((val, idx) for (idx, val) in enumerate([rb, rf, rl]))

    return jsonify({'crypto': crypto, 'rate': val, 'provider': ['CAT', 'DOG', 'FOX'][idx]})
Exemplo n.º 10
0
 def test_simple(self, obj):
     assert jsonify(obj)
Exemplo n.º 11
0
def conf(state, with_defaults=False, **kwargs):
    """List configuration."""
    return jsonify(state.app.conf.table(with_defaults=with_defaults),
                   keyfilter=_wanted_config_key,
                   unknown_type_filter=safe_repr)
Exemplo n.º 12
0
    def test_simple(self):
        self.assertTrue(jsonify(Queue('foo')))
        self.assertTrue(jsonify(['foo', 'bar', 'baz']))
        self.assertTrue(jsonify({'foo': 'bar'}))
        self.assertTrue(jsonify(datetime.utcnow()))
        self.assertTrue(jsonify(datetime.utcnow().replace(tzinfo=pytz.utc)))
        self.assertTrue(jsonify(datetime.utcnow().replace(microsecond=0)))
        self.assertTrue(jsonify(date(2012, 1, 1)))
        self.assertTrue(jsonify(time(hour=1, minute=30)))
        self.assertTrue(jsonify(time(hour=1, minute=30, microsecond=3)))
        self.assertTrue(jsonify(timedelta(seconds=30)))
        self.assertTrue(jsonify(10))
        self.assertTrue(jsonify(10.3))
        self.assertTrue(jsonify('hello'))

        unknown_type_filter = Mock()
        obj = object()
        self.assertIs(
            jsonify(obj, unknown_type_filter=unknown_type_filter),
            unknown_type_filter.return_value,
        )
        unknown_type_filter.assert_called_with(obj)

        with self.assertRaises(ValueError):
            jsonify(obj)
    def test_simple(self):
        self.assertTrue(jsonify(Queue('foo')))
        self.assertTrue(jsonify(['foo', 'bar', 'baz']))
        self.assertTrue(jsonify({'foo': 'bar'}))
        self.assertTrue(jsonify(datetime.utcnow()))
        self.assertTrue(jsonify(datetime.utcnow().replace(tzinfo=pytz.utc)))
        self.assertTrue(jsonify(datetime.utcnow().replace(microsecond=0)))
        self.assertTrue(jsonify(date(2012, 1, 1)))
        self.assertTrue(jsonify(time(hour=1, minute=30)))
        self.assertTrue(jsonify(time(hour=1, minute=30, microsecond=3)))
        self.assertTrue(jsonify(timedelta(seconds=30)))
        self.assertTrue(jsonify(10))
        self.assertTrue(jsonify(10.3))
        self.assertTrue(jsonify('hello'))

        unknown_type_filter = Mock()
        obj = object()
        self.assertIs(
            jsonify(obj, unknown_type_filter=unknown_type_filter),
            unknown_type_filter.return_value,
        )
        unknown_type_filter.assert_called_with(obj)

        with self.assertRaises(ValueError):
            jsonify(obj)
Exemplo n.º 14
0
 def test_simple(self, obj):
     assert jsonify(obj)
Exemplo n.º 15
0
def dump_conf(state, with_defaults=False, **kwargs):
    return jsonify(state.app.conf.table(with_defaults=with_defaults),
                   keyfilter=_wanted_config_key,
                   unknown_type_filter=safe_repr)
Exemplo n.º 16
0
def dump_conf(state, with_defaults=False, **kwargs):
    return jsonify(state.app.conf.table(with_defaults=with_defaults),
                   keyfilter=_wanted_config_key,
                   unknown_type_filter=safe_repr)