def _prepare_tiny_shield_models():
    models = customize_pagination_with_sort_columns(list(SORTABLE_COLUMNS.keys()), DEFAULT_SORT_COLUMN)
    models.extend([
        get_internal_or_generated_award_id_model(),
        {'key': 'piid', 'name': 'piid', 'optional': True, 'type': 'text', 'text_type': 'search'}
    ])
    return models
Beispiel #2
0
def _prepare_tiny_shield_models():
    models = customize_pagination_with_sort_columns(list(SORTABLE_COLUMNS.keys()), DEFAULT_SORT_COLUMN)
    models.extend([
        get_internal_or_generated_award_id_model(),
        {'key': 'piid', 'name': 'piid', 'optional': True, 'type': 'text', 'text_type': 'search'}
    ])
    return models
Beispiel #3
0
def _prepare_tiny_shield_models():
    models = customize_pagination_with_sort_columns(list(SORTABLE_COLUMNS.keys()), DEFAULT_SORT_COLUMN)
    models.extend(
        [
            get_internal_or_generated_award_id_model(),
            {"key": "piid", "name": "piid", "optional": True, "type": "text", "text_type": "search"},
        ]
    )
    return models
 def __init__(self):
     models = customize_pagination_with_sort_columns(
         list(TransactionViewSet.transaction_lookup.keys()),
         'action_date'
     )
     models.extend([
         get_internal_or_generated_award_id_model(),
         {'key': 'idv', 'name': 'idv', 'type': 'boolean', 'default': True, 'optional': True}
     ])
     self._tiny_shield_models = models
     super(TransactionViewSet, self).__init__()
 def __init__(self):
     models = customize_pagination_with_sort_columns(
         list(TransactionViewSet.transaction_lookup.keys()), "action_date"
     )
     models.extend(
         [
             get_internal_or_generated_award_id_model(),
             {"key": "idv", "name": "idv", "type": "boolean", "default": True, "optional": True},
         ]
     )
     self._tiny_shield_models = models
     super(TransactionViewSet, self).__init__()
Beispiel #6
0
def _prepare_tiny_shield_models():
    models = customize_pagination_with_sort_columns(SORTABLE_COLUMNS,
                                                    DEFAULT_SORT_COLUMN)
    models.extend([
        get_internal_or_generated_award_id_model(), {
            'key': 'idv',
            'name': 'idv',
            'type': 'boolean',
            'default': True,
            'optional': True
        }
    ])
    return models
 def __init__(self):
     models = customize_pagination_with_sort_columns(
         list(TransactionViewSet.transaction_lookup.keys()), 'action_date')
     models.extend([
         get_internal_or_generated_award_id_model(), {
             'key': 'idv',
             'name': 'idv',
             'type': 'boolean',
             'default': True,
             'optional': True
         }
     ])
     self._tiny_shield_models = models
     super(TransactionViewSet, self).__init__()
Beispiel #8
0
def _prepare_tiny_shield_models():
    models = customize_pagination_with_sort_columns(SORTABLE_COLUMNS,
                                                    DEFAULT_SORT_COLUMN)
    models.extend([
        get_internal_or_generated_award_id_model(), {
            'key': 'type',
            'name': 'type',
            'type': 'enum',
            'enum_values': tuple(TYPE_TO_SQL_MAPPING),
            'default': 'child_idvs',
            'optional': True
        }
    ])
    return models
Beispiel #9
0
def _prepare_tiny_shield_models():
    models = customize_pagination_with_sort_columns(SORTABLE_COLUMNS, DEFAULT_SORT_COLUMN)
    models.extend(
        [
            get_internal_or_generated_award_id_model(),
            {
                "key": "type",
                "name": "type",
                "type": "enum",
                "enum_values": tuple(TYPE_TO_SQL_MAPPING),
                "default": "child_idvs",
                "optional": True,
            },
        ]
    )
    return models
Beispiel #10
0
        gather_financial_accounts_by_awards gfaba
        left outer join treasury_appropriation_account taa on
            taa.treasury_account_identifier = gfaba.treasury_account_id
        left outer join federal_account fa on
            fa.agency_identifier = taa.agency_id and
            fa.main_account_code = taa.main_account_code
        left outer join agency_id_to_agency_id_for_toptier_mapping afmap on
            afmap.agency_id = gfaba.funding_agency_id
    group by
        federal_account, fa.account_title, funding_agency_abbreviation, funding_agency_name,
        afmap.agency_id_for_toptier
    order by
        {order_by} {order_direction}
""")

TINYSHIELD_MODELS = customize_pagination_with_sort_columns(
    list(SORTABLE_COLUMNS.keys()), DEFAULT_SORT_COLUMN)
TINYSHIELD_MODELS.append(get_internal_or_generated_award_id_model())


@validate_post_request(TINYSHIELD_MODELS)
class IDVAccountsViewSet(APIView):
    """
    These endpoints are used to power USAspending.gov's IDV Summary Funding Accounts component.
    """

    endpoint_doc = "usaspending_api/api_contracts/contracts/v2/idvs/accounts.md"

    @staticmethod
    def _business_logic(request_data: dict) -> list:
        # By this point, our award_id has been validated and cleaned up by
        # TinyShield.  We will either have an internal award id that is an
def test_invalid_customized_pagination_values():
    with pytest.raises(TypeError):
        customize_pagination_with_sort_columns(None)
    with pytest.raises(TypeError):
        customize_pagination_with_sort_columns(1)
    with pytest.raises(TypeError):
        customize_pagination_with_sort_columns([1, 2, 3])
    with pytest.raises(ValueError):
        customize_pagination_with_sort_columns(['field1', 'fieldA', 'fieldOne'], 1)
    with pytest.raises(ValueError):
        customize_pagination_with_sort_columns(['field1', 'fieldA', 'fieldOne'], 'fieldTwo')

    # This should work.  Last second sanity check.
    customize_pagination_with_sort_columns(['field1', 'fieldA', 'fieldOne'], 'fieldOne')
def test_customized_pagination_with_a_default_sort_column():
    pagination = customize_pagination_with_sort_columns(['field1', 'fieldA', 'fieldOne'], 'fieldOne')

    r = TinyShield(pagination).block({})
    assert r == {'page': 1, 'limit': 10, 'order': 'desc', 'sort': 'fieldOne'}
Beispiel #13
0
def test_customized_pagination_with_a_default_sort_column():
    pagination = customize_pagination_with_sort_columns(
        ["field1", "fieldA", "fieldOne"], "fieldOne")

    r = TinyShield(pagination).block({})
    assert r == {"page": 1, "limit": 10, "order": "desc", "sort": "fieldOne"}