Example #1
0
def test_verify_token_logs_out_other_tokens(client):
    token = "123"
    email = "*****@*****.**"

    verification_email = save(VerificationEmail(email=email, is_faculty=True))

    prior_token = save(
        VerificationToken(token="1010", email_id=verification_email.id))

    save(VerificationToken(token=token, email_id=verification_email.id))

    response = client.post("/api/verify-token", json={"token": token})

    assert response.status_code == HTTPStatus.OK.value

    assert prior_token.logged_out
Example #2
0
def test_set_unavailable_to_mentor(client, auth):
    token = "123"
    email = "*****@*****.**"

    verification_email = save(VerificationEmail(email=email, is_faculty=True))

    save(VerificationToken(token=token, email_id=verification_email.id))

    save(
        FacultyProfile(
            name="Test",
            contact_email=email,
            verification_email_id=verification_email.id,
            cadence="monthly",
        ))

    auth.login(token)

    data = {"available": False}

    response = client.post("/api/availability", json=data)

    assert response.status_code == HTTPStatus.OK.value
    assert response.json["available"] is False

    assert FacultyProfile.query.all()[0].available_for_mentoring is False
Example #3
0
def save_verification_token(email_id, token, is_personal_device):
    verification_token = VerificationToken(
        email_id=email_id, token=token, is_personal_device=is_personal_device)

    save(verification_token)

    return verification_token
Example #4
0
def test_get_public_tags(client, auth):
    token = "1234"
    verification_email = save(VerificationEmail(email="*****@*****.**"))

    save(VerificationToken(token=token, email_id=verification_email.id))

    profile = save(
        FacultyProfile(
            verification_email=verification_email,
            name="Test User",
            cadence="monthly",
            contact_email="*****@*****.**",
        )
    )

    activity_option = save(ActivityOption(value="activity", public=True))

    save(FacultyProfileActivity(profile=profile, tag=activity_option))

    auth.login(token)

    response = client.get("/api/faculty-search-tags")

    assert response.status_code == HTTPStatus.OK.value

    assert response.json == {
        "tags": {
            "activities": ["activity"],
            "clinical_specialties": [],
            "degrees": [],
            "hospital_affiliations": [],
            "parts_of_me": [],
            "professional_interests": [],
        }
    }
Example #5
0
def test_set_unavailable_to_mentor(client):
    token = '123'
    email = '*****@*****.**'

    verification_email = VerificationEmail(email=email)

    with app.app_context():
        db.session.add(verification_email)
        db.session.commit()

        db.session.add(
            VerificationToken(token=token, email_id=verification_email.id))

        profile = Profile(
            name='Test',
            contact_email=email,
            verification_email_id=verification_email.id,
            cadence='monthly',
        )
        db.session.add(profile)
        db.session.commit()

    data = {'available': False}

    response = client.post('/api/availability',
                           json=data,
                           headers={'Authorization': f'Token {token}'})

    assert response.status_code == HTTPStatus.OK.value
    assert response.json['available'] is False

    with app.app_context():
        assert Profile.query.all()[0].available_for_mentoring is False
Example #6
0
def test_create_profile_with_custom_tag(client):
    token = '1234'

    name = 'New User'
    email = '*****@*****.**'

    verification_email = save(VerificationEmail(email=email))

    save(VerificationToken(token=token, email_id=verification_email.id))

    clinical_specialties = ['Endocrinology, Diabetes & Metabolism']
    affiliations = ["Brigham and Women's Hospital"]

    professional_interests = ['Advocacy']
    parts_of_me = ['African American']
    activities = ['Surfing the web']

    profile = {
        'name': name,
        'contact_email': email,
        'clinical_specialties': clinical_specialties,
        'affiliations': affiliations,
        'professional_interests': professional_interests,
        'parts_of_me': parts_of_me,
        'activities': activities
    }

    response = client.post(
        f'/api/profile',
        json=profile,
        headers={'Authorization': f'Token {token}'}
    )

    assert response.status_code == http.HTTPStatus.CREATED.value

    profile_id = Profile.query.all()[0].id

    assert response.json == {
        'id': profile_id,
        'activities': activities,
        'additional_information': '',
        'professional_interests': professional_interests,
        'affiliations': affiliations,
        'cadence': None,
        'clinical_specialties': clinical_specialties,
        'contact_email': email,
        'name': name,
        'other_cadence': None,
        'parts_of_me': parts_of_me,
        'profile_image_url': None,
        'willing_discuss_personal': False,
        'willing_goal_setting': False,
        'willing_networking': False,
        'willing_career_guidance': False,
        'willing_student_group': False,
        'willing_shadowing': False
    }

    assert ActivityOption.query.filter(ActivityOption.value == activities[0]).one()
