selenium: adding function to switch between 'test' and 'demo' base URLs,

used to introduce currency mismatches when testing errors management
This commit is contained in:
Marcello Stanisci 2016-05-03 15:05:58 +02:00
parent 048e4f8dc9
commit dc83b85e85

View File

@ -17,9 +17,10 @@ import time
import logging import logging
import sys import sys
import os import os
import re
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
taler_baseurl = os.environ['TALER_BASEURL'] if 'TALER_BASEURL' in os.environ else 'https://test.taler.net/' taler_baseurl = os.environ.get('TALER_BASEURL', 'https://test.taler.net/')
def client_setup(args): def client_setup(args):
"""Return a dict containing the driver and the extension's id""" """Return a dict containing the driver and the extension's id"""
@ -52,6 +53,17 @@ def is_error(client):
return False return False
def switch_base():
"""If 'test' is in TALER_BASEURL, then make it be 'demo', and viceversa.
Used to trig currency mismatch errors. It assumes that the https://{test,demo}.taler.net
layout is being used"""
global taler_baseurl
url = parse.urlparse(taler_baseurl)
if url[1] == 'test.taler.net':
taler_baseurl = "https://demo.taler.net"
if url[1] == 'demo.taler.net':
taler_baseurl = "https://test.taler.net"
def make_donation(client, amount_value=None): def make_donation(client, amount_value=None):
"""Make donation at shop.test.taler.net. Assume the wallet has coins""" """Make donation at shop.test.taler.net. Assume the wallet has coins"""
client.get(parse.urljoin(taler_baseurl, "shop")) client.get(parse.urljoin(taler_baseurl, "shop"))
@ -208,6 +220,7 @@ ret = client_setup(args)
client = ret['client'] client = ret['client']
client.implicitly_wait(10) client.implicitly_wait(10)
withdraw(client, 10) withdraw(client, 10)
switch_base() # inducing error
make_donation(client, 6.0) make_donation(client, 6.0)
buy_article(client) buy_article(client)
logger.info("Test passed") logger.info("Test passed")