-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support mult-chain wallets in get_metadata calls (#46)
* Update requirements for new testing format * Add logic for new methods * Version bump Co-authored-by: Justin Herrera <justin@magic.link>
- Loading branch information
1 parent
9b7d51f
commit e37b143
Showing
7 changed files
with
192 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from magic_admin.resources.token import Token | ||
from magic_admin.resources.user import User | ||
from magic_admin.resources.wallet import WalletType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from enum import Enum | ||
|
||
|
||
class WalletType(Enum): | ||
ETH = 'ETH' | ||
HARMONY = 'HARMONY' | ||
ICON = 'ICON' | ||
FLOW = 'FLOW' | ||
TEZOS = 'TEZOS' | ||
ZILLIQA = 'ZILLIQA' | ||
POLKADOT = 'POLKADOT' | ||
SOLANA = 'SOLANA' | ||
AVAX = 'AVAX' | ||
ALGOD = 'ALGOD' | ||
COSMOS = 'COSMOS' | ||
CELO = 'CELO' | ||
BITCOIN = 'BITCOIN' | ||
NEAR = 'NEAR' | ||
HELIUM = 'HELIUM' | ||
CONFLUX = 'CONFLUX' | ||
TERRA = 'TERRA' | ||
TAQUITO = 'TAQUITO' | ||
ED = 'ED' | ||
HEDERA = 'HEDERA' | ||
NONE = 'NONE' | ||
ANY = 'ANY' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
VERSION = '0.0.5' | ||
VERSION = '0.1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,205 @@ | ||
from unittest import mock | ||
from unittest.mock import sentinel | ||
|
||
import pytest | ||
from pretend import stub | ||
|
||
from magic_admin.resources.user import User | ||
from magic_admin.resources.wallet import WalletType | ||
from testing.data.did_token import future_did_token | ||
from testing.data.did_token import issuer | ||
from testing.data.did_token import public_address | ||
|
||
|
||
class TestUser: | ||
|
||
metadata_with_wallets = stub( | ||
data=stub( | ||
email=sentinel.email, | ||
issuer=sentinel.issuer, | ||
public_address=sentinel.public_address, | ||
wallets=[ | ||
stub( | ||
network=sentinel.network, | ||
wallet_type=WalletType.ETH.value, | ||
public_address=sentinel.public_address_1, | ||
), | ||
stub( | ||
network=sentinel.network, | ||
wallet_type=WalletType.ETH.value, | ||
public_address=sentinel.public_address_2, | ||
), | ||
stub( | ||
network=sentinel.network, | ||
wallet_type=WalletType.ETH.value, | ||
public_address=sentinel.public_address_3, | ||
), | ||
], | ||
), | ||
error_code=sentinel.error_code, | ||
message=sentinel.message, | ||
status=sentinel.status, | ||
) | ||
|
||
metadata_no_wallets = stub( | ||
data=stub( | ||
email=sentinel.email, | ||
issuer=sentinel.issuer, | ||
public_address=sentinel.public_address, | ||
), | ||
error_code=sentinel.error_code, | ||
message=sentinel.message, | ||
status=sentinel.ok, | ||
) | ||
|
||
@pytest.fixture(autouse=True) | ||
def setup(self): | ||
self.user = User() | ||
self.user.Token = mock.Mock() | ||
|
||
@pytest.fixture | ||
def mock_get_metadata_by_issuer(self): | ||
with mock.patch.object( | ||
self.user, | ||
'get_metadata_by_issuer', | ||
) as mock_get_metadata_by_issuer: | ||
yield mock_get_metadata_by_issuer | ||
|
||
@pytest.fixture | ||
def mock_logout_by_issuer(self): | ||
with mock.patch.object( | ||
self.user, | ||
'logout_by_issuer', | ||
) as mock_logout_by_issuer: | ||
yield mock_logout_by_issuer | ||
|
||
@pytest.fixture | ||
def mock_construct_issuer_with_public_address(self): | ||
with mock.patch( | ||
def mock_construct_issuer_with_public_address(self, mocker): | ||
return mocker.patch( | ||
'magic_admin.resources.user.construct_issuer_with_public_address', | ||
) as mock_construct_issuer_with_public_address: | ||
yield mock_construct_issuer_with_public_address | ||
return_value=sentinel.public_address, | ||
) | ||
|
||
def test_get_metadata_by_issuer(self): | ||
with mock.patch.object( | ||
self.user, | ||
'request', | ||
) as mock_request: | ||
assert self.user.get_metadata_by_issuer(issuer) == mock_request.return_value | ||
self.user.get_metadata_by_issuer_and_wallet = mock.Mock( | ||
return_value=self.metadata_no_wallets, | ||
) | ||
|
||
assert self.user.get_metadata_by_issuer( | ||
sentinel.issuer, | ||
) == self.metadata_no_wallets | ||
|
||
self.user.get_metadata_by_issuer_and_wallet.assert_called_once_with( | ||
sentinel.issuer, | ||
WalletType.NONE, | ||
) | ||
|
||
def test_get_metadata_by_issuer_and_any_wallet(self): | ||
self.user.request = mock.Mock(return_value=self.metadata_with_wallets) | ||
|
||
mock_request.assert_called_once_with( | ||
assert self.user.get_metadata_by_issuer_and_wallet( | ||
sentinel.issuer, | ||
WalletType.ANY, | ||
) == self.metadata_with_wallets | ||
|
||
self.user.request.assert_called_once_with( | ||
'get', | ||
self.user.v1_user_info, | ||
params={'issuer': issuer}, | ||
params={ | ||
'issuer': sentinel.issuer, | ||
'wallet_type': WalletType.ANY, | ||
}, | ||
) | ||
|
||
def test_get_metadata_by_token(self): | ||
self.user.get_metadata_by_issuer = mock.Mock(return_value=self.metadata_no_wallets) | ||
|
||
assert self.user.get_metadata_by_token( | ||
future_did_token, | ||
) == self.user.get_metadata_by_issuer.return_value | ||
|
||
self.user.Token.get_issuer.assert_called_once_with(future_did_token) | ||
self.user.get_metadata_by_issuer.assert_called_once_with( | ||
self.user.Token.get_issuer.return_value, | ||
) | ||
|
||
def test_get_metadata_by_token_and_any_wallet(self): | ||
self.user.get_metadata_by_issuer_and_wallet = mock.Mock( | ||
return_value=self.metadata_with_wallets, | ||
) | ||
|
||
assert self.user.get_metadata_by_token_and_wallet( | ||
future_did_token, | ||
WalletType.ANY, | ||
) == self.user.get_metadata_by_issuer_and_wallet.return_value | ||
|
||
self.user.Token.get_issuer.assert_called_once_with(future_did_token) | ||
self.user.get_metadata_by_issuer_and_wallet.assert_called_once_with( | ||
self.user.Token.get_issuer.return_value, | ||
WalletType.ANY, | ||
) | ||
|
||
def test_get_metadata_by_public_address( | ||
self, | ||
mock_get_metadata_by_issuer, | ||
mock_construct_issuer_with_public_address, | ||
): | ||
self.user.get_metadata_by_issuer = mock.Mock(return_value=self.metadata_no_wallets) | ||
|
||
assert self.user.get_metadata_by_public_address( | ||
public_address, | ||
) == mock_get_metadata_by_issuer.return_value | ||
sentinel.public_address, | ||
) == self.user.get_metadata_by_issuer.return_value | ||
|
||
mock_construct_issuer_with_public_address.assert_called_once_with( | ||
public_address, | ||
sentinel.public_address, | ||
) | ||
mock_get_metadata_by_issuer.assert_called_once_with( | ||
self.user.get_metadata_by_issuer.assert_called_once_with( | ||
mock_construct_issuer_with_public_address.return_value, | ||
) | ||
|
||
def test_get_metadata_by_token(self, mock_get_metadata_by_issuer): | ||
self.user.Token = mock.Mock() | ||
def test_get_metadata_by_public_address_and_any_wallet( | ||
self, | ||
mock_construct_issuer_with_public_address, | ||
): | ||
self.user.get_metadata_by_issuer_and_wallet = mock.Mock( | ||
return_value=self.metadata_with_wallets, | ||
) | ||
|
||
assert self.user.get_metadata_by_token( | ||
future_did_token, | ||
) == mock_get_metadata_by_issuer.return_value | ||
assert self.user.get_metadata_by_public_address_and_wallet( | ||
sentinel.public_address, | ||
WalletType.ANY, | ||
) == self.user.get_metadata_by_issuer_and_wallet.return_value | ||
|
||
self.user.Token.get_issuer.assert_called_once_with(future_did_token) | ||
mock_get_metadata_by_issuer.assert_called_once_with( | ||
self.user.Token.get_issuer.return_value, | ||
mock_construct_issuer_with_public_address.assert_called_once_with( | ||
sentinel.public_address, | ||
) | ||
self.user.get_metadata_by_issuer_and_wallet.assert_called_once_with( | ||
mock_construct_issuer_with_public_address.return_value, | ||
WalletType.ANY, | ||
) | ||
|
||
def test_logout_by_issuer(self): | ||
with mock.patch.object( | ||
self.user, | ||
'request', | ||
) as mock_request: | ||
assert self.user.logout_by_issuer(issuer) == mock_request.return_value | ||
self.user.request = mock.Mock() | ||
|
||
assert self.user.logout_by_issuer( | ||
sentinel.issuer, | ||
) | ||
|
||
mock_request.assert_called_once_with( | ||
self.user.request.assert_called_once_with( | ||
'post', | ||
self.user.v2_user_logout, | ||
data={'issuer': issuer}, | ||
data={ | ||
'issuer': sentinel.issuer, | ||
}, | ||
) | ||
|
||
def test_logout_by_public_address( | ||
self, | ||
mock_logout_by_issuer, | ||
mock_construct_issuer_with_public_address, | ||
): | ||
self.user.logout_by_issuer = mock.Mock() | ||
|
||
assert self.user.logout_by_public_address( | ||
public_address, | ||
) == mock_logout_by_issuer.return_value | ||
) == self.user.logout_by_issuer.return_value | ||
|
||
mock_construct_issuer_with_public_address.assert_called_once_with( | ||
public_address, | ||
) | ||
mock_logout_by_issuer.assert_called_once_with( | ||
self.user.logout_by_issuer.assert_called_once_with( | ||
mock_construct_issuer_with_public_address.return_value, | ||
) | ||
|
||
def test_logout_by_token(self, mock_logout_by_issuer): | ||
self.user.Token = mock.Mock() | ||
def test_logout_by_token(self): | ||
self.user.logout_by_issuer = mock.Mock() | ||
|
||
assert self.user.logout_by_token( | ||
future_did_token, | ||
) == mock_logout_by_issuer.return_value | ||
) == self.user.logout_by_issuer.return_value | ||
|
||
self.user.Token.get_issuer.assert_called_once_with(future_did_token) | ||
mock_logout_by_issuer.assert_called_once_with( | ||
self.user.logout_by_issuer.assert_called_once_with( | ||
self.user.Token.get_issuer.return_value, | ||
) |