Beispiel #1
0
 def test_login_view(self, app, client):
     """Login view is rendered when requesting ``/login`` endpoint."""
     with captured_templates(app) as templates:
         response = client.get("/login")
         template, context = templates[0]
         assert response.status_code == 200
         assert template.name == "auth/login.html"
Beispiel #2
0
 def test_add_patient_view(self, app, client, login_user):
     """View for adding new patients renders when requesting ``/new-patient``."""
     with captured_templates(app) as templates:
         response = client.get("/new-patient")
         template, context = templates[0]
         assert response.status_code == 200
         assert template.name == "patients/add_patient.html"
Beispiel #3
0
 def test_register_view(self, app, client):
     """Register view is rendered when requesting ``/register`` endpoint."""
     with captured_templates(app) as templates:
         response = client.get("/register")
         template, context = templates[0]
         assert response.status_code == 200
         assert template.name == "auth/register.html"
Beispiel #4
0
def test_index(app, client, view):
    """Index (home) page renders."""
    with captured_templates(app) as templates:
        response = client.get(view)
        template, context = templates[0]
        assert response.status_code == 200
        assert template.name == "home/splash.html"
Beispiel #5
0
def test_about(app, client):
    """About page renders."""
    with captured_templates(app) as templates:
        response = client.get("/about")
        template, context = templates[0]
        assert response.status_code == 200
        assert template.name == "home/about.html"
Beispiel #6
0
 def test_forgot_password(self, app, client):
     """Forgot password view is rendered."""
     with captured_templates(app) as templates:
         response = client.get("/forgot_password")
         template, context = templates[0]
         assert response.status_code == 200
         assert template.name == "auth/forgot_password.html"
Beispiel #7
0
 def test_logout_user(self, app, client, login_user):
     """Logged in users are logged out and redirected to home page."""
     with captured_templates(app) as templates:
         response = client.get("/logout", follow_redirects=True)
         template, context = templates[0]
         assert response.status_code == 200
         assert template.name == "home/splash.html"
Beispiel #8
0
 def test_empty_view_if_no_patients(self, app, client, login_user):
     """Patient view is empty if there are no patients."""
     with captured_templates(app) as templates:
         response = client.get("/patients")
         template, context = templates[0]
         assert response.status_code == 200
         assert not context["patients"]
         assert template.name == "patients/patients.html"
Beispiel #9
0
 def test_add_rx_view(self, app, client, login_user, patient, init_patient):
     """Add prescription view renders for logged in users."""
     with captured_templates(app) as templates:
         response = client.get("/patients/1/new-prescription")
         template, context = templates[0]
         assert response.status_code == 200
         assert context["patient"] == patient
         assert template.name == "prescriptions/add_prescription.html"
Beispiel #10
0
 def test_dashboard_view_rxs(self, app, client, login_user,
                             init_patient_with_rxs):
     """Dashboard view renders with prescriptions."""
     with captured_templates(app) as templates:
         response = client.get("/dashboard")
         template, context = templates[0]
         assert response.status_code == 200
         assert template.name == "dashboard/dashboard.html"
Beispiel #11
0
 def test_patients_deviating(self, app, client, login_user,
                             init_patient_with_rxs):
     """Only deviating patients are shown and are marked as non-adherent."""
     with captured_templates(app) as templates:
         response = client.get("/patients_deviating")
         template, context = templates[0]
         assert response.status_code == 200
         assert all(map(lambda p: not p.is_adherent(), context["patients"]))
         assert template.name == "patients/patients.html"
Beispiel #12
0
 def test_patients_adhering(self, app, client, login_user,
                            init_perfect_patient):
     """Only adherent patients are shown and are marked as adherent."""
     with captured_templates(app) as templates:
         response = client.get("/patients_ontrack")
         template, context = templates[0]
         assert response.status_code == 200
         assert all(map(lambda p: p.is_adherent(), context["patients"]))
         assert template.name == "patients/patients.html"
Beispiel #13
0
def test_home(app):
    with captured_templates(app) as templates:
        rv = app.test_client().get('/')
        assert rv.status_code == 200
        assert len(templates) == 1
        template, context = templates[0]
        assert template.name == 'blog.html'
        print(context)
        assert len(context['blog']) == 5  # pagination
