Exemplo n.º 1
0
    def test_api_key_balance(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/account/balance",
                           body='''{"amount":"1.00000000","currency":"BTC"}''',
                           content_type='text/json')

        this(self.account.balance).should.equal(1.0)
Exemplo n.º 2
0
def test_have_property():
    (u"this(instance).should.have.property(property_name)")

    class Person(object):
        name = "John Doe"

        def __repr__(self):
            return ur"Person()"

    jay = Person()

    assert this(jay).should.have.property("name")
    assert this(jay).should_not.have.property("age")

    def opposite():
        assert this(jay).should_not.have.property("name")

    def opposite_not():
        assert this(jay).should.have.property("age")

    assert that(opposite).raises(AssertionError)
    assert that(opposite).raises(
        "Person() should not have the property `name`, but it is 'John Doe'")

    assert that(opposite_not).raises(AssertionError)
    assert that(opposite_not).raises(
        "Person() should have the property `age` but doesn't")
Exemplo n.º 3
0
 def test_alloc_some_of_the_bridges(self):
     """Set the needed number of bridges"""
     needed = 10
     distname = "test-distributor"
     bucket = Bucket.BucketData(distname, needed)
     this(bucket.name).should.be.equal(distname)
     this(bucket.needed).should.be.equal(needed)
Exemplo n.º 4
0
 def test_alloc_all_the_bridges(self):
     """Set the needed number of bridges to the default"""
     needed = '*'
     distname = "test-distributor"
     bucket = Bucket.BucketData(distname, needed)
     this(bucket.name).should.be.equal(distname)
     this(bucket.needed).should.be.equal(Bucket.BUCKET_MAX_BRIDGES)
def test_order_callback():
    """
    The example from the callbacks doc
    https://coinbase.com/docs/merchant_tools/callbacks
    """
    this(CoinbaseOrder.parse_callback(callback_body)) \
        .should.be.equal(expected_order)
Exemplo n.º 6
0
    def test_receive_addresses(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/account/receive_address",
                               body='''{"address" : "1DX9ECEF3FbGUtzzoQhDT8CG3nLUEA2FJt"}''',
                               content_type='text/json')

        this(self.account.receive_address).should.equal(u'1DX9ECEF3FbGUtzzoQhDT8CG3nLUEA2FJt')
 def go(self, account):
     rates = account.exchange_rates
     this(last_request_params()).should.equal({})
     this(rates['gbp_to_usd']).should.be.equal(Decimal('1.648093'))
     this(rates['usd_to_btc']).should.be.equal(Decimal('0.002'))
     this(rates['btc_to_usd']).should.be.equal(Decimal('499.998'))
     this(rates['bdt_to_btc']).should.be.equal(Decimal('0.000026'))
Exemplo n.º 8
0
 def test_transactions(self):
     self.account.send(amount=CoinbaseAmount('.5', 'BTC'),
                       to_address='*****@*****.**')
     self.account.send(amount=CoinbaseAmount('.8', 'BTC'),
                       to_address='*****@*****.**')
     this([tx.recipient_address for tx in self.account.transactions()]) \
         .should.equal(['*****@*****.**', '*****@*****.**'])
Exemplo n.º 9
0
def test_have_property():
    (u"this(instance).should.have.property(property_name)")

    class Person(object):
        name = "John Doe"

        def __repr__(self):
            return r"Person()"

    jay = Person()

    assert this(jay).should.have.property("name")
    assert this(jay).should_not.have.property("age")

    def opposite():
        assert this(jay).should_not.have.property("name")

    def opposite_not():
        assert this(jay).should.have.property("age")

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr(
        "Person() should not have the property `name`, but it is 'John Doe'"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(
        "Person() should have the property `age` but does not")
Exemplo n.º 10
0
def test_be():
    ("this(X).should.be(X) when X is a reference to the same object")

    d1 = {}
    d2 = d1
    d3 = {}

    assert isinstance(this(d2).should.be(d1), bool)
    assert this(d2).should.be(d1)
    assert this(d3).should_not.be(d1)

    def wrong_should():
        return this(d3).should.be(d1)

    def wrong_should_not():
        return this(d2).should_not.be(d1)

    wrong_should_not.when.called.should.throw(
        AssertionError,
        '{} should not be the same object as {}, but it is',
    )
    wrong_should.when.called.should.throw(
        AssertionError,
        '{} should be the same object as {}, but it is not',
    )
Exemplo n.º 11
0
def test_match_contain():
    (u"expect('some string').to.contain('tri')")

    assert this("some string").should.contain("tri")
    assert this("some string").should_not.contain('foo')

    def opposite():
        assert this("some string").should.contain("bar")

    def opposite_not():
        assert this("some string").should_not.contain(r"string")

    expect(opposite).when.called.to.throw(AssertionError)
    if PY3:
        expect(opposite).when.called.to.throw(
            "'bar' should be in 'some string'")
    else:
        expect(opposite).when.called.to.throw(
            "u'bar' should be in u'some string'")

    expect(opposite_not).when.called.to.throw(AssertionError)
    if PY3:
        expect(opposite_not).when.called.to.throw(
            "'string' should NOT be in 'some string'")
    else:
        expect(opposite_not).when.called.to.throw(
            "u'string' should NOT be in u'some string'")
Exemplo n.º 12
0
    def test_sell_price_10(self):
        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/prices/sell?qty=1",
                               body='''{"amount":"630.31","currency":"USD"}''',
                               content_type='text/json')

        sell_price_10 = self.account.sell_price(10)
        this(sell_price_10).should.be.greater_than(100)
