# coding=utf-8
import logging.config
import unittest

from dsn_redis import RedisProxy
from dsn_redis import StrictRedisBuilder


class PrototypesTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        logging.config.fileConfig('logging.conf')

    def setUp(self):
        builder = StrictRedisBuilder()
        redis = builder.build()
        self.proxy = RedisProxy(redis)

    def test_hash_map(self):
        try:
            hmap = self.proxy.get_hash_map('hashmap')
            hmap['a'] = u'a'
            hmap['b'] = 'b'
            hmap.set('c', 1)
            hmap.expire(1200)
            print(repr(hmap.get_string('a')))
            print(repr(hmap.get_string('b')))
            print(repr(hmap.get_string('c')))
            print(repr(hmap.get_integer('c')))
            self.proxy.delete('hashmap')
            self.assertFalse(self.proxy.exists('hashmap'))
        except Exception as e:
            print(e)
            self.fail()

    def test_string(self):
        try:
            s = self.proxy.get_string('test_string')
            s.set('test')
            print(repr(s.get()))
            self.proxy.delete('test_string')
            self.assertFalse(self.proxy.exists('test_string'))
        except Exception as e:
            print(e)
            self.fail()
