Esempio n. 1
0
    def testConstructor(self):
        flexmock(file_io) \
            .should_receive('read') \
            .and_return('127.0.0.1')

        flexmock(Cluster).should_receive('connect').\
            and_return(flexmock(execute=lambda x: None))

        db = cassandra_interface.DatastoreProxy()
Esempio n. 2
0
    def testConstructor(self):
        flexmock(helper_functions) \
            .should_receive('read_file') \
            .and_return('127.0.0.1')

        flexmock(pycassa).should_receive("ConnectionPool") \
            .and_return(FakePool())

        db = cassandra_interface.DatastoreProxy()
Esempio n. 3
0
def primed():
    """ Check if the required keyspace and tables are present.

  Returns:
    A boolean indicating that Cassandra has been primed.
  """
    try:
        db_access = cassandra_interface.DatastoreProxy()
    except cassandra.InvalidRequest:
        return False
    return db_access.get_metadata(cassandra_interface.PRIMED_KEY) == 'true'
Esempio n. 4
0
    def testGet(self):
        flexmock(helper_functions) \
            .should_receive('read_file') \
            .and_return('127.0.0.1')

        flexmock(pycassa).should_receive("ConnectionPool") \
            .and_return(FakePool())

        db = cassandra_interface.DatastoreProxy()

        # Make sure no exception is thrown
        assert {} == db.batch_get_entity('table', [], [])
Esempio n. 5
0
    def testRangeQuery(self):
        flexmock(helper_functions) \
            .should_receive('read_file') \
            .and_return('127.0.0.1')

        flexmock(pycassa) \
            .should_receive("ColumnFamily") \
            .and_return(FakeColumnFamily())

        db = cassandra_interface.DatastoreProxy()

        assert [] == db.range_query("table", [], "start", "end", 0)
Esempio n. 6
0
    def testRangeQuery(self):
        flexmock(file_io) \
            .should_receive('read') \
            .and_return('127.0.0.1')

        flexmock(Cluster).should_receive('connect').\
            and_return(flexmock(execute=lambda x, **y: []))

        db = cassandra_interface.DatastoreProxy()

        self.assertListEqual([], db.range_query("table", [], "start", "end",
                                                0))
Esempio n. 7
0
    def testDeleteTable(self):
        flexmock(file_io) \
            .should_receive('read') \
            .and_return('127.0.0.1')

        flexmock(Cluster).should_receive('connect').\
            and_return(flexmock(execute=lambda x: None))

        db = cassandra_interface.DatastoreProxy()

        # Make sure no exception is thrown
        db.delete_table('table')
Esempio n. 8
0
    def testGet(self):
        flexmock(file_io) \
            .should_receive('read') \
            .and_return('127.0.0.1')

        flexmock(Cluster).should_receive('connect').\
            and_return(flexmock(execute=lambda x, **y: []))

        db = cassandra_interface.DatastoreProxy()

        # Make sure no exception is thrown
        assert {} == db.batch_get_entity('table', [], [])
Esempio n. 9
0
    def testDeleteTable(self):
        flexmock(helper_functions) \
            .should_receive('read_file') \
            .and_return('127.0.0.1')

        flexmock(pycassa.system_manager) \
            .should_receive("SystemManager") \
            .and_return(FakeSystemManager())

        db = cassandra_interface.DatastoreProxy()

        # Make sure no exception is thrown
        db.delete_table('table')
Esempio n. 10
0
    def testPut(self):
        flexmock(helper_functions) \
            .should_receive('read_file') \
            .and_return('127.0.0.1')

        flexmock(pycassa) \
            .should_receive("ColumnFamily") \
            .and_return(FakeColumnFamily())

        db = cassandra_interface.DatastoreProxy()

        # Make sure no exception is thrown
        assert None == db.batch_put_entity('table', [], [], {})
Esempio n. 11
0
    def testPut(self):
        flexmock(file_io) \
            .should_receive('read') \
            .and_return('127.0.0.1')

        session = flexmock(prepare=lambda x: '', execute=lambda x: None)
        flexmock(BatchStatement).should_receive('add')
        flexmock(Cluster).should_receive('connect').\
            and_return(session)

        db = cassandra_interface.DatastoreProxy()

        # Make sure no exception is thrown
        assert None == db.batch_put_entity('table', [], [], {})
Esempio n. 12
0
def primed():
    """ Check if the required keyspace and tables are present.

  Returns:
    A boolean indicating that Cassandra has been primed.
  """
    try:
        db_access = cassandra_interface.DatastoreProxy()
    except cassandra.InvalidRequest:
        return False

    try:
        primed_version = db_access.get_metadata(cassandra_interface.PRIMED_KEY)
        return primed_version == str(CURRENT_VERSION)
    finally:
        db_access.close()
Esempio n. 13
0
 def setUp(self):
     self.cass = cassandra_interface.DatastoreProxy()
     self.cass.create_table(TEST3_TABLE, TEST3_TABLE_SCHEMA)