"""Tests for handler utilities.""" from artist.constants import headers as headers_constants from artist.utils import handler_util def test_extract_subaccount_id_account_id_same(): """Test that the value of subaccount_id/account_id is returned. Should be returned when the two values are the same. """ assert handler_util.extract_subaccount_id( subaccount_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_SUBACCOUNT, account_id=123 ) == 123 def test_extract_subaccount_id_account_id_none(): """Test that the explicit subaccount id is returned. Should be returned when the value of account id is empty and the account type is subaccount. """ assert handler_util.extract_subaccount_id( subaccount_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_SUBACCOUNT, account_id=None ) == 123 def test_extract_subaccount_id_account_id_different(): """Test that the explicit subaccount id is returned. Should be returned when the value of account id is different. """ assert handler_util.extract_subaccount_id( subaccount_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_SUBACCOUNT, account_id=456 ) == 123 def test_extract_subaccount_id_none_account_id_different(): """Test that the account id is returned. Should be returned when the explicit subaccount id is empty. """ assert handler_util.extract_subaccount_id( subaccount_id=None, account_type=headers_constants.GRASS_ACCOUNT_TYPE_SUBACCOUNT, account_id=123 ) == 123 def test_extract_subaccount_id_none_different_account_type(): """Test that the account id is ignored. Should be ignored if the account type is not "subaccount". """ assert handler_util.extract_subaccount_id( subaccount_id=None, account_type=headers_constants.GRASS_ACCOUNT_TYPE_VENDOR, account_id=123 ) is None def test_extract_subaccount_id_when_no_account_type(): """Test that the subaccount is returned. Should be returned if the account_type is notpassed. """ assert handler_util.extract_subaccount_id( subaccount_id=123, account_type=None, account_id=183 ) == 123 def test_extract_subaccount_id_account_type_vendor(): """Test that the subaccount id is returned. Should be returned if account type is passed but is not subaccount. """ assert handler_util.extract_subaccount_id( subaccount_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_VENDOR, account_id=183 ) == 123 # TESTS FOR extract_vendor_id def test_extract_vendor_id_account_id_same(): """Test that the value of vendor_id/account_id is returned. Should be returned when the two values are the same. """ assert handler_util.extract_vendor_id( vendor_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_VENDOR, account_id=123 ) == 123 def test_extract_vendor_id_account_id_none(): """Test that the explicit vendor id is returned. Should be returned when the account id is empty and the account type is vendor. """ assert handler_util.extract_vendor_id( vendor_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_VENDOR, account_id=None ) == 123 def test_extract_vendor_id_account_id_different(): """Test that the explicit vendor is used. Should be used if the account id is different and the account type is vendor. """ assert handler_util.extract_vendor_id( vendor_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_VENDOR, account_id=456 ) == 123 def test_extract_vendor_id_account_id_none_account_id_different(): """Test that the account id is returned. Should be returned if the explicit vendor id is empty and account type is vendor. """ assert handler_util.extract_vendor_id( vendor_id=None, account_type=headers_constants.GRASS_ACCOUNT_TYPE_VENDOR, account_id=123 ) == 123 def test_extract_vendor_id_account_id_none_different_account_type(): """Test that the empty explicit vendor id is returned. Should be returned if the account type is not subaccount. """ assert handler_util.extract_vendor_id( vendor_id=None, account_type=headers_constants.GRASS_ACCOUNT_TYPE_SUBACCOUNT, account_id=123 ) is None def test_extract_vendor_id_when_no_account_type(): """Test that the vendor id is returned. Should be returned if the account_type is not passed. """ assert handler_util.extract_vendor_id( vendor_id=123, account_type=None, account_id=183 ) == 123 def test_extract_vendor_id_account_type_vendor(): """Test that the vendor id is returned. Should be returned if account type is passed but is not vendor. """ assert handler_util.extract_vendor_id( vendor_id=123, account_type=headers_constants.GRASS_ACCOUNT_TYPE_SUBACCOUNT, account_id=183 ) == 123