Exemple #1
0
def test_superuser_can_update_profile(superuser_api_client, profile):
    new_email_data = {"email": "*****@*****.**"}
    assert profile.email != new_email_data["email"]

    put_update(superuser_api_client, get_user_profile_url(profile), new_email_data)
    profile.refresh_from_db()
    assert profile.email == new_email_data["email"]
    assert profile.user != superuser_api_client.user
Exemple #2
0
def test_put_update_own_profile(user_api_client, profile):
    assert Profile.objects.count() == 1

    user_profile_url = get_user_profile_url(profile)
    phone_number_data = {"phone": "0461234567"}

    put_update(user_api_client, user_profile_url, phone_number_data)

    profile.refresh_from_db()
    assert profile.phone == phone_number_data["phone"]
Exemple #3
0
def test_put_nonexistent_concept_of_interest(user_api_client, profile):
    assert not profile.concepts_of_interest.exists()
    assert not Concept.objects.exists()

    serialized_concept_of_interest = "nonexistent:concept"
    concept_of_interest_data = {
        "concepts_of_interest": [serialized_concept_of_interest]
    }

    user_profile_url = get_user_profile_url(profile)
    put_update(
        user_api_client, user_profile_url, concept_of_interest_data, status_code=400
    )
Exemple #4
0
def test_put_concept_of_interest_in_wrong_format(user_api_client, profile, concept):
    assert not profile.concepts_of_interest.exists()
    assert Concept.objects.exists()

    badly_serialized_concept_of_interest = "{}-{}".format(
        concept.vocabulary.prefix, concept.code
    )
    concept_of_interest_data = {
        "concepts_of_interest": [badly_serialized_concept_of_interest]
    }

    user_profile_url = get_user_profile_url(profile)
    put_update(
        user_api_client, user_profile_url, concept_of_interest_data, status_code=400
    )
Exemple #5
0
def test_concept_of_interest_to_internal_value(user_api_client, profile, concept):
    assert not profile.concepts_of_interest.exists()

    serialized_concept_of_interest = "{}:{}".format(
        concept.vocabulary.prefix, concept.code
    )
    concept_of_interest_data = {
        "concepts_of_interest": [serialized_concept_of_interest]
    }

    user_profile_url = get_user_profile_url(profile)
    put_update(user_api_client, user_profile_url, concept_of_interest_data)

    assert profile.concepts_of_interest.exists()
    coi = profile.concepts_of_interest.first()
    assert coi == concept
Exemple #6
0
def test_update_own_profile_creates_change_log_entry(user_api_client):
    with reversion.create_revision():
        post_create(user_api_client, PROFILE_URL)

    profile = Profile.objects.latest("id")
    versions = Version.objects.get_for_object(profile)
    assert len(versions) == 1

    user_profile_url = get_user_profile_url(profile)
    email_data = {"email": "*****@*****.**"}
    put_update(user_api_client, user_profile_url, email_data)

    profile.refresh_from_db()
    versions = Version.objects.get_for_object(profile)
    assert len(versions) == 2
    assert versions[0].revision.user == user_api_client.user
    assert versions[0].field_dict["email"] == email_data["email"]
Exemple #7
0
def test_put_profile_image(user_api_client, profile, default_image):
    assert not profile.image

    user_profile_url = get_user_profile_url(profile)
    image_data = {"image": default_image}

    put_update(user_api_client, user_profile_url, image_data)

    profile.refresh_from_db()
    assert profile.image

    expected_image_path = os.path.join(
        settings.MEDIA_ROOT, get_user_media_folder(profile, default_image.name)
    )
    actual_image_path = os.path.join(settings.MEDIA_ROOT, profile.image.url)
    assert os.path.exists(actual_image_path)
    assert actual_image_path == expected_image_path
Exemple #8
0
def test_override_previous_profile_image(user_api_client, profile_with_image):
    assert profile_with_image.image

    old_image_path = os.path.join(settings.MEDIA_ROOT, profile_with_image.image.url)
    assert os.path.exists(old_image_path)

    new_image_file = create_in_memory_image_file("new_avatar", "png")
    new_image = SimpleUploadedFile("new_avatar.png", new_image_file.read(), "image/png")
    user_profile_url = get_user_profile_url(profile_with_image)
    new_image_data = {"image": new_image}

    put_update(user_api_client, user_profile_url, new_image_data)

    profile_with_image.refresh_from_db()

    new_image_path = os.path.join(settings.MEDIA_ROOT, profile_with_image.image.url)
    assert os.path.exists(new_image_path)
    assert not os.path.exists(old_image_path)