Пример #1
0
    def test_get_one_result(self):
        self.mock_cass.get_slice.return_value = defer.Deferred()
        self.mock_cass.get.return_value = defer.Deferred()
        self.handler.finish = mock.MagicMock()
        self.request.arguments = {}
        self.handler.get("sip:pub")
        self.mock_cass.get_slice.assert_called_once_with(
            column_family=config.PRIVATE_IDS_TABLE, key='sip:pub')
        result_list = [
            ColumnOrSuperColumn(column=Column(timestamp=1371131096949743,
                                              name='priv',
                                              value='priv',
                                              ttl=None),
                                counter_super_column=None,
                                super_column=None,
                                counter_column=None)
        ]

        # set the 2nd mock cass
        rv = self.mock_cass.get_slice.return_value
        self.mock_cass.reset_mock()
        self.mock_cass.get_slice.return_value = defer.Deferred()
        rv.callback(result_list)

        self.mock_cass.get_slice.assert_called_once_with(
            column_family=config.PUBLIC_IDS_TABLE, key='priv')
        result_list = [
            ColumnOrSuperColumn(column=Column(timestamp=1371131096949743,
                                              name='sip:pub',
                                              value='sip:pub',
                                              ttl=None),
                                counter_super_column=None,
                                super_column=None,
                                counter_column=None)
        ]

        self.mock_cass.get_slice.return_value.callback(result_list)

        self.assertTrue(self.handler.finish.called)
        self.assertEquals(self.handler.get_status(), httplib.OK)
        self.assertEquals(self.handler.finish.call_args[0][0],
                          {"public_ids": ["sip:pub"]})
Пример #2
0
 def test_put_multi_ims_subscription(self):
     """Test multiple IMS subscriptions can be put into the cache"""
     self.cass_client.batch_mutate.return_value = batch_mutate = defer.Deferred(
     )
     res = Result(
         self.cache.put_multi_ims_subscription(["pub1", "pub2"],
                                               "xml",
                                               ttl=self.ttl,
                                               timestamp=self.timestamp))
     row = {
         "impu": [
             Column("ims_subscription_xml", "xml", self.timestamp,
                    self.ttl),
             Column("_exists", "", self.timestamp, self.ttl)
         ]
     }
     self.cass_client.batch_mutate.assert_called_once_with(
         {
             "pub1": row,
             "pub2": row
         },
         consistency=ConsistencyLevel.LOCAL_QUORUM)
     batch_mutate.callback(None)
     self.assertEquals(res.value(), None)
Пример #3
0
    def test_user_wrong_association(self):
        self.mock_cass.get_slice.return_value = defer.Deferred()
        self.mock_cass.get.return_value = defer.Deferred()
        self.handler.finish = mock.MagicMock()
        get_deferred = self.handler.get("priv", "pub")
        get_errback = mock.MagicMock()
        get_deferred.addErrback(get_errback)

        # Expect a call to validate the pub/priv
        self.mock_cass.get_slice.assert_called_once_with(column_family=config.PUBLIC_IDS_TABLE, key='priv', start='pub', finish='pub')
        result_list = [
             ColumnOrSuperColumn(column=Column(timestamp=1371131096949743,
            name='pub2', value='pub2', ttl=None), counter_super_column=None,
            super_column=None, counter_column=None)]
        self.mock_cass.get_slice.return_value.callback(result_list)

        self.assertEquals(get_errback.call_args[0][0].getErrorMessage(), 'HTTP 404: Not Found')
Пример #4
0
 def side_effect_slice(column_family, key):
     if (column_family == config.PUBLIC_IDS_TABLE and key == 'priv'):
         return ([
             ColumnOrSuperColumn(column=Column(
                 timestamp=1371131096949743,
                 name='sip:pub',
                 value='sip:pub',
                 ttl=None),
                                 counter_super_column=None,
                                 super_column=None,
                                 counter_column=None)
         ])
     elif (column_family == config.PRIVATE_IDS_TABLE
           and key == 'sip:pub2'):
         return []
     else:
         raise Exception('FAIL')