Beispiel #14
0
 def test_patients_unprescribed(self, app, client, login_user,
                                init_patient):
     """Only unprescribed patients are shown (with null adherence)."""
     with captured_templates(app) as templates:
         response = client.get("/patients_unprescribed")
         template, context = templates[0]
         assert response.status_code == 200
         assert all(map(lambda p: not p.prescriptions, context["patients"]))
         assert template.name == "patients/patients.html"
Beispiel #15
0
 def test_patient_profile(self, app, client, login_user,
                          init_perfect_patient):
     """Detail view for a single patient is rendered when patient card is clicked."""
     with captured_templates(app) as templates:
         response = client.get("/patients/1")
         template, context = templates[0]
         assert response.status_code == 200
         assert context["patient"].id == 1
         assert context["prescriptions"][0].drug == "Vitamin C++"
         assert template.name == "patients/profile.html"
Beispiel #16
0
 def test_patient_search(self, app, client, login_user, patient,
                         init_patient):
     """Detail view for a single patient is rendered when searched for."""
     name = f"{patient.firstname} {patient.lastname}"
     with captured_templates(app) as templates:
         r = client.get(f"/patients/search?name={name}",
                        follow_redirects=True)
         template, context = templates[0]
         assert r.status_code == 200
         assert template.name == "patients/profile.html"
Beispiel #17
0
 def test_dashboard_view_no_rxs(self, app, client, login_user):
     """Dashboard view renders with no prescriptions."""
     with captured_templates(app) as templates:
         response = client.get("/dashboard")
         template, context = templates[0]
         assert response.status_code == 200
         assert type(context["adh_over_time"]) is str
         assert type(context["top_general_adh"]) is str
         assert type(context["top_ontime_adh"]) is str
         assert template.name == "dashboard/dashboard.html"
Beispiel #18
0
 def test_register_new_user(self, app, client, user_data):
     """New users are registered in the database and redirected to login page."""
     with captured_templates(app) as templates:
         response = client.post("/register",
                                data=user_data,
                                follow_redirects=True)
         template, context = templates[0]
         assert response.status_code == 200
         assert User.query.filter_by(
             username=user_data["username"]).count() == 1
         assert template.name == "auth/login.html"
Beispiel #19
0
 def test_login_existing_user(self, app, client, user_data, init_user):
     """Existing users (doctors) are redirected to ``patients`` page after login."""
     data = {
         "username": user_data["username"],
         "password": user_data["password"]
     }
     with captured_templates(app) as templates:
         response = client.post("/login", data=data, follow_redirects=True)
         template, context = templates[0]
         assert response.status_code == 200
         assert template.name == "patients/patients.html"
Beispiel #20
0
def test_random_drink(app):
    with captured_templates(app) as templates:
        resp = app.test_client().get('/bar/random_cocktail')

        template, context = templates[0]
        assert resp.status_code == 200
        assert template.name == 'cocktails.html'

        cocktail = CocktailApi().get_random_cocktail()
        assert isinstance(cocktail.ingredients, dict)
        assert cocktail.name
        assert cocktail.ingredients
Beispiel #21
0
 def test_add_new_patient(self, app, client, login_user, patient_data):
     """New patient is added to the db."""
     with captured_templates(app) as templates:
         r = client.post("/new-patient",
                         data=patient_data,
                         follow_redirects=True)
         template, context = templates[0]
         patients = context["current_user"].patients
         assert r.status_code == 200
         assert len(patients) == 1
         assert patients[0].firstname == patient_data["firstname"]
         assert template.name == "patients/patients.html"
Beispiel #22
0
def test_task_orders_submit_form_step_one_validates_object_name(
        app, client, user_session, portfolio):
    user_session(portfolio.owner)
    with captured_templates(app) as templates:
        client.post(
            url_for("task_orders.submit_form_step_one_add_pdf",
                    portfolio_id=portfolio.id),
            data={"pdf-object_name": "a" * 41},
            follow_redirects=True,
        )

        _, context = templates[-1]

        assert "object_name" in context["form"].pdf.errors
