def mockup(cls):
        cls.mockup_id_card = join(STUFF_DIR, 'test-image-1.jpg')
        cls.mockup_id_card_secondary = join(STUFF_DIR, 'test-image-2.png')

        iran = Country(name='Iran', code='ir', phone_prefix=98)
        tehran_state = State(name='Tehran', country=iran)
        tehran_city = City(name='Tehran', state=tehran_state)

        cls.session.add(tehran_city)

        admin1 = Admin()
        admin1.email = '*****@*****.**'
        admin1.password = '******'
        admin1.is_active = True
        cls.session.add(admin1)

        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        client1.is_email_verified = True
        client1.evidence.mobile_phone = '+77777777777'
        client1.evidence.fixed_phone = '+888888888'
        cls.session.add(client1)

        cls.session.commit()

        cls.city1_id = tehran_city.id
        cls.client1_id = client1.id
    def mockup(cls):
        cls.mockup_attachment1 = join(STUFF_DIR, 'test-image-1.jpg')
        cls.mockup_attachment2 = join(STUFF_DIR, 'test-image-2.png')

        admin1 = Admin()
        admin1.email = '*****@*****.**'
        admin1.password = '******'
        admin1.is_active = True
        cls.session.add(admin1)

        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        cls.session.add(client1)

        client2 = Client()
        client2.email = '*****@*****.**'
        client2.password = '******'
        client2.is_active = True
        client2.is_email_verified = True
        cls.session.add(client2)

        department1 = TicketDepartment(title='department-1')
        department2 = TicketDepartment(title='department-2')
        cls.session.add(department1)
        cls.session.add(department2)

        cls.session.commit()

        cls.mockup_department1_id = department1.id
        cls.mockup_admin1_id = admin1.id
        cls.mockup_client1_id = client1.id
        cls.mockup_client2_id = client2.id
    def mockup(cls):
        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        client1.is_email_verified = True
        cls.session.add(client1)

        cls.session.commit()

        cls.client1_id = client1.id

        cls.mockup_mobile_phone = '+119954395345'
        cls.valid_mobile_verification_code = '168875'
        cls.bad_mobile_verification_code = '101010'

        cls.mockup_fixed_phone = '+112159409435'
        cls.valid_fixed_verification_code = '200666'
        cls.bad_fixed_verification_code = '101010'
Example #4
0
    def mockup(cls):
        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        cls.session.add(client1)

        client2 = Client()
        client2.email = '*****@*****.**'
        client2.password = '******'
        client2.is_active = True
        client2.is_email_verified = True
        cls.session.add(client2)

        client3 = Client()
        client3.email = '*****@*****.**'
        client3.password = '******'
        client3.is_active = True
        cls.session.add(client3)

        cls.session.commit()

        cls.client1_id = client1.id
Example #5
0
    def mockup(cls):
        admin1 = Admin()
        admin1.email = '*****@*****.**'
        admin1.password = '******'
        admin1.is_active = True

        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        client1.is_email_verified = True
        client1.is_evidence_verified = True

        cls.session.add(admin1)
        cls.session.add(client1)

        usd = Fiat(symbol='USD', name='USA Dollar')

        cls.session.add(usd)

        cls.session.commit()

        cls.client1_id = client1.id
Example #6
0
    def mockup(cls):
        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        client1.is_email_verified = True
        client1.is_evidence_verified = True
        cls.session.add(client1)

        irr = Fiat(
            symbol='IRR',
            name='Iran Rial',
            normalization_scale=-5,
            smallest_unit_scale=-3,
        )
        cls.session.add(irr)

        # Adding a payment gateway
        shaparak = PaymentGateway()
        shaparak.name = "shaparak"
        shaparak.fiat_symbol = "IRR"
        shaparak.cashin_min = cashin_min
        shaparak.cashin_max = cashin_max
        shaparak.cashin_static_commission = cashin_static_commission
        shaparak.cashin_commission_rate = cashin_commission_rate
        shaparak.cashin_max_commission = cashin_max_commission
        cls.session.add(shaparak)

        shetab_address_1 = BankCard()
        shetab_address_1.pan = mockup_card_address
        shetab_address_1.holder = "Test Tester"
        shetab_address_1.client = client1
        shetab_address_1.fiat_symbol = "IRR"
        shetab_address_1.is_verified = True

        cls.session.add(shetab_address_1)

        cls.session.commit()

        cls.mockup_client_1_id = client1.id
        cls.mockup_shetab_address_1_id = shetab_address_1.id
        cls.mockup_payment_gateway_name = shaparak.name

        class MockStexchangeClient(StexchangeClient):
            def __init__(self, headers=None):
                super().__init__("", headers)
                self.mock_balance = ["0", "0"]

            def asset_list(self):
                return ujson.loads('[{"name": "IRR", "prec": 2}]')

            def balance_update(self, user_id, asset, business, business_id, change, detail):
                if user_id == cls.mockup_client_1_id and business == 'cashin' and asset == 'IRR':
                    self.mock_balance[0] = '{:.8f}'.format(Decimal(self.mock_balance[0]) + Decimal(change))
                return ujson.loads(
                    '{"IRR": {"available": "' +
                    self.mock_balance[0] +
                    '", "freeze": "' +
                    self.mock_balance[1] +
                    '"}}'
                )

            def balance_query(self, *args, **kwargs):
                return ujson.loads(
                    '{"IRR": {"available": "' +
                    self.mock_balance[0] +
                    '", "freeze": "' +
                    self.mock_balance[1] +
                    '"}}'
                )

        stexchange_client._set_instance(MockStexchangeClient())
