# Path: greenpithumb/db_store.py
# _CREATE_TABLE_COMMANDS = """
# CREATE TABLE temperature
# (
#     timestamp TEXT,
#     temperature REAL    --temperature (in degrees Celsius)
# );
# CREATE TABLE humidity
# (
#     timestamp TEXT,
#     humidity REAL
# );
# CREATE TABLE soil_moisture
# (
#     timestamp TEXT,
#     soil_moisture INTEGER
# );
# CREATE TABLE light
# (
#     timestamp TEXT,
#     light REAL
# );
# CREATE TABLE watering_events
# (
#     timestamp TEXT,
#     water_pumped REAL   --amount of water pumped (in mL)
# );
# """
# _TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%MZ'
# def _timestamp_to_utc(timestamp):
# def _open_db(db_path):
# def _create_db(db_path):
# def open_or_create_db(db_path):
#     def __init__(self, connection):
#     def _do_insert(self, sql, timestamp, value):
#     def _do_get(self, sql, record_type):
#     def insert(self, soil_moisture_record):
#     def get(self):
#     def insert(self, light_record):
#     def get(self):
#     def insert(self, humidity_record):
#     def get(self):
#     def insert(self, temperature_record):
#     def get(self):
#     def insert(self, watering_event_record):
#     def get(self):
# class _DbStoreBase(object):
# class SoilMoistureStore(_DbStoreBase):
# class LightStore(_DbStoreBase):
# class HumidityStore(_DbStoreBase):
# class TemperatureStore(_DbStoreBase):
# class WateringEventStore(_DbStoreBase):


import contextlib
import datetime
import os
import shutil
import sqlite3
import tempfile
import unittest
import mock
import pytz
from dateutil import tz
from greenpithumb import db_store
        with tempfile.NamedTemporaryFile() as temp_file:
            with contextlib.closing(db_store.open_or_create_db(temp_file.name)):
                mock_connect.assert_called_once_with(temp_file.name)
        # If the database already existed, we should not do anything except
        # call sqlite3.connect().
        mock_connection.cursor.assert_not_called()
        mock_connection.commit.assert_not_called()

    def test_creates_file_and_tables_when_db_does_not_already_exist(self):
        # Create a path for a file that does not already exist.
        db_path = os.path.join(self._temp_dir, 'test.db')
        with contextlib.closing(
                db_store.open_or_create_db(db_path)) as connection:
            cursor = connection.cursor()
            # Insertions into all tables should work after initialization.
            cursor.execute('INSERT INTO temperature VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 98.6))
            cursor.execute('INSERT INTO humidity VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 93.7))
            cursor.execute('INSERT INTO soil_moisture VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 57))
            cursor.execute('INSERT INTO light VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 75.2))
            cursor.execute('INSERT INTO watering_events VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 258.9))
            connection.commit()


class StoreClassesTest(unittest.TestCase):


# Path: greenpithumb/db_store.py
# _CREATE_TABLE_COMMANDS = """
# CREATE TABLE temperature
# (
#     timestamp TEXT,
#     temperature REAL    --temperature (in degrees Celsius)
# );
# CREATE TABLE humidity
# (
#     timestamp TEXT,
#     humidity REAL
# );
# CREATE TABLE soil_moisture
# (
#     timestamp TEXT,
#     soil_moisture INTEGER
# );
# CREATE TABLE light
# (
#     timestamp TEXT,
#     light REAL
# );
# CREATE TABLE watering_events
# (
#     timestamp TEXT,
#     water_pumped REAL   --amount of water pumped (in mL)
# );
# """
# _TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%MZ'
# def _timestamp_to_utc(timestamp):
# def _open_db(db_path):
# def _create_db(db_path):
# def open_or_create_db(db_path):
#     def __init__(self, connection):
#     def _do_insert(self, sql, timestamp, value):
#     def _do_get(self, sql, record_type):
#     def insert(self, soil_moisture_record):
#     def get(self):
#     def insert(self, light_record):
#     def get(self):
#     def insert(self, humidity_record):
#     def get(self):
#     def insert(self, temperature_record):
#     def get(self):
#     def insert(self, watering_event_record):
#     def get(self):
# class _DbStoreBase(object):
# class SoilMoistureStore(_DbStoreBase):
# class LightStore(_DbStoreBase):
# class HumidityStore(_DbStoreBase):
# class TemperatureStore(_DbStoreBase):
# class WateringEventStore(_DbStoreBase):


# Path: tests/test_db_store.py
import contextlib
import datetime
import os
import shutil
import sqlite3
import tempfile
import unittest
import mock
import pytz
from dateutil import tz
from greenpithumb import db_store

        with tempfile.NamedTemporaryFile() as temp_file:
            with contextlib.closing(db_store.open_or_create_db(temp_file.name)):
                mock_connect.assert_called_once_with(temp_file.name)
        # If the database already existed, we should not do anything except
        # call sqlite3.connect().
        mock_connection.cursor.assert_not_called()
        mock_connection.commit.assert_not_called()

    def test_creates_file_and_tables_when_db_does_not_already_exist(self):
        # Create a path for a file that does not already exist.
        db_path = os.path.join(self._temp_dir, 'test.db')
        with contextlib.closing(
                db_store.open_or_create_db(db_path)) as connection:
            cursor = connection.cursor()
            # Insertions into all tables should work after initialization.
            cursor.execute('INSERT INTO temperature VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 98.6))
            cursor.execute('INSERT INTO humidity VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 93.7))
            cursor.execute('INSERT INTO soil_moisture VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 57))
            cursor.execute('INSERT INTO light VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 75.2))
            cursor.execute('INSERT INTO watering_events VALUES (?, ?)',
                           ('2016-07-23T10:51Z', 258.9))
            connection.commit()


class StoreClassesTest(unittest.TestCase):


    def setUp(self):