Beispiel #23
0
 def test_add_rx(self, app, client, login_user, rx_data, init_patient):
     """New rxs are added to the db and users are redirected to the patient view."""
     endpoint = "/patients/1/new-prescription"
     rx_data["dosage"] = list(adherence.DOSAGE_TO_FREQ.keys())[0]
     with captured_templates(app) as templates:
         response = client.post(endpoint,
                                data=rx_data,
                                follow_redirects=True)
         template, context = templates[0]
         patient = context["patient"]
         assert response.status_code == 200
         assert patient.id == 1
         assert len(patient.prescriptions) == 1
         assert patient.prescriptions[0].drug == rx_data["drug"]
         assert template.name == "patients/profile.html"
Beispiel #24
0
def test_user_register(app):
    with captured_templates(
            app) as templates, mail.record_messages() as outbox:
        payload = dict(username='******',
                       email='*****@*****.**',
                       submit='Sign Up')
        resp = app.test_client().post('/users/register',
                                      data=json.dumps(payload),
                                      follow_redirects=True)

        template, context = templates[0]
        print(resp.json)
        user = User.select().where(User.email == '*****@*****.**').first()
        print(context)
        users = User.select().where(User.email == '*****@*****.**').get()
        print(users)
        assert resp.status_code == 200
        assert len(outbox) == 1
Beispiel #25
0
def test_get_members_data(app, client, user_session):
    user = UserFactory.create()
    application = ApplicationFactory.create(environments=[{
        "name":
        "testing",
        "members": [{
            "user": user,
            "role_name": CSPRole.BASIC_ACCESS.value
        }],
    }])
    environment = application.environments[0]
    app_role = ApplicationRoles.get(user_id=user.id,
                                    application_id=application.id)
    env_role = EnvironmentRoles.get(application_role_id=app_role.id,
                                    environment_id=environment.id)

    user_session(application.portfolio.owner)

    with captured_templates(app) as templates:
        response = app.test_client().get(
            url_for("applications.settings", application_id=application.id))

        assert response.status_code == 200
        _, context = templates[-1]

        member = context["members"][0]
        assert member["role_id"] == app_role.id
        assert member["user_name"] == user.full_name
        assert member["permission_sets"] == {
            "perms_team_mgmt": False,
            "perms_env_mgmt": False,
            "perms_del_env": False,
        }
        assert member["environment_roles"] == [{
            "environment_id":
            str(environment.id),
            "environment_name":
            environment.name,
            "role":
            env_role.role,
        }]
        assert member["role_status"]
        assert isinstance(member["form"], UpdateMemberForm)
Beispiel #26
0
def test_edit_application_environments_obj(app, client, user_session):
    portfolio = PortfolioFactory.create()
    application = Applications.create(
        portfolio.owner,
        portfolio,
        "Snazzy Application",
        "A new application for me and my friends",
        {"env"},
    )
    env = application.environments[0]
    app_role1 = ApplicationRoleFactory.create(application=application)
    env_role1 = EnvironmentRoleFactory.create(application_role=app_role1,
                                              environment=env,
                                              role=CSPRole.BASIC_ACCESS.value)
    app_role2 = ApplicationRoleFactory.create(application=application,
                                              user=None)
    env_role2 = EnvironmentRoleFactory.create(application_role=app_role2,
                                              environment=env,
                                              role=CSPRole.NETWORK_ADMIN.value)

    user_session(portfolio.owner)

    with captured_templates(app) as templates:
        response = app.test_client().get(
            url_for("applications.settings", application_id=application.id))

        assert response.status_code == 200
        _, context = templates[-1]

        env_obj = context["environments_obj"][0]
        assert env_obj["name"] == env.name
        assert env_obj["id"] == env.id
        assert isinstance(env_obj["edit_form"], EditEnvironmentForm)
        assert {
            "user_name": app_role1.user_name,
            "status": env_role1.status.value,
        } in env_obj["members"]
        assert {
            "user_name": app_role2.user_name,
            "status": env_role2.status.value,
        } in env_obj["members"]
        assert isinstance(context["audit_events"], Paginator)