Exemplo n.º 13
0
def test_have_property_with_value():
    (u"this(instance).should.have.property(property_name).being or "
     ".with_value should allow chain up")

    class Person(object):
        name = "John Doe"

        def __repr__(self):
            return r"Person()"

    jay = Person()

    assert this(jay).should.have.property("name").being.equal("John Doe")
    assert this(jay).should.have.property("name").not_being.equal("Foo")

    def opposite():
        assert this(jay).should.have.property("name").not_being.equal(
            "John Doe")

    def opposite_not():
        assert this(jay).should.have.property("name").being.equal(
            "Foo")

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw(compat_repr(
        "'John Doe' should differ to 'John Doe', but is the same thing"))

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw(compat_repr(
        "X is 'John Doe' whereas Y is 'Foo'"))
Exemplo n.º 14
0
    def test_buy_price_2(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/prices/buy?qty=10",
                               body='''{"amount":"633.25","currency":"USD"}''',
                               content_type='text/json')

        buy_price_10 = self.account.buy_price(10)
        this(buy_price_10).should.be.greater_than(100)
Exemplo n.º 15
0
 def test_invalidNicknameNonAlphanumeric(self):
     """Test a line with a non-alphanumeric router nickname."""
     self.makeRLine(nick='abcdef/*comment*/')
     fields = networkstatus.parseRLine(self.line)
     nick, ident, desc = fields[:3]
     this(nick).should.be(None)
     the(ident).should.be.a(basestring)
     the(desc).should.be(None)
Exemplo n.º 16
0
    def test_stateCreation(self):
        this(self.state).should.be.ok

        this(self.state).should.have.property('config').being.ok
        this(self.state).should.have.property('config').being.equal(self.config)

        this(self.state.options).should.be.ok
        this(self.state.options).should.equal(self.options)
Exemplo n.º 17
0
    def test_retrieve_balance(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/account/balance",
                               body='''{"amount":"0.00000000","currency":"BTC"}''',
                               content_type='text/json')

        this(float(self.account.balance)).should.equal(0.0)
        this(self.account.balance.currency).should.equal('BTC')
Exemplo n.º 18
0
 def test_missingPrefix(self):
     """Changed to allow a missing 'a' prefix in branch
     ``hotfix/9462B-netstatus-returns-None``.
     """
     self.line = '%s:1234' % self.oraddr
     ip, port = networkstatus.parseALine(self.line)
     this(ip).should.be.a(basestring)
     this(port).should.be(None)
Exemplo n.º 19
0
 def test_invalidNicknameTooLong(self):
     """Test a line with a router nickname which is way too long."""
     self.makeRLine(nick='ThisIsAReallyReallyLongRouterNickname')
     fields = networkstatus.parseRLine(self.line)
     nick, ident, desc = fields[:3]
     this(nick).should.be(None)
     the(ident).should.be.a(basestring)
     the(desc).should.be(None)
Exemplo n.º 20
0
    def test_order_list(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/orders",
                               body='''{"orders":[{"order":{"id":"A7C52JQT","created_at":"2013-03-11T22:04:37-07:00","status":"completed","total_btc":{"cents":100000000,"currency_iso":"BTC"},"total_native":{"cents":3000,"currency_iso":"USD"},"custom":"","button":{"type":"buy_now","name":"Order #1234","description":"order description","id":"eec6d08e9e215195a471eae432a49fc7"},"transaction":{"id":"513eb768f12a9cf27400000b","hash":"4cc5eec20cd692f3cdb7fc264a0e1d78b9a7e3d7b862dec1e39cf7e37ababc14","confirmations":0}}}],"total_count":1,"num_pages":1,"current_page":1}''',
                               content_type='text/json')

        orders = self.account.orders()
        this(orders).should.be.a(list)
        this(orders[0].order_id).should.equal("A7C52JQT")