def test_update_profile(client):
    token = '1234'

    verification_email = save(VerificationEmail(email='*****@*****.**'))

    save(VerificationToken(token=token, email_id=verification_email.id))

    profile = save(
        Profile(
            name='Test User',
            verification_email_id=verification_email.id,
            contact_email='*****@*****.**',
            cadence='monthly',
        ))

    new_profile = {
        'name': 'New User',
        'contact_email': '*****@*****.**',
        'affiliations': [],
        'clinical_specialties': [],
        'professional_interests': [],
        'parts_of_me': [],
        'activities': [],
        'degrees': [],
    }

    response = client.put(
        f'/api/profiles/{profile.id}',
        json=new_profile,
        headers={'Authorization': f'Token {token}'},
    )

    assert response.status_code == http.HTTPStatus.OK.value

    check_json = {
        key: value
        for key, value in response.json.items() if key != 'id'
    }

    assert check_json == {
        'activities': [],
        'additional_information': '',
        'professional_interests': [],
        'affiliations': [],
        'cadence': 'monthly',
        'clinical_specialties': [],
        'degrees': [],
        'contact_email': '*****@*****.**',
        'name': 'New User',
        'other_cadence': None,
        'parts_of_me': [],
        'profile_image_url': None,
        'willing_discuss_personal': False,
        'willing_goal_setting': False,
        'willing_networking': False,
        'willing_career_guidance': False,
        'willing_student_group': False,
        'willing_shadowing': False,
    }
Example #8
0
def test_create_profile_with_custom_tag(client, auth):
    token = "1234"

    name = "New User"
    email = "*****@*****.**"

    verification_email = save(VerificationEmail(email=email))

    save(VerificationToken(token=token, email_id=verification_email.id))

    clinical_specialties = ["Endocrinology, Diabetes & Metabolism"]
    affiliations = ["Brigham and Women's Hospital"]

    professional_interests = ["Advocacy"]
    parts_of_me = ["African American"]
    activities = ["Surfing the web"]
    degrees = ["MBA"]

    profile = {
        "name": name,
        "contact_email": email,
        "clinical_specialties": clinical_specialties,
        "affiliations": affiliations,
        "professional_interests": professional_interests,
        "parts_of_me": parts_of_me,
        "activities": activities,
        "degrees": degrees,
        "cadence": "monthly",
    }

    auth.login(token)

    response = client.post("/api/profile", json=profile)

    assert response.status_code == http.HTTPStatus.CREATED.value

    profile_id = FacultyProfile.query.all()[0].id

    expected_fields = {
        "id": profile_id,
        "date_updated": MOCK_DATE.isoformat(),
        "activities": activities,
        "professional_interests": professional_interests,
        "affiliations": affiliations,
        "clinical_specialties": clinical_specialties,
        "contact_email": email,
        "degrees": degrees,
        "name": name,
        "parts_of_me": parts_of_me,
    }

    assert expected_fields.items() <= response.json.items()

    assert ActivityOption.query.filter(ActivityOption.value == activities[0]).one()
