def handle(self, *args, **options):
        connection.setup_connection_if_unset()
        connection.create_keyspace()
        ConfiguredCassandraUserModelClass = utils.get_cassandra_user_model()
        self.stdout.write('Sync-ing "{}"'.format(ConfiguredCassandraUserModelClass))
        management.sync_table(ConfiguredCassandraUserModelClass)

        self.stdout.write('Sync-ing "{}"'.format(session_models.CassandraSession))
        management.sync_table(session_models.CassandraSession)
Example #2
0
    def _create_user(self, username=None, auto_first_last_email=False, **kwargs):
        """
        Creates an user instance and inserts it in the database.
        The received 'kwargs' are passed to YourConfiguredUserModel.create()
        """
        ModelClass = utils.get_cassandra_user_model()

        if username is None:
            rnd = uuid.uuid4().hex[0:20]
            username = "******".format(rnd)

        if auto_first_last_email:
            kwargs['first_name'] = kwargs.get('first_name', "John '{}'".format(username))
            kwargs['last_name'] = kwargs.get('last_name', "Doe")
            kwargs['email'] = kwargs.get('email', "{}@example.com".format(username))

        cassandra_user = ModelClass.create(username=username, **kwargs)
        return cassandra_user
Example #3
0
def setup():
    """
    Setup connection, create keyspace and models.

    Use: call this in the 'setUpClass()' method of the base class of your unittests:

        class BaseTest(unittest.TestCase, tests_utils.PCassandraTestUtilsMixin):

            cassandra_connection_done = False

            @classmethod
            def setUpClass(cls):
                unittest.TestCase.setUpClass()
                if not cls.cassandra_connection_done:
                    tests_utils.PCassandraTestUtilsMixin._full_setup()
                    cls.cassandra_connection_done = True
    """
    setup_connection_and_create_keyspace()

    ModelClass = utils.get_cassandra_user_model()
    management.sync_table(ModelClass)
    def handle(self, *args, **options):
        connection.setup_connection_if_unset()

        ConfiguredCassandraUserModelClass = utils.get_cassandra_user_model()
        username = input("Enter the username: "******"Password: "******"Password (again): ")

        if password != password2:
            print("ERROR: password mismatch")
            sys.exit(1)

        user.username = username.strip()
        user.email = '{}@example.com'.format(username)
        user.set_password(username)
        user.is_staff = self.SUPERUSER
        user.is_superuser = self.SUPERUSER
        user.save()
        print("User '{}' created".format(username))
Example #5
0
 def _get_cassandra_user_model(cls):
     if not cls._CASSANDRA_USER_MODEL:
         cls._CASSANDRA_USER_MODEL = utils.get_cassandra_user_model()
     return cls._CASSANDRA_USER_MODEL