Exemplo n.º 21
0
    def test_transaction_list(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/transactions",
                               body='''{"current_user":{"id":"509e01ca12838e0200000212","email":"*****@*****.**","name":"*****@*****.**"},"balance":{"amount":"0.00000000","currency":"BTC"},"total_count":4,"num_pages":1,"current_page":1,"transactions":[{"transaction":{"id":"514e4c37802e1bf69100000e","created_at":"2013-03-23T17:43:35-07:00","hsh":null,"notes":"Testing","amount":{"amount":"1.00000000","currency":"BTC"},"request":true,"status":"pending","sender":{"id":"514e4c1c802e1bef9800001e","email":"*****@*****.**","name":"*****@*****.**"},"recipient":{"id":"509e01ca12838e0200000212","email":"*****@*****.**","name":"*****@*****.**"}}},{"transaction":{"id":"514e4c1c802e1bef98000020","created_at":"2013-03-23T17:43:08-07:00","hsh":null,"notes":"Testing","amount":{"amount":"1.00000000","currency":"BTC"},"request":true,"status":"pending","sender":{"id":"514e4c1c802e1bef9800001e","email":"*****@*****.**","name":"*****@*****.**"},"recipient":{"id":"509e01ca12838e0200000212","email":"*****@*****.**","name":"*****@*****.**"}}},{"transaction":{"id":"514b9fb1b8377ee36500000d","created_at":"2013-03-21T17:02:57-07:00","hsh":"42dd65a18dbea0779f32021663e60b1fab8ee0f859db7172a078d4528e01c6c8","notes":"You gave me this a while ago. It's turning into a fair amount of cash and thought you might want it back :) Building something on your API this weekend. Take care!","amount":{"amount":"-1.00000000","currency":"BTC"},"request":false,"status":"complete","sender":{"id":"509e01ca12838e0200000212","email":"*****@*****.**","name":"*****@*****.**"},"recipient":{"id":"4efec8d7bedd320001000003","email":"*****@*****.**","name":"Brian Armstrong"},"recipient_address":"*****@*****.**"}},{"transaction":{"id":"509e01cb12838e0200000224","created_at":"2012-11-09T23:27:07-08:00","hsh":"ac9b0ffbe36dbe12c5ca047a5bdf9cadca3c9b89b74751dff83b3ac863ccc0b3","notes":"","amount":{"amount":"1.00000000","currency":"BTC"},"request":false,"status":"complete","sender":{"id":"4efec8d7bedd320001000003","email":"*****@*****.**","name":"Brian Armstrong"},"recipient":{"id":"509e01ca12838e0200000212","email":"*****@*****.**","name":"*****@*****.**"},"recipient_address":"*****@*****.**"}}]}''',
                           content_type='text/json')

        transaction_list = self.account.transactions()

        this(transaction_list).should.be.an(list)
Exemplo n.º 22
0
    def test_contacts(self):
        HTTPretty.register_uri(
            HTTPretty.GET,
            "https://coinbase.com/api/v1/contacts",
            body="""{"contacts":[{"contact":{"email":"*****@*****.**"}}],"total_count":1,"num_pages":1,"current_page":1}""",
            content_type="text/json",
        )

        this(self.account.contacts).should.equal([{u"email": u"*****@*****.**"}])
Exemplo n.º 23
0
    def test_getting_user_details(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/users",
                               body='''{"users":[{"user":{"id":"509f01da12837e0201100212","name":"New User","email":"*****@*****.**","time_zone":"Pacific Time (US & Canada)","native_currency":"USD","buy_level":1,"sell_level":1,"balance":{"amount":"1225.86084181","currency":"BTC"},"buy_limit":{"amount":"10.00000000","currency":"BTC"},"sell_limit":{"amount":"50.00000000","currency":"BTC"}}}]}''',
                               content_type='text/json')

        user = self.account.get_user_details()

        this(user.id).should.equal("509f01da12837e0201100212")
        this(user.balance).should.equal(1225.86084181)
