Ejemplo 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()
Ejemplo n.º 2
0
    def test_batch_mutate(self):
        app_id = 'guestbook'
        transaction = 1
        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()

        db.batch_mutate(app_id, [], [], transaction)
Ejemplo n.º 3
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))
Ejemplo n.º 4
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')
Ejemplo n.º 5
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', [], [])
Ejemplo n.º 6
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', [], [], {})
Ejemplo n.º 7
0
    def setUp(self, *args, **kwargs):
        super(TestCassandra, self).setUp(*args, **kwargs)
        # Prepare patchers
        self.read_patcher = mock.patch.object(file_io, 'read')
        self.execute_patcher = mock.patch.object(
            cassandra_interface.TornadoCassandra, 'execute')
        self.cluster_class_patcher = mock.patch.object(cassandra_interface,
                                                       'Cluster')

        # Start patches
        self.read_mock = self.read_patcher.start()
        self.execute_mock = self.execute_patcher.start()
        self.cluster_class_mock = self.cluster_class_patcher.start()

        # Configure mocks
        self.read_mock.return_value = '127.0.0.1'
        self.session_mock = mock.MagicMock()
        self.connect_mock = mock.MagicMock(return_value=self.session_mock)
        self.cluster_mock = mock.MagicMock(connect=self.connect_mock)
        self.cluster_class_mock.return_value = self.cluster_mock

        # Instantiate Datastore proxy
        self.db = cassandra_interface.DatastoreProxy()
Ejemplo n.º 8
0
 def setUp(self):
     self.cass = cassandra_interface.DatastoreProxy()
     self.cass.create_table(TEST3_TABLE, TEST3_TABLE_SCHEMA)