Example #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)
Example #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")
Example #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)
Example #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)
Example #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'))
 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(['*****@*****.**', '*****@*****.**'])
Example #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")
Example #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',
    )
Example #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'")
Example #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)
Example #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'"))
Example #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)
 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)
Example #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)
Example #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')
 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)
 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)
Example #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")
Example #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)
Example #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"*****@*****.**"}])
Example #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)
Example #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)
Example #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")
Example #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')
Example #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")
Example #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)
Example #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")
Example #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")
Example #31
0
 def opposite_not():
     assert this([]).should_not.be.a('list')
 def test_persistent_getState(self):
     persistent.should.have.property('_getState').being(callable)
     this(persistent._getState()).should.be.a(persistent.State)
 def test_optionsCreation(self):
     this(self.options).should.be.ok
     this(self.options).should.be.a(dict)
Example #34
0
 def opposite():
     assert this("cool").should.be.none
Example #35
0
 def opposite():
     assert this(True).should.be.falsy
Example #36
0
 def opposite_not():
     assert this(jay).should.have.property("age")
Example #37
0
 def opposite_not():
     assert this(jay).should.have.property("name").being.equal("Foo")
Example #38
0
 def opposite_not():
     assert this([1, 2, 3]).should_not.have.length_of(3)
Example #39
0
 def opposite():
     assert this(4).should.be.greater_than(5)
Example #40
0
 def opposite_not():
     assert this({}).should_not.be.empty
Example #41
0
 def opposite():
     assert this(('foo', 'bar', 'a', 'b')).should.have.length_of(1)
Example #42
0
 def opposite():
     assert this([3, 2, 1]).should.be.empty
Example #43
0
 def opposite_not():
     assert this(opposite).should_not.be.callable
Example #44
0
 def opposite():
     assert this("foo").should.be.callable
Example #45
0
 def wrong_should():
     return this(d3).should.be(d1)
Example #46
0
 def opposite_not():
     assert this(2).should_not.be.greater_than(1)
Example #47
0
 def wrong_should_not():
     return this(d2).should_not.be(d1)
Example #48
0
 def opposite():
     assert this(4).should.be.greater_than_or_equal_to(5)
Example #49
0
 def opposite():
     assert this(jay).should.have.property("name").not_being.equal(
         "John Doe")
Example #50
0
 def opposite_not():
     assert this(2).should_not.be.greater_than_or_equal_to(1)
Example #51
0
 def opposite():
     assert this(jay).should_not.have.key("name")
Example #52
0
 def opposite():
     assert this(5).should.be.lower_than(4)
Example #53
0
 def opposite_not():
     assert this(False).should_not.be.falsy
Example #54
0
 def opposite_not():
     assert this(1).should_not.be.lower_than(2)
 def test_STATEFILE(self):
     this(self.state).should.have.property('statefile')
     the(self.state.statefile).should.be.a(str)
Example #56
0
 def opposite():
     assert this(5).should.be.lower_than_or_equal_to(4)
 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')
Example #58
0
 def opposite_not():
     assert this(1).should_not.be.lower_than_or_equal_to(2)
Example #59
0
 def opposite():
     assert this(1).should_not.be.an(int)
Example #60
0
 def opposite_not():
     assert this(None).should_not.be.none