Example #7
0
    def mockup(cls):
        admin1 = Admin()
        admin1.email = '*****@*****.**'
        admin1.password = '******'
        admin1.is_active = True
        cls.session.add(admin1)

        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        client1.is_email_verified = True
        client1.is_evidence_verified = True
        cls.session.add(client1)

        client2 = Client()
        client2.email = '*****@*****.**'
        client2.password = '******'
        client2.is_active = True
        client2.is_email_verified = True
        client2.is_evidence_verified = True
        cls.session.add(client2)

        irr = Fiat(
            symbol='IRR',
            name='Iran Rial',
        )
        cls.session.add(irr)

        # Adding a payment gateway
        shaparak = PaymentGateway()
        shaparak.name = "shaparak"
        shaparak.fiat_symbol = "IRR"
        shaparak.cashout_min = cashout_min
        shaparak.cashout_max = cashout_max
        shaparak.cashout_static_commission = cashout_static_commission
        shaparak.cashout_commission_rate = cashout_commission_rate
        shaparak.cashout_max_commission = cashout_max_commission
        cls.session.add(shaparak)

        # Mine, verified:
        sheba_address_1 = BankAccount()
        sheba_address_1.iban = 'IR123456789123456789123456'
        sheba_address_1.owner = "Client One"
        sheba_address_1.client = client1
        sheba_address_1.fiat_symbol = "IRR"
        sheba_address_1.is_verified = True

        # Mine, unverified:
        sheba_address_2 = BankAccount()
        sheba_address_2.iban = 'IR837498056254698443242343'
        sheba_address_2.owner = "Client One"
        sheba_address_2.client = client1
        sheba_address_2.fiat_symbol = "IRR"
        sheba_address_2.is_verified = False

        # Other's, verified:
        sheba_address_3 = BankAccount()
        sheba_address_3.iban = 'IR837498056254698443242343'
        sheba_address_3.owner = "Client Two"
        sheba_address_3.client = client2
        sheba_address_3.fiat_symbol = "IRR"
        sheba_address_3.is_verified = True

        for address in [sheba_address_1, sheba_address_2, sheba_address_3]:
            cls.session.add(address)

        cls.session.commit()

        cls.mockup_client_1_id = client1.id

        cls.mockup_sheba_address_verified_id = sheba_address_1.id
        cls.mockup_sheba_address_unverified_id = sheba_address_2.id
        cls.mockup_sheba_address_others_id = sheba_address_3.id
        cls.mockup_payment_gateway_name = shaparak.name

        class MockStexchangeClient(StexchangeClient):
            def __init__(self, headers=None):
                super().__init__("", headers)
                self.mock_balance = ["3001", "0"]

            def asset_list(self):
                return ujson.loads('[{"name": "IRR", "prec": 2}]')

            def balance_update(self, user_id, asset, business, business_id, change, detail):
                if user_id == cls.mockup_client_1_id and business in ['cashout', 'cashback'] and asset == 'IRR':
                    self.mock_balance[0] = '{:.8f}'.format(Decimal(change) + Decimal(self.mock_balance[0]))
                return ujson.loads(
                    '{"IRR": {"available": "' +
                    self.mock_balance[0] +
                    '", "freeze": "' +
                    self.mock_balance[1] +
                    '"}}'
                )

            def balance_query(self, *args, **kwargs):
                return ujson.loads(
                    '{"IRR": {"available": "' +
                    self.mock_balance[0] +
                    '", "freeze": "' +
                    self.mock_balance[1] +
                    '"}}'
                )

        stexchange_client._set_instance(MockStexchangeClient())
