Exemplo n.º 1
0
def test_client_user_as_agency_member(action, permission):
    agency1 = AgencyFactory(users=2, clients=2)
    agency2 = AgencyFactory(users=1)

    user1, user2 = [p.user for p in agency1.user_profiles.all()]
    client1, client2 = [ac.client for ac in agency1.agency_clients.all()]

    (userA, ) = [p.user for p in agency2.user_profiles.all()]

    view1 = create_view(ClientViewset, action, user1, permission)
    view2 = create_view(ClientViewset, action, user2, permission)

    viewA = create_view(ClientViewset, action, userA, permission)

    # both members of agency 1 should se same clients
    assert view1.get_queryset().count() == 2
    assert client1 in view1.get_queryset()
    assert client2 in view1.get_queryset()

    assert view2.get_queryset().count() == 2
    assert client1 in view2.get_queryset()
    assert client2 in view2.get_queryset()

    # someone from other agency will not see clients
    assert viewA.get_queryset().count() == 0
Exemplo n.º 2
0
 def create_agency(self):
     agency = AgencyFactory(users=2)
     for p in agency.user_profiles.all():
         ClientFactory.create_batch(5, created_by=p.user)
         SurveyFactory.create(is_public=True, created_by=p.user)
         SurveyFactory.create(is_public=False, created_by=p.user)
         QuestionFactory.create(is_public=True, created_by=p.user)
         QuestionFactory.create(is_public=False, created_by=p.user)
Exemplo n.º 3
0
def test_client_user_no_permissions(action):
    agency1 = AgencyFactory(users=2, clients=2)

    user1, user2 = [p.user for p in agency1.user_profiles.all()]
    client1, client2 = [ac.client for ac in agency1.agency_clients.all()]

    view1 = create_view(ClientViewset, "view", user1)

    assert view1.get_queryset().count() == 0
Exemplo n.º 4
0
def test_iep_enrollment_programs_must_be_from_same_agency():
    agency1 = AgencyFactory(users=1, clients=2)
    agency2 = AgencyFactory()
    program1 = ProgramFactory(agency=agency1)
    program2 = ProgramFactory(agency=agency2)
    client = Client.objects.first()

    iep = ClientIEPFactory(client=client)
    enrollment1 = EnrollmentFactory(client=client, program=program1)
    enrollment2 = EnrollmentFactory(client=client, program=program2)

    ClientIEPEnrollmentFactory(iep=iep, enrollment=enrollment1)
    ClientIEPEnrollmentFactory(iep=iep, enrollment=enrollment2)

    try:
        iep.clean()
        assert False
    except ValidationError:
        pass
Exemplo n.º 5
0
def test_users_me():
    agency = AgencyFactory(users=1)
    # TODO: make sure that user is from DFCS
    user = agency.user_profiles.first().user

    api_client = APIClient()
    api_client.force_authenticate(user)

    response = api_client.get("/users/me/")
    assert response.status_code == 200
Exemplo n.º 6
0
def test_iep_status_change_will_update_client_is_new_field():
    agency1 = AgencyFactory(users=1, clients=2)
    agency2 = AgencyFactory()
    program1 = ProgramFactory(agency=agency1)
    program2 = ProgramFactory(agency=agency2)
    client = Client.objects.first()

    iep = ClientIEPFactory(client=client)

    assert client.is_new is True

    iep.status = IEPStatus.IN_PROGRESS
    iep.save()

    assert client.is_new is False

    iep.status = IEPStatus.ENDED
    iep.save()

    assert client.is_new is True
Exemplo n.º 7
0
def test_client_user_as_owner(action, permission):
    agency1 = AgencyFactory(users=2, clients=2)

    user1, user2 = [p.user for p in agency1.user_profiles.all()]
    client1, client2 = [ac.client for ac in agency1.agency_clients.all()]

    view1 = create_view(ClientViewset, action, user1, permission)
    view2 = create_view(ClientViewset, action, user2, permission)

    # both members of agency 1 should se same clients
    assert view1.get_queryset().count() == 1
    assert client1 in view1.get_queryset()

    assert view2.get_queryset().count() == 1
    assert client2 in view2.get_queryset()
