def test_api_instantiates_api_class_with_configured_settings(self):
        random_login = "******" % random.randint(100, 200)
        random_key = "some random key %d" % random.randint(100, 200)
        random_return = "some random return %d" % random.randint(100, 200)
        settings = fudge.Fake()
        settings.has_attr(AUTHORIZE={
            "LOGIN": random_login,
            "KEY": random_key,
        })
        api_class = fudge.Fake()

        # Note that delimiter is included here because authorize's code
        # can't even keep track of what deliminter it wants to use!
        (api_class.expects_call()
                .with_args(random_login, random_key, delimiter=u"|")
                .returns(random_return))
        fudge.clear_calls()

        backend = backends.AuthorizeNetBackend(api_class=api_class,
                settings=settings)
        result = backend.get_api()
        self.assertEqual(result, random_return)
        fudge.verify()
from django.conf import settings
from itertools import cycle


"""
The slave database is selected in a round-robin pattern. If there are no slave databases listed, we will use master
for all operations.

Slave databases are defined in settings.SLAVE_DATABASES as a tuple of the slave database connection names.
Master database is defined in settings.MASTER_DATABASE, which by default is 'default'.
"""
HAS_SLAVES = False
if settings.has_attr('SLAVE_DATABASES'):
    HAS_SLAVES = True
    SLAVE_DATABASE = cycle(settings.SLAVE_DATABASES)

if settings.has_attr('MASTER_DATABASE'):
    MASTER_DATABASE = settings.MASTER_DATABASE
else:
    MASTER_DATABASE = 'default'


class MasterSlaveRouter(object):
    """
    A simple database router that directs all reads to the slave database(s) and writes to the master.
    If there are multiple slave databases, it will select them in a round-robin pattern.
    """
    def db_for_read(self, *args):
        """
        Decides which database is to be selected for the read operation.
        """
def create_backend_with_settings(step):
    settings = fudge.Fake()
    settings.has_attr(testable_backends = "%s.SecondBackend" % \
            SecondBackend.__module__)

    world.backend = GenericBackend("testable_backends", settings=settings)