Пример #5
0
    def test_post_add_first_entry(self):
        self.mock_cass.get_slice.return_value = defer.Deferred()
        self.handler.finish = mock.MagicMock()
        self.request.arguments = {'private_id': 'priv'}

        self.handler.post("sip:pub")
        # get_slice to check if it exists
        self.mock_cass.get_slice.assert_called_once_with(
            column_family=config.PUBLIC_IDS_TABLE,
            key='priv',
            start='sip:pub',
            finish='sip:pub')

        rv = self.mock_cass.get_slice.return_value
        self.mock_cass.reset_mock()

        # Prepare for 2x get-slice calls to check for limits
        def side_effect_slice(column_family, key):
            if (column_family == config.PUBLIC_IDS_TABLE and key == 'priv'):
                return []
            elif (column_family == config.PRIVATE_IDS_TABLE
                  and key == 'sip:pub'):
                return []
            else:
                raise Exception('FAIL')

        self.mock_cass.get_slice.side_effect = side_effect_slice
        self.mock_cass.insert.return_value = defer.Deferred()

        rv.callback([])  # The callback on the original get_slice
        # This will trigger the 2 get_slices, and then
        # the two inserts

        # Restore the get_slice mock in in advance of the final call on it.
        self.mock_cass.get_slice.return_value = defer.Deferred()
        self.mock_cass.get_slice.side_effect = None

        self.mock_cass.insert.assert_has_calls([
            call(column_family=config.PUBLIC_IDS_TABLE,
                 key='priv',
                 column='sip:pub',
                 value='sip:pub'),
            call(column_family=config.PRIVATE_IDS_TABLE,
                 key='sip:pub',
                 column='priv',
                 value='priv')
        ],
                                               any_order=True)

        self.mock_cass.reset_mock()
        self.mock_cass.insert.return_value.callback(mock.MagicMock())

        # get_slice public IDs, key=priv to get returned data
        self.mock_cass.get_slice.assert_called_once_with(
            column_family=config.PRIVATE_IDS_TABLE, key='sip:pub')

        result_list = [
            ColumnOrSuperColumn(column=Column(timestamp=1371131096949743,
                                              name='priv',
                                              value='priv',
                                              ttl=None),
                                counter_super_column=None,
                                super_column=None,
                                counter_column=None)
        ]
        self.mock_cass.get_slice.return_value.callback(result_list)

        self.assertTrue(self.handler.finish.called)
        self.assertEquals(self.handler.get_status(), httplib.CREATED)
        self.assertEquals(self.handler.finish.call_args[0][0], {
            "public_id": "sip:pub",
            "private_ids": ["priv"]
        })
Пример #6
0
def dostuff(client):
    yield client.insert(key='test',
                        column_family=CF,
                        value='testval',
                        column=colname)
    yield client.insert(key='test',
                        column_family=SCF,
                        value='testval',
                        column=colname,
                        super_column=scname)

    res = yield client.get(key='test', column_family=CF, column=colname)
    print 'get', res

    res = yield client.get(key='test',
                           column_family=SCF,
                           column=colname,
                           super_column=scname)
    print 'get (super)', res

    res = yield client.get_slice(key='test', column_family=CF)
    print 'get_slice', res

    res = yield client.multiget(keys=['test', 'test2'],
                                column_family=CF,
                                column=colname)
    print 'multiget', res

    res = yield client.multiget_slice(keys=['test', 'test2'], column_family=CF)
    print 'multiget_slice', res

    res = yield client.get_count(key='test', column_family=CF)
    print 'get_count', res

    yield client.add(key='test',
                     column_family=COUNT_CF,
                     value=1,
                     column='testcounter')
    res = yield client.get(key='test',
                           column_family=COUNT_CF,
                           column='testcounter')
    print 'get counter value', res

    yield client.add(key='test',
                     column_family=SUPERCOUNT_CF,
                     value=1,
                     column='testcounter',
                     super_column='testsuper')
    res = yield client.get(key='test',
                           column_family=SUPERCOUNT_CF,
                           column='testcounter',
                           super_column='testsuper')
    print 'get super counter value', res

    # batch insert will figure out if you're trying a CF or SCF
    # from the data structure
    res = yield client.batch_insert(key='test',
                                    column_family=CF,
                                    mapping={colname: 'bar'})
    print "batch_insert", res
    res = yield client.batch_insert(key='test',
                                    column_family=SCF,
                                    mapping={'foo': {
                                        colname: 'bar'
                                    }})
    print "batch_insert", res

    # with ttypes, you pass a list as you would for raw thrift
    # this way you can set custom timestamps
    cols = [Column(colname, 'bar', 1234), Column('bar', 'baz', 54321)]
    res = yield client.batch_insert(key='test', column_family=CF, mapping=cols)
    print "batch_insert", res
    cols = [SuperColumn(name=colname, columns=cols)]

    # of course you don't have to use kwargs if the order is correct
    res = yield client.batch_insert('test', SCF, cols)
    print "batch_insert", res