def test_matview_sql_generator(
        convert_traditional_views_to_materialized_views):
    """
    The goal of this test is to ensure that we can successfully create materialized views using our homegrown
    materialized view generator.  We will not test the validity of the data contained therein, just that we
    can create the materialized views without issue.
    """

    # Run through all of the materialized views and perform a simple count query.
    for matview in MATERIALIZED_VIEWS.values():
        # This will fail if the materialized view doesn't exist for whatever reason which is what we want.
        matview["model"].objects.count()
Beispiel #2
0
from django.conf import settings
from django.db import connection
from fiscalyear import datetime
from usaspending_api.common.matview_manager import (
    OVERLAY_VIEWS,
    DEPENDENCY_FILEPATH,
    MATERIALIZED_VIEWS,
    MATVIEW_GENERATOR_FILE,
    DEFAULT_MATIVEW_DIR,
)
from usaspending_api.references.models import Agency


logger = logging.getLogger(__name__)
TEMP_SQL_FILES = [DEFAULT_MATIVEW_DIR / val["sql_filename"] for val in MATERIALIZED_VIEWS.values()]


def read_text_file(filepath):
    with open(filepath, "r") as plaintext_file:
        file_content_str = plaintext_file.read()
    return file_content_str


def convert_string_to_datetime(input: str) -> datetime.datetime:
    """Parse a string into a datetime object"""
    return parser.parse(input)


def convert_string_to_date(input: str) -> datetime.date:
    """Parse a string into a date object"""
Beispiel #3
0
from django.db import connection
from fiscalyear import FiscalDateTime, FiscalQuarter, datetime, FiscalDate
from usaspending_api.common.exceptions import InvalidParameterException
from usaspending_api.common.matview_manager import (
    OVERLAY_VIEWS,
    DEPENDENCY_FILEPATH,
    MATERIALIZED_VIEWS,
    MATVIEW_GENERATOR_FILE,
    DEFAULT_MATIVEW_DIR,
)
from usaspending_api.references.models import Agency

logger = logging.getLogger(__name__)
TEMP_SQL_FILES = [
    DEFAULT_MATIVEW_DIR / val["sql_filename"]
    for val in MATERIALIZED_VIEWS.values()
]


def read_text_file(filepath):
    with open(filepath, "r") as plaintext_file:
        file_content_str = plaintext_file.read()
    return file_content_str


def validate_date(date):
    if not isinstance(date, (datetime.datetime, datetime.date)):
        raise TypeError("Incorrect parameter type provided")

    if not (date.day or date.month or date.year):
        raise Exception("Malformed date object provided")