Exemplo n.º 24
0
    def test_getting_transaction(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/transactions/5158b227802669269c000009",
                               body='''{"transaction":{"id":"5158b227802669269c000009","created_at":"2013-03-31T15:01:11-07:00","hsh":"223a404485c39173ab41f343439e59b53a5d6cba94a02501fc6c67eeca0d9d9e","notes":"","amount":{"amount":"-0.10000000","currency":"BTC"},"request":false,"status":"pending","sender":{"id":"509e01ca12838e0200000212","email":"*****@*****.**","name":"*****@*****.**"},"recipient_address":"15yHmnB5vY68sXpAU9pR71rnyPAGLLWeRP"}}''',
                               content_type='text/json')

        transaction = self.account.get_transaction('5158b227802669269c000009')

        this(transaction.status).should.equal('pending')
        this(transaction.amount).should.equal(-0.1)
Exemplo n.º 25
0
    def test_retrieve_balance(self):

        HTTPretty.register_uri(
            HTTPretty.GET,
            "https://coinbase.com/api/v1/account/balance",
            body="""{"amount":"0.00000000","currency":"BTC"}""",
            content_type="text/json",
        )

        this(self.account.balance).should.equal(0.0)
        this(self.account.balance.currency).should.equal("BTC")
Exemplo n.º 26
0
    def test_request_bitcoin(self):

        HTTPretty.register_uri(HTTPretty.POST, "https://coinbase.com/api/v1/transactions/request_money",
                               body='''{"success":true,"transaction":{"id":"514e4c37802e1bf69100000e","created_at":"2013-03-23T17:43:35-07:00","hsh":null,"notes":"Testing","amount":{"amount":"1.00000000","currency":"BTC"},"request":true,"status":"pending","sender":{"id":"514e4c1c802e1bef9800001e","email":"*****@*****.**","name":"*****@*****.**"},"recipient":{"id":"509e01ca12838e0200000212","email":"*****@*****.**","name":"*****@*****.**"}}}''',
                               content_type='text/json')

        new_request = self.account.request('*****@*****.**', 1, 'Testing')

        this(new_request.amount).should.equal(1)
        this(new_request.request).should.equal(True)
        this(new_request.sender.email).should.equal('*****@*****.**')
        this(new_request.recipient.email).should.equal('*****@*****.**')
        this(new_request.notes).should.equal('Testing')
Exemplo n.º 27
0
    def test_getting_order(self):

        HTTPretty.register_uri(HTTPretty.GET, "https://coinbase.com/api/v1/orders/A7C52JQT",
                               body='''{"order":{"id":"A7C52JQT","created_at":"2013-03-11T22:04:37-07:00","status":"completed","total_btc":{"cents":10000000,"currency_iso":"BTC"},"total_native":{"cents":10000000,"currency_iso":"BTC"},"custom":"","button":{"type":"buy_now","name":"test","description":"","id":"eec6d08e9e215195a471eae432a49fc7"},"transaction":{"id":"513eb768f12a9cf27400000b","hash":"4cc5eec20cd692f3cdb7fc264a0e1d78b9a7e3d7b862dec1e39cf7e37ababc14","confirmations":0}}}''',
                               content_type='text/json')

        order = self.account.get_order("A7C52JQT")

        this(order.order_id).should.equal("A7C52JQT")
        this(order.status).should.equal("completed")
        this(order.total_btc).should.equal(CoinbaseAmount(Decimal(".1"), "BTC"))
        this(order.button.name).should.equal("test")
        this(order.transaction.transaction_id).should.equal("513eb768f12a9cf27400000b")
Exemplo n.º 28
0
def test_be():
    (u"this(X).should.be(X) when X is a reference to the same object")

    d1 = {}
    d2 = d1
    d3 = {}

    assert isinstance(this(d2).should.be(d1), bool)
    assert this(d2).should.be(d1)
    assert this(d3).should_not.be(d1)

    (this(d2).should_not.be).when.called_with(d1).should.throw(AssertionError)
    (this(d3).should.be).when.called_with(d1).should.throw(AssertionError)
Exemplo n.º 29
0
def test_find_inline_doctests_with_titles():
    ("SteadyMark should find docstrings and use the "
     "previous header as title")

    md = """# test 1
a paragraph

```python
>>> x = 'doc'
>>> y = 'test'
>>> assert (x + y) == 'doctest'
```

# not a test

foobar

```ruby
ruby no!
```

# another part

## test 2

a paragraph

```python
assert False, 'uh yeah'
```
    """

    sm = SteadyMark.inspect(md)

    sm.tests.should.have.length_of(2)

    test1, test2 = sm.tests

    test1.title.should.equal("test 1")
    test1.raw_code.should.equal(">>> x = 'doc'\n"
                                ">>> y = 'test'\n"
                                ">>> assert (x + y) == 'doctest'")

    this(test1.code).should.be.a('doctest.DocTest')
    test1.run()
    test2.title.should.equal("test 2")
    test2.raw_code.should.equal("assert False, 'uh yeah'")
    eval.when.called_with(test2.code).should.throw(AssertionError, "uh yeah")
