Commit 144b6fad authored by Huihui, Jonathan's avatar Huihui, Jonathan
Browse files

added testing

parent 3fdc39c9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4,7 +4,11 @@ RUN apt-get -yqq update && apt-get -yqq upgrade && \
      apt-get -yqq install vim 

COPY src/ tmp/src


RUN set -eux && pip install --upgrade pip && \
      cd /tmp/src/ && pip install -e . 

COPY ./test/test.py /test/test.py

CMD ['sh', 'tail', '-f', '/dev/null']
+7 −9
Original line number Diff line number Diff line
@@ -6,12 +6,13 @@ PostgreSQL database. However, the connection paramater may be specified to open
any type of connection through implementation of this abstract class.
"""
import traceback
from abc import ABCMeta, abstractmethod
from abc import ABC, abstractmethod
from common.logz import create_logger
from common.env import check_environment as ce
import psycopg2


class Database(ABCMeta):
# from common.database import Database
class Database(ABC):
    """ Provides an abstract class for connecting to a database using
        environmental variables.

@@ -67,7 +68,8 @@ class Database(ABCMeta):
            :param connection_info: a dictionary containing connection info
        """
        self.logger = create_logger()
        self.conection_info = connection_info
        self.connection_info = connection_info
        self.logger.debug(connection_info)
        self.connection = None
        self.cursor = None
        self.logger.debug('Database object successfully initialized')
@@ -93,10 +95,6 @@ class Database(ABCMeta):
        """ hande database closing when leaving with """
        self.close()

    @abstractmethod
    def open(self):
        pass

    def silent_open(self):
        """Open database silently without returning anything."""
        try:
@@ -129,7 +127,7 @@ class Database(ABCMeta):
    def is_open(self):
        """Determine if the database is open or not."""
        # TODO @Jonathan -- code review please
        if self.cursor is not None and self._connection is not None:
        if self.cursor is not None and self.connection is not None:
            # Test if both connection and cursor are on
            return True  # If both are on, return True
        # If one or both connection and cursor are missing, return False
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ import pandas as pd
import sqlalchemy


class Pandas_Mixin():
class PandasMixin():
    """Group together all pandas logic."""
    def query_pandas(self, query=None, table=None, schema=None):
        """Return a query as a pandas table.
+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
import psycopg2


class Postgres_Mixin():
class PostgresMixin():
    """Serve common connection method for postgres."""

    def open(self, search_path='public'):
@@ -27,7 +27,7 @@ class Postgres_Mixin():
                connect_timeout=self.connection_info['dbTimeout'])
            self.connection.set_client_encoding('UTF8')
            self.logger.debug('Successfully opened connection to database')
            self.cursor = self._connection.cursor()
            self.cursor = self.connection.cursor()
            self.logger.debug('Successfully created a cursor')
            # TODO @Jonathan v--- not the default search paths - env var?
            """ ^---- need this re-explained """
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ import os
from setuptools import setup

# update version information here
_version = '0.1.5'
_version = '0.1.6'

# packages
_packages = ['common', 'common.mixins']