'Test keyspace segregation when same connection is used
@since 3.7
@jira_ticket PYTHON-613
@expected_result Keyspace segration is honored
@test_category object_mapper'

def test_keyspace(self):

    self._reset_data()
    with ContextQuery(TestModel, connection='cluster') as tm:
        tm.objects.using(keyspace='ks2').create(partition=1, cluster=1)
        tm.objects.using(keyspace='ks2').create(partition=2, cluster=2)
        with self.assertRaises(TestModel.DoesNotExist):
            tm.objects.get(partition=1, cluster=1)
        obj1 = tm.objects.using(keyspace='ks2').get(partition=1, cluster=1)
        obj1.count = 2
        obj1.save()
    with self.assertRaises(NoHostAvailable):
        TestModel.objects.using(keyspace='ks2').get(partition=1, cluster=1)
    obj2 = TestModel.objects.using(connection='cluster', keyspace='ks2').get(partition=1, cluster=1)
    self.assertEqual(obj2.count, 2)
    TestModel.objects(partition=2, cluster=2).using(connection='cluster', keyspace='ks2').update(count=5)
    obj3 = TestModel.objects.using(connection='cluster', keyspace='ks2').get(partition=2, cluster=2)
    self.assertEqual(obj3.count, 5)
    TestModel.objects(partition=2, cluster=2).using(connection='cluster', keyspace='ks2').delete()
    with self.assertRaises(TestModel.DoesNotExist):
        TestModel.objects.using(connection='cluster', keyspace='ks2').get(partition=2, cluster=2)