Example #8
0
    def mockup(cls):
        client1 = Client()
        client1.email = '*****@*****.**'
        client1.password = '******'
        client1.is_active = True
        client1.is_email_verified = True
        cls.session.add(client1)

        cls.session.flush()

        btc = Cryptocurrency(
            symbol='BTC',
            name='Bitcoin',
            wallet_id='BTC',
            withdraw_min=withdraw_min,
            withdraw_max=withdraw_max,
            withdraw_static_commission=withdraw_static_commission,
            withdraw_commission_rate=withdraw_commission_rate,
            withdraw_max_commission=withdraw_max_commission,
        )
        cls.session.add(btc)

        cls.session.commit()

        cls.mockup_client_1_id = client1.id

        class MockStexchangeClient(StexchangeClient):
            def __init__(self, headers=None):
                super().__init__("", headers)
                self.mock_balance = ["2200", "0"]

            def asset_list(self):
                return ujson.loads('[{"name": "BTC", "prec": 8}]')

            def balance_update(self, user_id, asset, business, business_id,
                               change, detail):
                if Decimal(change) < Decimal(0) and Decimal(
                        self.mock_balance[0]) + Decimal(change) < Decimal(0):
                    raise BalanceNotEnoughException(1)

                if user_id == cls.mockup_client_1_id and business == 'withdraw' and asset == 'BTC':
                    self.mock_balance[0] = '{:.8f}'.format(
                        Decimal(change) + Decimal(self.mock_balance[0]))
                return ujson.loads('{"BTC": {"available": "' +
                                   self.mock_balance[0] + '", "freeze": "' +
                                   self.mock_balance[1] + '"}}')

            def balance_query(self, *args, **kwargs):
                return ujson.loads('{"BTC": {"available": "' +
                                   self.mock_balance[0] + '", "freeze": "' +
                                   self.mock_balance[1] + '"}}')

        stexchange_client._set_instance(MockStexchangeClient())

        class MockStawalletClient(StawalletClient):
            def __init__(self, headers=None):
                super().__init__("", headers)
                self.mock_balance = ["0", "0"]

            # def get_wallets(self):
            #     return [{
            #         'id': '1',
            #         'balance': '1',
            #         'secret': '1',
            #         'onchainStatus': '1',
            #     }]

            def get_invoice(self, wallet_id, invoice_id):
                if wallet_id == 'BTC' and invoice_id == 1:
                    return ujson.loads("""
                                        {
                                          "id" : 1,
                                          "wallet" : "BTC",
                                          "extra" : null,
                                          "user" : "1",
                                          "creation" : "2019-03-19T12:11:10.337+03:00",
                                          "expiration" : null,
                                          "address" : {
                                            "id" : 2,
                                            "wallet" : "BTC",
                                            "address" : "1D6CqUvHtQRXU4TZrrj5j1iofo8f4oXyLj",
                                            "active" : true
                                          }
                                        } 
                                    """)

            def get_invoices(self, wallet_id, user_id):
                if wallet_id == 'BTC' and user_id == 1:
                    return ujson.loads("""
                                    [ 
                                        {
                                          "id" : 1,
                                          "wallet" : "BTC",
                                          "extra" : null,
                                          "user" : "1",
                                          "creation" : "2019-03-19T12:11:10.337+03:00",
                                          "expiration" : null,
                                          "address" : {
                                            "id" : 2,
                                            "wallet" : "BTC",
                                            "address" : "1D6CqUvHtQRXU4TZrrj5j1iofo8f4oXyLj",
                                            "active" : true
                                          }
                                        } 
                                    ]
                                    """)

            def post_invoice(self, wallet_id, user_id, force=False):
                if wallet_id == 'BTC' and user_id == 1:
                    if mock_address_usage[
                            '1D6CqUvHtQRXU4TZrrj5j1iofo8f4oXyLj']:
                        return ujson.loads("""
                                    [ 
                                        {
                                          "id" : 2,
                                          "wallet" : "BTC",
                                          "extra" : null,
                                          "user" : "1",
                                          "creation" : "2019-03-19T12:11:10.337+03:00",
                                          "expiration" : null,
                                          "address" : {
                                            "id" : 2,
                                            "wallet" : "BTC",
                                            "address" : "1AJbsFZ64EpEfS5UAjAfcUG8pH8Jn3rn1F",
                                            "active" : true
                                          }
                                        } 
                                    ]
                                    """)
                    else:
                        raise StawalletHttpException(409, {})

            def get_deposits(self, wallet_id, user_id, page=0):
                if wallet_id == 'BTC' and user_id == 1:
                    if mock_address_usage[
                            '1D6CqUvHtQRXU4TZrrj5j1iofo8f4oXyLj']:
                        return ujson.loads("""
                                        [{
                                          "id" : 1,
                                          "invoice" : {
                                            "id" : 1,
                                            "wallet" : "BTC",
                                            "extra" : null,
                                            "user" : "1",
                                            "creation" : "2019-03-19T12:38:11.310+03:00",
                                            "expiration" : null,
                                            "address" : {
                                              "id" : 2,
                                              "wallet" : "BTC",
                                              "address" : "1D6CqUvHtQRXU4TZrrj5j1iofo8f4oXyLj",
                                              "active" : true
                                            }
                                          },
                                          "grossAmount" : 198763,
                                          "netAmount" : 198000,
                                          "proof" : {
                                            "txHash" : "5061556f857e118aae8d948496f61f645e12cf7ca2a107f8e4ae78b535e86dfb",
                                            "blockHash" : "000000000000000000188252ee9277e8f60482a91b7f3cc9a4a7fb75ded482a8",
                                            "blockHeight" : 562456,
                                            "confirmationsLeft" : 0,
                                            "confirmationsTrace" : [ ],
                                            "link" : "https://www.blockchain.com/btc/tx/5061556f857e118aae8d948496f61f645e12cf7ca2a107f8e4ae78b535e86dfb",
                                            "extra" : null,
                                            "error" : null
                                          },
                                          "status" : "ACCEPTED",
                                          "extra" : null,
                                          "confirmed" : true
                                        }]""")
                    else:
                        return ujson.loads("[]")

            def get_deposit(self, wallet_id, deposit_id):
                if wallet_id == 'BTC' and deposit_id == 1:
                    if mock_address_usage[
                            '1D6CqUvHtQRXU4TZrrj5j1iofo8f4oXyLj']:
                        return ujson.loads("""
                                        {
                                          "id" : 1,
                                          "invoice" : {
                                            "id" : 1,
                                            "wallet" : "BTC",
                                            "extra" : null,
                                            "user" : "1",
                                            "creation" : "2019-03-19T12:38:11.310+03:00",
                                            "expiration" : null,
                                            "address" : {
                                              "id" : 2,
                                              "wallet" : "BTC",
                                              "address" : "1D6CqUvHtQRXU4TZrrj5j1iofo8f4oXyLj",
                                              "active" : true
                                            }
                                          },
                                          "grossAmount" : 198763,
                                          "netAmount" : 198000,
                                          "proof" : {
                                            "txHash" : "5061556f857e118aae8d948496f61f645e12cf7ca2a107f8e4ae78b535e86dfb",
                                            "blockHash" : "000000000000000000188252ee9277e8f60482a91b7f3cc9a4a7fb75ded482a8",
                                            "blockHeight" : 562456,
                                            "confirmationsLeft" : 0,
                                            "confirmationsTrace" : [ ],
                                            "link" : "https://www.blockchain.com/btc/tx/5061556f857e118aae8d948496f61f645e12cf7ca2a107f8e4ae78b535e86dfb",
                                            "extra" : null,
                                            "error" : null
                                          },
                                          "status" : "ACCEPTED",
                                          "extra" : null,
                                          "confirmed" : true
                                        }""")

            def get_withdraws(self, wallet_id, user_id, page=0):
                if wallet_id == 'BTC' and user_id == 1:
                    return ujson.loads("""
                        [ {
                          "id" : 1,
                          "businessUid" : "abc-def-gh",
                          "wallet" : "test-btc-wallet",
                          "user" : "1",
                          "target" : "1Mwz1i3MK7AruNFwF3X84FK4qMmpooLtZG",
                          "netAmount" : 65020000,
                          "grossAmount" : 65740000,
                          "estimatedNetworkFee" : 50000,
                          "finalNetworkFee" : null,
                          "type" : "withdraw",
                          "status" : "queued",
                          "txid" : null,
                          "proof" : null,
                          "issuedAt" : "2019-03-20T12:55:46.390+03:00",
                          "paidAt" : null,
                          "trace" : null,
                          "manual" : true
                        } ]""")

            def get_withdraw(self, wallet_id, withdraw_id):
                return ujson.loads("""
                    {
                      "id" : 1,
                      "businessUid" : "abc-def-gh",
                      "wallet" : "test-btc-wallet",
                      "user" : "1",
                      "target" : "2N2sn7skY9ZcDph2ougMdKn9a7tFj9ADhNV",
                      "netAmount" : 65020000,
                      "grossAmount" : 65740000,
                      "estimatedNetworkFee" : 50000,
                      "finalNetworkFee" : null,
                      "type" : "withdraw",
                      "status" : "queued",
                      "txid" : null,
                      "proof" : null,
                      "issuedAt" : "2019-03-20T12:54:44.009+03:00",
                      "paidAt" : null,
                      "trace" : null,
                      "manual" : true
                    }""")

            def schedule_withdraw(self,
                                  wallet_id,
                                  user_id,
                                  business_uid,
                                  is_manual: bool,
                                  destination_address,
                                  amount_to_be_withdrawed,
                                  withdrawal_fee,
                                  estimated_network_fee,
                                  is_decharge=False):
                mock_business_uid_usage['abc-def-gh'] = True
                return ujson.loads("""{
                      "id" : 2,
                      "businessUid" : "abc-def-gh",
                      "wallet" : "test-btc-wallet",
                      "user" : "1",
                      "target" : "2N2sn7skY9ZcDph2ougMdKn9a7tFj9ADhNV",
                      "netAmount" : 2000,
                      "grossAmount" : 2175,
                      "estimatedNetworkFee" : 0,
                      "finalNetworkFee" : null,
                      "type" : "withdraw",
                      "status" : "queued",
                      "txid" : null,
                      "proof" : null,
                      "issuedAt" : "2019-03-20T12:52:26.948+03:00",
                      "paidAt" : null,
                      "trace" : "2019-03-20T12:52:38.228+03:00 : Issued (automatic)",
                      "manual" : true
                    }""")

            def edit_withdraw(self, wallet_id, withdraw_id, is_manual: bool):
                return ujson.loads("""
                    {
                      "id" : 2,
                      "businessUid" : "abc-def-gh",
                      "wallet" : "test-btc-wallet",
                      "user" : "1",
                      "target" : "2N2sn7skY9ZcDph2ougMdKn9a7tFj9ADhNV",
                      "netAmount" : 93511223,
                      "grossAmount" : 93583223,
                      "estimatedNetworkFee" : 485385,
                      "finalNetworkFee" : null,
                      "type" : "withdraw",
                      "status" : "waiting_manual",
                      "txid" : null,
                      "proof" : null,
                      "issuedAt" : "2019-03-20T12:52:26.948+03:00",
                      "paidAt" : null,
                      "trace" : "2019-03-20T12:52:38.228+03:00 : Issued (automatic)\n2019-03-20T12:53:28.001+03:00 : Change to manual",
                      "manual" : true
                    }""")

            def resolve_withdraw(self, wallet_id, withdraw_id,
                                 final_network_fee, transaction_hash: str):
                return ujson.loads("""
                    {
                      "id" : 2,
                      "businessUid" : "abc-def-gh",
                      "wallet" : "test-btc-wallet",
                      "user" : "1",
                      "target" : "2N2sn7skY9ZcDph2ougMdKn9a7tFj9ADhNV",
                      "netAmount" : 93511223,
                      "grossAmount" : 93583223,
                      "estimatedNetworkFee" : 485385,
                      "finalNetworkFee" : 485385,
                      "type" : "withdraw",
                      "status" : "pushed",
                      "txid" : "b6f6991d03df0e2e04dafffcd6bc418aac66049e2cd74b80f14ac86db1e3f0da",
                      "proof" : null,
                      "issuedAt" : "2019-03-20T12:52:26.948+03:00",
                      "paidAt" : "2019-03-20T12:54:08.547+03:00",
                      "trace" : "2019-03-20T12:52:38.228+03:00 : Issued (automatic)\n2019-03-20T12:53:28.001+03:00 : Change to manual\n2019-03-20T12:54:08.547+03:00 : Submit manual withdrawal info",
                      "manual" : null
                    }""")

            def quote_withdraw(self, wallet_id, user_id, business_uid,
                               destination_address, amount):
                return ujson.loads(
                    """
                {
                  "estimatedNetworkFee" : 0,
                  "hasSufficientWalletBalance" : true,
                  "estimatedSendingTime" : 0,
                  "estimatedReceivingTime" : 0,
                  "errors" : [ ],
                  "addressValid" : """ +
                    str(len(destination_address) >= 30).lower() + """,
                  "networkUp" : true,
                  "sendingManually" : false,
                  "userEligible" : true,
                  "businessUidDuplicated" : """ +
                    str(mock_business_uid_usage['abc-def-gh']).lower() + """,
                  "businessUidValid" : true,
                  "amountValid" : true
                }""")

        stawallet_client._set_instance(MockStawalletClient())