Exemplo n.º 30
0
def test_false_be_falsy():
    (u"this(False).should.be.false")

    assert this(False).should.be.falsy
    assert this(True).should_not.be.falsy

    def opposite():
        assert this(True).should.be.falsy

    def opposite_not():
        assert this(False).should_not.be.falsy

    expect(opposite).when.called.to.throw(AssertionError)
    expect(opposite).when.called.to.throw("expected `True` to be falsy")

    expect(opposite_not).when.called.to.throw(AssertionError)
    expect(opposite_not).when.called.to.throw("expected `False` to be truthy")
Exemplo n.º 31
0
 def opposite_not():
     assert this([]).should_not.be.a('list')
Exemplo n.º 32
0
 def test_persistent_getState(self):
     persistent.should.have.property('_getState').being(callable)
     this(persistent._getState()).should.be.a(persistent.State)
Exemplo n.º 33
0
 def test_optionsCreation(self):
     this(self.options).should.be.ok
     this(self.options).should.be.a(dict)
Exemplo n.º 34
0
 def opposite():
     assert this("cool").should.be.none
Exemplo n.º 35
0
 def opposite():
     assert this(True).should.be.falsy
Exemplo n.º 36
0
 def opposite_not():
     assert this(jay).should.have.property("age")
Exemplo n.º 37
0
 def opposite_not():
     assert this(jay).should.have.property("name").being.equal("Foo")
Exemplo n.º 38
0
 def opposite_not():
     assert this([1, 2, 3]).should_not.have.length_of(3)
Exemplo n.º 39
0
 def opposite():
     assert this(4).should.be.greater_than(5)
Exemplo n.º 40
0
 def opposite_not():
     assert this({}).should_not.be.empty
Exemplo n.º 41
0
 def opposite():
     assert this(('foo', 'bar', 'a', 'b')).should.have.length_of(1)
Exemplo n.º 42
0
 def opposite():
     assert this([3, 2, 1]).should.be.empty
Exemplo n.º 43
0
 def opposite_not():
     assert this(opposite).should_not.be.callable
Exemplo n.º 44
0
 def opposite():
     assert this("foo").should.be.callable
Exemplo n.º 45
0
 def wrong_should():
     return this(d3).should.be(d1)
Exemplo n.º 46
0
 def opposite_not():
     assert this(2).should_not.be.greater_than(1)
Exemplo n.º 47
0
 def wrong_should_not():
     return this(d2).should_not.be(d1)
Exemplo n.º 48
0
 def opposite():
     assert this(4).should.be.greater_than_or_equal_to(5)
Exemplo n.º 49
0
 def opposite():
     assert this(jay).should.have.property("name").not_being.equal(
         "John Doe")
Exemplo n.º 50
0
 def opposite_not():
     assert this(2).should_not.be.greater_than_or_equal_to(1)
Exemplo n.º 51
0
 def opposite():
     assert this(jay).should_not.have.key("name")
Exemplo n.º 52
0
 def opposite():
     assert this(5).should.be.lower_than(4)
Exemplo n.º 53
0
 def opposite_not():
     assert this(False).should_not.be.falsy
Exemplo n.º 54
0
 def opposite_not():
     assert this(1).should_not.be.lower_than(2)
Exemplo n.º 55
0
 def test_STATEFILE(self):
     this(self.state).should.have.property('statefile')
     the(self.state.statefile).should.be.a(str)
Exemplo n.º 56
0
 def opposite():
     assert this(5).should.be.lower_than_or_equal_to(4)
Exemplo n.º 57
0
 def test_state_init(self):
     this(self.state).should.have.property('config')
     this(self.state).should.have.property('proxyList')
     this(self.state).should.have.property('statefile')
Exemplo n.º 58
0
 def opposite_not():
     assert this(1).should_not.be.lower_than_or_equal_to(2)
Exemplo n.º 59
0
 def opposite():
     assert this(1).should_not.be.an(int)
Exemplo n.º 60
0
 def opposite_not():
     assert this(None).should_not.be.none