""" Unit tests for DynamoDB Config Store """
import time
import unittest
from random import random

from boto.dynamodb2.layer1 import DynamoDBConnection
from boto.dynamodb2.exceptions import ItemNotFound, ValidationException
from boto.dynamodb2.table import Table

from dynamodb_config_store import DynamoDBConfigStore
from dynamodb_config_store.exceptions import MisconfiguredSchemaException

connection = DynamoDBConnection(
    aws_access_key_id='foo',
    aws_secret_access_key='bar',
    host='localhost',
    port=8000,
    is_secure=False)


class TestCustomThroughput(unittest.TestCase):

    def setUp(self):

        # Configuration options
        self.table_name = 'conf'
        self.store_name = 'test'
        self.read_units = 10
        self.write_units = 8

        # Instanciate the store
        self.store = DynamoDBConfigStore(
            connection,
            self.table_name,
            self.store_name,
            read_units=self.read_units,
            write_units=self.write_units)

        # Get an Table instance for validation
        self.table = Table(self.table_name, connection=connection)

    def test_custom_throughput(self):
        """ Test that we can set custom thoughput for new tables """
        throughput = self.table.describe()[u'Table'][u'ProvisionedThroughput']

        self.assertEqual(throughput[u'ReadCapacityUnits'], self.read_units)
        self.assertEqual(throughput[u'WriteCapacityUnits'], self.write_units)

    def tearDown(self):
        """ Tear down the test case """
        self.table.delete()


class TestCustomStoreAndOptionKeys(unittest.TestCase):

    def setUp(self):

        # Configuration options
        self.table_name = 'conf'
        self.store_name = 'test'
        self.store_key = '_s'
        self.option_key = '_o'