Example #9
0
def test_get_profiles_empty(client, auth):
    verification_email = save(VerificationEmail(email="*****@*****.**"))

    verification_token = save(
        VerificationToken(token="1234", email_id=verification_email.id))

    auth.login(verification_token.token)

    response = client.get("/api/profiles")

    assert response.status_code == http.HTTPStatus.OK.value

    assert response.json == {"profile_count": 0, "profiles": []}
Example #10
0
def create_test_verification_token(
    token: Optional[str] = None,
    verification_email: Optional[VerificationEmail] = None,
    is_admin: bool = False,
    is_faculty: bool = True,
) -> VerificationToken:
    if token is None:
        token = str(uuid.uuid4())

    if verification_email is None:
        verification_email = create_test_verification_email(
            is_faculty=is_faculty)

    return save(VerificationToken(token=token, email_id=verification_email.id))
def test_get_profiles_empty(client):
    verification_email = VerificationEmail(email='*****@*****.**')
    save(verification_email)

    verification_token = VerificationToken(token='1234',
                                           email_id=verification_email.id)
    save(verification_token)

    response = client.get(
        '/api/profiles',
        headers={'Authorization': f'Token {verification_token.token}'})

    assert response.status_code == http.HTTPStatus.OK.value

    assert response.json == {'profileCount': 0, 'profiles': []}
Example #12
0
def test_verify_valid_token(client):
    token = "123"
    email = "*****@*****.**"

    verification_email = save(VerificationEmail(email=email, is_faculty=True))

    save(VerificationToken(token=token, email_id=verification_email.id))

    response = client.post("/api/verify-token", json={"token": token})

    assert response.status_code == HTTPStatus.OK.value

    assert response.json == {
        "available_for_mentoring": None,
        "email": "*****@*****.**",
        "is_admin": None,
        "profile_id": None,
        "is_faculty": True,
    }
Example #13
0
def test_get_empty_public_tags(client, auth):
    token = "1234"
    verification_email = save(VerificationEmail(email="*****@*****.**"))

    verification_token = save(
        VerificationToken(token=token, email_id=verification_email.id)
    )

    auth.login(verification_token.token)

    response = client.get("/api/faculty-search-tags")

    assert response.status_code == HTTPStatus.OK.value

    assert response.json == {
        "tags": {
            "activities": [],
            "clinical_specialties": [],
            "degrees": [],
            "hospital_affiliations": [],
            "parts_of_me": [],
            "professional_interests": [],
        }
    }
Example #14
0
def test_verify_valid_token(client):
    token = '123'
    email = '*****@*****.**'

    verification_email = VerificationEmail(email=email, is_mentor=True)

    with app.app_context():
        db.session.add(verification_email)
        db.session.commit()

        db.session.add(
            VerificationToken(token=token, email_id=verification_email.id))
        db.session.commit()

    response = client.post('/api/verify-token', json={'token': token})

    assert response.status_code == HTTPStatus.OK.value
    assert response.json == {
        'available_for_mentoring': None,
        'email': '*****@*****.**',
        'is_admin': None,
        'profile_id': None,
        'is_mentor': True,
    }
