-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathtest_load_gtas_mgmt_cmd.py
More file actions
144 lines (134 loc) · 4.3 KB
/
test_load_gtas_mgmt_cmd.py
File metadata and controls
144 lines (134 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from unittest.mock import MagicMock
import pytest
from django.conf import settings
from django.core.management import call_command
from model_bakery import baker
from usaspending_api.etl.broker_etl_helpers import PhonyCursor
from usaspending_api.references.models import GTASSF133Balances
@pytest.mark.django_db
def test_program_activity_fresh_load(monkeypatch):
"""
Test the gtas totals load to ensure data is loaded with the correct totals.
"""
baker.make("references.DisasterEmergencyFundCode", code="A")
baker.make("accounts.TreasuryAppropriationAccount", tas_rendering_label="999-X-111")
baker.make("references.ProgramActivityPark", code="test")
data_broker_mock = MagicMock()
data_broker_mock.cursor.return_value = PhonyCursor("usaspending_api/references/tests/data/broker_gtas.json")
mock_connections = {
settings.DEFAULT_DB_ALIAS: MagicMock(),
settings.BROKER_DB_ALIAS: data_broker_mock,
}
monkeypatch.setattr("usaspending_api.references.management.commands.load_gtas.connections", mock_connections)
call_command("load_gtas")
expected_results = {
"count": 3,
"row_tuples": [
(
1600,
-1,
-11.00,
-11.00,
-10.00,
-11.00,
-11.00,
-11.00,
-11.00,
-11.00,
-11.00,
-11.00,
-11.00,
11,
11,
-111,
-110,
-11.00,
"test",
"test",
"test",
"test",
"test",
),
(
1600,
-2,
-12.00,
-12.00,
-9.00,
-12.00,
-12.00,
-12.00,
-12.00,
-12.00,
-12.00,
-12.00,
-12.00,
12,
12,
-121,
-120,
-12.00,
"test",
"test",
"test",
"test",
"test",
),
(
1601,
-1,
-13.00,
-13.00,
-8.00,
-13.00,
-13.00,
-13.00,
-13.00,
-13.00,
-13.00,
-13.00,
-13.00,
13,
13,
-131,
-130,
-13.00,
"test",
"test",
"test",
"test",
"test",
),
],
}
actual_results = {
"count": GTASSF133Balances.objects.count(),
"row_tuples": list(
GTASSF133Balances.objects.values_list(
"fiscal_year",
"fiscal_period",
"budget_authority_unobligated_balance_brought_forward_cpe",
"adjustments_to_unobligated_balance_brought_forward_cpe",
"obligations_incurred_total_cpe",
"budget_authority_appropriation_amount_cpe",
"borrowing_authority_amount",
"contract_authority_amount",
"spending_authority_from_offsetting_collections_amount",
"other_budgetary_resources_amount_cpe",
"obligations_incurred",
"deobligations_or_recoveries_or_refunds_from_prior_year_cpe",
"unobligated_balance_cpe",
"total_budgetary_resources_cpe",
"status_of_budgetary_resources_total_cpe",
"anticipated_prior_year_obligation_recoveries",
"prior_year_paid_obligation_recoveries",
"adjustments_to_unobligated_balance_brought_forward_cpe",
"budget_object_class",
"program_activity_reporting_key_id",
"prior_year_adjustment",
"by_direct_reimbursable_fun",
"bea_category",
).order_by("-budget_authority_unobligated_balance_brought_forward_cpe")
),
}
assert expected_results == actual_results