Ejemplo n.º 1
0
def populate_agencies():
    cmd = sync_agencies.Command()
    cmd.create_system_groups()
    mommy.make(Agency, name="Aquarius", omb_agency_code="123")
    dod = mommy.make(Agency,
                     name="Department of Defense",
                     abbr="DOD",
                     omb_agency_code="111")
    mommy.make(Agency,
               name="Department of Homeland Security",
               abbr="DHS",
               omb_agency_code="100")
    mommy.make(Agency,
               name="General Services Administration",
               abbr="GSA",
               omb_agency_code="101")
    mommy.make(Agency,
               name="Department of Justice",
               abbr="Justice",
               omb_agency_code="102")
    mommy.make(Agency,
               name="Department of Foo",
               abbr="FOO",
               omb_agency_code="112")

    MockAgencies = namedtuple("MockAgencies", ["dod", "all_agencies"])
    all_agencies_group = AgencyGroup.objects.get(slug="all-agencies")
    mock_agencies = MockAgencies(dod=dod, all_agencies=all_agencies_group)
    yield mock_agencies
Ejemplo n.º 2
0
def test_create_system_groups():
    """We create agency groups *if they do not already exist*. When creating,
    we generate a version"""
    AgencyGroup.objects.create(slug='cfo-act', name='Alt CFO')
    cmd = sync_agencies.Command()
    cmd.create_system_groups()

    assert AgencyGroup.objects.count() == 3
    # We only make a new version for the newly generated groups
    assert Version.objects.get_for_model(AgencyGroup).count() == 2
    assert AgencyGroup.objects.get(slug='executive').name == 'Executive'
    # name not changed
    assert AgencyGroup.objects.get(slug='cfo-act').name == 'Alt CFO'
    assert AgencyGroup.objects.get(slug='cio-council').name == 'CIO Council'
Ejemplo n.º 3
0
def test_sync_row_new():
    cmd = sync_agencies.Command()
    cmd.create_system_groups()
    cmd.sync_row({
        'agencyAbbreviation': None,
        'agencyCode': '123',
        'agencyName': 'Aquarius',
        'agencyType': '5-Other Branches',
        'CFO_Act': '1',
        'CIO_Council': None,
    })

    assert Agency.objects.count() == 1
    agency = Agency.objects.get()
    assert agency.name == 'Aquarius'
    assert agency.abbr == ''
    assert agency.omb_agency_code == '123'
    assert agency.public
    group_slugs = {g.slug for g in agency.groups.all()}
    assert Version.objects.get_for_object(agency).count() == 1
    assert group_slugs == {'all-agencies', 'cfo-act'}
Ejemplo n.º 4
0
def test_sync_row_existing():
    mommy.make(Agency, omb_agency_code='90210')
    assert Agency.objects.count() == 1

    cmd = sync_agencies.Command()
    cmd.create_system_groups()
    cmd.sync_row({
        'agencyAbbreviation': 'BH',
        'agencyCode': '90210',
        'agencyName': 'New Name Here',
        'agencyType': '1-CFO Act',  # this will be ignored
        'CFO_Act': '',
        'CIO_Council': '1',
    })

    assert Agency.objects.count() == 1
    agency = Agency.objects.get()
    assert agency.name == 'New Name Here'
    assert agency.abbr == 'BH'
    assert agency.omb_agency_code == '90210'
    assert agency.public
    group_slugs = {g.slug for g in agency.groups.all()}
    assert group_slugs == {'all-agencies', 'cio-council', 'executive'}
    assert Version.objects.get_for_object(agency).count() == 1