Example #15
0
def main():
    context()

    profiles = [
        Profile(
            name='Manatee',
            contact_email='*****@*****.**',
            profile_image_url=
            f'{CLOUDINARY_PREFIX}/v1528666929/keonolml4mwgsixpprsh.png',
            clinical_specialties=[
                # 'Advanced Heart Failure & Transplant Cardiology',
                # 'Clinical Cardiac Electrophysiology',
                # 'Cardiovascular Disease',
            ],
            affiliations=[],  # 'Forsyth Institute'.split(),
            activities=[],
            cadence='monthly',
        ),
        Profile(
            name='Falcon!!',
            contact_email='*****@*****.**',
            profile_image_url=
            f'{CLOUDINARY_PREFIX}/v1528666737/nbnszojbvgqaxxlv1izh.png',
            clinical_specialties=
            [],  # 'Endocrinology, Diabetes & Metabolism'.split(','),
            affiliations=[],  # 'Dana-Farber Cancer Institute',
            activities=[],
            additional_information=(
                'I am excited to take students under my wing and'
                ' share my love of diabetes outcomes research!'),
            willing_shadowing=True,
            willing_networking=True,
            willing_goal_setting=True,
            willing_discuss_personal=True,
            willing_career_guidance=False,
            cadence='monthly',
        ),
        Profile(
            name='California Sea Lion',
            contact_email='*****@*****.**',
            profile_image_url=
            f'{CLOUDINARY_PREFIX}/v1528667191/aqzz8rwsutgdx4bzpbbn.png',
            clinical_specialties=
            [],  # 'Pediatric Hematology-Oncology,Pain Medicine'.split(','),
            affiliations=[],  # 'Children’s Hospital Boston',
            activities=[],
            additional_information=(
                "I'm happy to discuss personal aspects,"
                ' such as work-life balance, and how my role as a mother'
                ' impacts my work in pediatrics.'),
            willing_shadowing=True,
            willing_networking=True,
            willing_goal_setting=True,
            willing_discuss_personal=True,
            willing_career_guidance=False,
            cadence='monthly',
        ),
        Profile(
            name='Cat',
            contact_email='*****@*****.**',
            profile_image_url=
            f'{CLOUDINARY_PREFIX}/v1528741344/eo4fleywh2ljmj27i89s.png',
            clinical_specialties=
            [],  # 'Dermatology,Procedural Dermatology'.split(','),
            affiliations=[],  # 'Brigham and Women’s Hospital',
            activities=[],
            additional_information=
            ("I'm interested in meeting with students who are passionate about the skin!"
             ),
            willing_shadowing=True,
            willing_networking=False,
            willing_goal_setting=True,
            willing_discuss_personal=False,
            willing_career_guidance=False,
            cadence='quarterly',
        ),
        Profile(
            name='Puppy',
            contact_email='*****@*****.**',
            profile_image_url=
            f'{CLOUDINARY_PREFIX}/v1528668241/q8k83ozecn81gjq1qpjp.png',
            clinical_specialties=
            [],  # ['Addiction Psychiatry', 'Child & Adolescent Psychiatry'],
            affiliations=[],  # 'McLean Hospital',
            activities=[],
            additional_information=
            ('Looking forward to discussing all aspects of life and medicine with students.'
             ),
            willing_shadowing=True,
            willing_networking=True,
            willing_goal_setting=True,
            willing_discuss_personal=True,
            willing_career_guidance=False,
            cadence='biweekly',
        ),
    ]

    for index, profile in enumerate(profiles):
        email = VerificationEmail(email=f'animal{index}@gmail.com',
                                  is_mentor=True)

        save(email)

        profile.verification_email_id = email.id

        save(profile)

        print(profile.id)

    save(VerificationToken(token=str(uuid.uuid4()), email_id=email.id))
Example #16
0
        contact_email='*****@*****.**',
        profile_image_url=
        'https://res.cloudinary.com/dxzddmun4/image/upload/c_crop,h_200,w_200/v1528668241/q8k83ozecn81gjq1qpjp.png',
        clinical_specialties=
        'Addiction Psychiatry,Child & Adolescent Psychiatry'.split(','),
        affiliations='McLean Hospital',
        activities=[],
        additional_information=
        'Looking forward to discussing all aspects of life and medicine with students.',
        willing_shadowing=True,
        willing_networking=True,
        willing_goal_setting=True,
        willing_discuss_personal=True,
        willing_career_guidance=False,
        cadence='biweekly',
    ),
]

for index, profile in enumerate(profiles):
    email = VerificationEmail(email=f'animal{index}@gmail.com', is_mentor=True)

    save(email)

    profile.verification_email_id = email.id

    save(profile)

    print(profile.id)

save(VerificationToken(token=str(uuid.uuid4()), email_id=email.id))