def test_purchase_choice_vpn(self):
        self.config = PlebNetConfig.get
        self.triblerwallet = TriblerWallet.__init__
        self.settings = plebnet_settings.Init.wallets_testnet_created
        self.purchase = azirevpn.AzireVpn.purchase
        self.logger = Logger.warning
        self.host = plebnet_settings.Init.vpn_host

        PlebNetConfig.get = MagicMock(side_effect=self.side_effect)
        plebnet_settings.Init.wallets_testnet_created = MagicMock(
            return_value=None)
        TriblerWallet.__init__ = MagicMock(return_value=None)
        azirevpn.AzireVpn.purchase = MagicMock(return_value=('Hash', 0))
        Logger.warning = MagicMock()
        plebnet_settings.Init.vpn_host = MagicMock(return_value='AzireVPN')

        self.assertEquals(cloudomate.purchase_choice_vpn(PlebNetConfig()),
                          plebnet_settings.SUCCESS)

        PlebNetConfig.get = self.config
        TriblerWallet.__init__ = self.triblerwallet
        plebnet_settings.Init.wallets_testnet_created = self.settings
        azirevpn.AzireVpn.purchase = self.purchase
        Logger.warning = self.logger
        plebnet_settings.Init.vpn_host = self.host
示例#2
0
def attempt_purchase_vpn():
    """
    Attempts to purchase a VPN, checks first if balance is sufficient
    The success message is stored to prevent further unecessary purchases.
    """
    provider = settings.vpn_host()
    if settings.wallets_testnet():
        domain = 'TBTC'
    else:
        domain = 'BTC'
    if market_controller.get_balance(
            domain) >= cloudomate_controller.calculate_price_vpn(provider):
        logger.log("Try to buy a new VPN from %s" % provider, log_name)
        success = cloudomate_controller.purchase_choice_vpn(config)
        if success == plebnet_settings.SUCCESS:
            logger.success("Purchasing VPN succesful!", log_name)
        elif success == plebnet_settings.FAILURE:
            logger.error("Error purchasing vpn", log_name)