def test_get_shard_for_instance_read_mod(self):
        instance = TShardedModel(partner_id=PID)
        router = ShardedPerTenantRouter()
        router._write_mode = False
        db_alias = router._get_shard_for_instance(instance)

        self.assertEqual(db_alias, 'test2__{}'.format(instance.partner_id))
    def test_get_shard_with_instance_read_mode(self):
        router = ShardedPerTenantRouter()
        router._write_mode = False
        instance = TShardedModel(partner_id=PID)
        hints = {'instance': instance}
        db_alias = router._get_shard(TShardedModel, **hints)

        self.assertEqual(db_alias, 'test2__{}'.format(instance.partner_id))
    def test_get_shard_read_mode(self):
        partner_id = PID
        router = ShardedPerTenantRouter()
        router._write_mode = False
        hints = {'exact_lookups': {TShardedModel.sharded_field: partner_id}}
        db_alias = router._get_shard(TShardedModel, **hints)

        self.assertEqual(db_alias, 'test2__{}'.format(partner_id))
    def test__build_db_alias_without_shard_value(self):
        router = ShardedPerTenantRouter()
        router._write_mode = True
        db_alias = router._build_db_alias(None, TShardedModel)

        self.assertEqual(db_alias, 'test1')
    def test__build_db_alias_with_config(self):
        router = ShardedPerTenantRouter()
        router._write_mode = True
        db_alias = router._build_db_alias(1, TShardedModel)

        self.assertEqual(db_alias, 'test1__1')
    def test_get_db_group_for_default(self):
        router = ShardedPerTenantRouter()
        router._write_mode = True
        db_group = router._get_db_group(TShardedModel)

        self.assertEqual(db_group, 'test1')
    def test_get_db_group_for_read(self):
        router = ShardedPerTenantRouter()
        router._write_mode = False
        db_group = router._get_db_group(TShardedModel)

        self.assertEqual(db_group, 'test2')
    def test_if_alias_not_in_DATABASES_then_return_db_group(self):
        router = ShardedPerTenantRouter()
        router._write_mode = True
        db_alias = router._build_db_alias(1, TShardedModel)

        self.assertEqual(db_alias, 'test1')