Exemplo n.º 1
0
 def test_admins_can_update_ones_facility(self, client, user, facility):
     client.force_authenticate(user=user)
     user.is_superuser = True
     user.save()
     response = client.post(
         "/api/v1/facility/bulk_upsert/",
         data=[
             {
                 "name":
                 facility.name,
                 "district":
                 facility.district,
                 "facility_type":
                 3,
                 "address":
                 facility.address,
                 "capacity": [{
                     "room_type": 1,
                     "total_capacity": 100,
                     "current_capacity": 48,
                 }],
             },
         ],
     )
     assert response.status_code == 204
Exemplo n.º 2
0
    def test_superuser_can_read_modify_delete_all(self, client, user, data):
        user.is_superuser = True
        user.save()

        response = client.post(
            "/api/v1/users/",
            data,
        )
        assert response.status_code == 201

        client.force_authenticate(user=user)

        response = client.get("/api/v1/users/")
        assert response.status_code == 200
        assert response.json()["count"] == 2
        assert user.username in {
            r["username"]
            for r in response.json()["results"]
        }
        assert data["username"] in {
            r["username"]
            for r in response.json()["results"]
        }

        response = client.get(f"/api/v1/users/{data['username']}/")
        assert response.status_code == 200
        res_data = response.json()
        res_data.pop("id")
        password = data.pop("password")
        assert res_data == {
            **data, 'district': 'Kozhikode',
            'gender': 'Male',
            'user_type': 'Doctor',
            'first_name': '',
            'last_name': '',
            'skill': None
        }

        response = client.put(f"/api/v1/users/{data['username']}/", {
            **data,
            "age": 31,
            "password": password,
        })
        assert response.status_code == 200
        assert response.json()["age"] == 31
        assert User.objects.only('age').get(
            username=data["username"]).age == 31

        response = client.delete(f"/api/v1/users/{data['username']}/")
        assert response.status_code == 204
        with pytest.raises(User.DoesNotExist):
            User.objects.get(username=data["username"])
Exemplo n.º 3
0
    def test_update_doesnt_change_creator(self, client, user, user_data,
                                          facility, facility_data):
        facility.created_by = User.objects.create(**user_data)
        facility.save()
        original_creator = facility.created_by

        user.is_superuser = True
        user.save()
        client.force_authenticate(user=user)

        response = client.put(f"/api/v1/facility/{facility.id}/",
                              facility_data)
        assert response.status_code == 200
        facility.refresh_from_db()
        assert facility.created_by == original_creator
Exemplo n.º 4
0
    def test_super_user_access(self, client, user, patient):
        client.force_authenticate(user=user)
        response = client.get(f"/api/v1/patient/{patient.id}/")
        assert response.status_code == 404

        user.is_superuser = True
        user.save()
        response = client.get(f"/api/v1/patient/{patient.id}/")
        assert response.status_code == 200
        assert response.data == {
            "id": patient.id,
            "name": patient.name,
            "age": patient.age,
            "gender": patient.gender,
            "phone_number": patient.phone_number,
            "contact_with_carrier": patient.contact_with_carrier,
            "medical_history": {2, 4},
            "medical_history_details": patient.medical_history_details,
            "tele_consultation_history": [],
            "is_active": True,
        }
Exemplo n.º 5
0
    def test_super_user_access(self, client, user, facility):
        client.force_authenticate(user=user)
        response = client.get(f"/api/v1/facility/{facility.id}/")
        assert response.status_code == 404

        user.is_superuser = True
        user.save()
        response = client.get(f"/api/v1/facility/{facility.id}/")
        assert response.status_code == 200
        assert response.data == {
            "id": facility.id,
            "name": facility.name,
            "district": "Kannur",
            "facility_type": "Educational Inst",
            "address": facility.address,
            "location": {
                "latitude": facility.location.tuple[1],
                "longitude": facility.location.tuple[0],
            },
            "oxygen_capacity": facility.oxygen_capacity,
            "phone_number": facility.phone_number,
        }