Exemplo n.º 8
0
def test_denying_eligibility_request_will_change_status():
    agency = AgencyFactory(users=1, clients=2)
    program = ProgramFactory(agency=agency)
    client = Client.objects.first()

    iep = ClientIEPFactory(client=client)

    Eligibility.objects.create(name="test")
    eligibility_request = EligibilityQueue.objects.create(client=client,
                                                          requestor=agency)
    iep.eligibility_request = eligibility_request
    iep.save()

    iep.eligibility_request.status = EligibilityStatus.NOT_ELIGIBLE.name
    iep.eligibility_request.save()

    iep.refresh_from_db()
    assert iep.status == IEPStatus.NOT_ELIGIBLE
Exemplo n.º 9
0
def test_ClientIEPEnrollment_and_Enrollment_must_have_same_client():
    agency = AgencyFactory(users=1, clients=2)
    program = ProgramFactory(agency=agency)
    client1 = Client.objects.first()
    client2 = Client.objects.last()

    assert client1.id != client2.id

    iep = ClientIEPFactory(client=client1)
    enrollment = EnrollmentFactory(client=client2, program=program)

    iep_enrollment = ClientIEPEnrollmentFactory(iep=iep, enrollment=enrollment)

    try:
        iep_enrollment.clean()
        assert False
    except ValidationError:
        pass
Exemplo n.º 10
0
def test_create_client_note():
    # create test agency
    agency1 = AgencyFactory(users=1, clients=1)
    user = agency1.user_profiles.first().user
    user.user_permissions.add(Permission.objects.get(codename="add_note"))

    client = Client.objects.first()

    url = "/notes/"
    api_client = APIClient()
    api_client.force_authenticate(user)

    response = api_client.post(
        url,
        {"source": {"id": client.id, "type": "Client"}, "text": "a message"},
        format="json",
    )

    assert response.status_code == 201
Exemplo n.º 11
0
def setup_agency_data():
    """
    We have 2 agencies here
    Agency1 has 2 clients: first one created by user1, second one created by user2

    Agency2 has 2 clients: first one created by user1, second one created by user2
    """
    agency1 = AgencyWithEligibilityFactory(name="Agency1",
                                           users=2,
                                           clients=2,
                                           num_eligibility=1)

    user1, user2 = [p.user for p in agency1.user_profiles.all()]
    client1, client2 = [ac.client for ac in agency1.agency_clients.all()]

    agency2 = AgencyFactory(name="Agency2", users=2, clients=2)

    user3, user4 = [p.user for p in agency2.user_profiles.all()]
    client3, client4 = [ac.client for ac in agency2.agency_clients.all()]

    return agency1, agency2
Exemplo n.º 12
0
def test_retrieve_client_iep():
    # create test agency
    agency1 = AgencyFactory(users=1, clients=1)
    user = agency1.user_profiles.first().user
    user.user_permissions.add(
        Permission.objects.get(codename="view_clientiep"))
    user.user_permissions.add(Permission.objects.get(codename="view_client"))
    client = Client.objects.first()

    ClientIEPFactory(client=client)

    url = "/iep/"
    api_client = APIClient()
    api_client.force_authenticate(user)

    response = api_client.get(url)

    assert response.status_code == 200
    assert len(response.data["results"]) == 1

    row = response.data["results"][0]
    assert row["client"]["id"] == str(client.id)
Exemplo n.º 13
0
    def handle(self, *args, **options):
        # arguments: options['poll_ids']:
        AgencyFactory.reset_sequence(Agency.objects.count())

        self.create_agency()
Exemplo n.º 14
0
def test_is_protected():
    agency = AgencyFactory(users=1, clients=2)

    user = agency.user_profiles.first().user
    view = create_view(ClientViewset, "view", user)
    assert AbilityPermission in view.permission_classes