def test_delete_page(api_client: TestClient, api_routes: AppRoutes, token):
    response = api_client.delete(api_routes.site_settings_custom_pages_id(1), headers=token)

    assert response.status_code == 200

    response = api_client.get(api_routes.site_settings_custom_pages_id(1))

    assert json.loads(response.text) is None
Example #2
0
def test_import(api_client: TestClient, api_routes: AppRoutes, backup_data, token):
    import_route = api_routes.backups_file_name_import("dev_sample_data_2021-Feb-13.zip")
    response = api_client.post(import_route, json=backup_data, headers=token)
    assert response.status_code == 200
    for _, value in json.loads(response.content).items():
        for v in value:
            assert v["status"] is True
def test_update_group(api_client: TestClient, api_routes: AppRoutes, token):
    new_data = {
        "name": "New Group Name",
        "id": 2,
        "categories": [],
        "webhookUrls": [],
        "webhookTime": "00:00",
        "webhookEnable": False,
        "users": [],
        "mealplans": [],
    }
    # Test Update
    response = api_client.put(api_routes.groups_id(2),
                              json=new_data,
                              headers=token)
    assert response.status_code == 200
    assert json.loads(response.text) == {
        "snackbar": {
            "text": "Group Settings Updated",
            "type": "success"
        }
    }

    # Validate Changes
    response = api_client.get(api_routes.groups, headers=token)
    all_groups = json.loads(response.text)
    id_2 = filter(lambda x: x["id"] == 2, all_groups)
    assert next(id_2) == new_data
def test_read_update(api_client: TestClient, api_routes: AppRoutes,
                     recipe_data, token):
    recipe_url = api_routes.recipes_recipe_slug(recipe_data.expected_slug)
    response = api_client.get(recipe_url, headers=token)
    assert response.status_code == 200

    recipe = json.loads(response.content)

    test_notes = [
        {
            "title": "My Test Title1",
            "text": "My Test Text1"
        },
        {
            "title": "My Test Title2",
            "text": "My Test Text2"
        },
    ]
    recipe["notes"] = test_notes
    recipe["tools"] = ["one tool", "two tool"]

    test_categories = ["one", "two", "three"]
    recipe["recipeCategory"] = test_categories

    response = api_client.put(recipe_url, json=recipe, headers=token)

    assert response.status_code == 200
    assert json.loads(response.text) == recipe_data.expected_slug

    response = api_client.get(recipe_url)

    recipe = json.loads(response.content)

    assert recipe["notes"] == test_notes
    assert recipe["recipeCategory"].sort() == test_categories.sort()
def test_read_theme(api_client: TestClient, api_routes: AppRoutes,
                    default_theme, new_theme):
    for theme in [default_theme, new_theme]:
        response = api_client.get(
            api_routes.themes_theme_name(theme.get("name")))
        assert response.status_code == 200
        assert json.loads(response.content) == theme
Example #6
0
def test_delete_theme(api_client: TestClient, api_routes: AppRoutes,
                      default_theme, new_theme, token):
    for theme in [default_theme, new_theme]:
        response = api_client.delete(api_routes.themes_id(theme.get("id")),
                                     headers=token)

        assert response.status_code == 200
def test_read_page(api_client: TestClient, api_routes: AppRoutes, page_data):
    response = api_client.get(api_routes.site_settings_custom_pages_id(1))

    page_data["id"] = 1
    page_data["slug"] = "my-new-page"

    assert json.loads(response.text) == page_data
def test_update_mealplan(api_client: TestClient, api_routes: AppRoutes, slug_1,
                         slug_2, token):

    response = api_client.get(api_routes.meal_plans_all, headers=token)

    existing_mealplan = json.loads(response.text)
    existing_mealplan = existing_mealplan[0]

    # Swap
    plan_uid = existing_mealplan.get("uid")
    existing_mealplan["meals"][0]["slug"] = slug_2
    existing_mealplan["meals"][1]["slug"] = slug_1

    response = api_client.put(api_routes.meal_plans_plan_id(plan_uid),
                              json=existing_mealplan,
                              headers=token)

    assert response.status_code == 200

    response = api_client.get(api_routes.meal_plans_all, headers=token)
    existing_mealplan = json.loads(response.text)
    existing_mealplan = existing_mealplan[0]

    assert existing_mealplan["meals"][0]["slug"] == slug_2
    assert existing_mealplan["meals"][1]["slug"] == slug_1
Example #9
0
def test_import_nextcloud_directory(api_client: TestClient,
                                    api_routes: AppRoutes, nextcloud_zip,
                                    token):
    selection = nextcloud_zip.name
    import_url = api_routes.migrations_source_file_name_import(
        "nextcloud", selection)
    response = api_client.post(import_url, headers=token)

    assert response.status_code == 200

    report = json.loads(response.content)
    assert report["failed"] == []

    expected_slug = "air-fryer-shrimp"
    recipe_url = api_routes.recipes_recipe_slug(expected_slug)
    response = api_client.get(recipe_url)
    assert response.status_code == 200
Example #10
0
def test_reset_user_password(api_client: TestClient, api_routes: AppRoutes, token):
    response = api_client.put(api_routes.users_id_reset_password(3), headers=token)

    assert response.status_code == 200

    form_data = {"username": "******", "password": "******"}
    response = api_client.post(api_routes.auth_token, form_data)

    assert response.status_code == 200
Example #11
0
def test_import_chowdown_directory(api_client: TestClient,
                                   api_routes: AppRoutes, chowdown_zip: Path,
                                   token):
    delete_url = api_routes.recipes_recipe_slug("roasted-okra")
    api_client.delete(delete_url,
                      headers=token)  # TODO: Manage Test Data better
    selection = chowdown_zip.name

    import_url = api_routes.migrations_import_type_file_name_import(
        "chowdown", selection)
    response = api_client.post(import_url, headers=token)

    assert response.status_code == 200

    reports = json.loads(response.content)

    for report in reports:
        assert report.get("status") is True
def test_block_delete(api_client: TestClient, api_routes: AppRoutes, token):
    response = api_client.delete(api_routes.groups_id(1), headers=token)

    assert json.loads(response.text) == {
        "snackbar": {
            "text": "Cannot delete default group",
            "type": "error"
        }
    }
Example #13
0
def test_delete_chowdown_migration_data(api_client: TestClient,
                                        api_routes: AppRoutes,
                                        chowdown_zip: Path, token):
    selection = chowdown_zip.name
    delete_url = api_routes.migrations_import_type_file_name_delete(
        "chowdown", selection)
    response = api_client.delete(delete_url, headers=token)

    assert response.status_code == 200
    assert not app_dirs.MIGRATION_DIR.joinpath(chowdown_zip.name).is_file()
Example #14
0
def test_create_by_json(api_client: TestClient, api_routes: AppRoutes, token,
                        raw_recipe):
    recipe_url = api_routes.recipes_recipe_slug("banana-bread")
    api_client.delete(recipe_url, headers=token)
    response = api_client.post(api_routes.recipes_create,
                               json=raw_recipe,
                               headers=token)

    assert response.status_code == 201
    assert json.loads(response.text) == "banana-bread"
Example #15
0
def test_delete__nextcloud_migration_data(api_client: TestClient,
                                          api_routes: AppRoutes,
                                          nextcloud_zip: Path, token):
    selection = nextcloud_zip.name
    delete_url = api_routes.migrations_source_file_name_delete(
        "nextcloud", selection)
    response = api_client.delete(delete_url, headers=token)

    assert response.status_code == 200
    assert not app_dirs.MIGRATION_DIR.joinpath(nextcloud_zip.name).is_file()
Example #16
0
def slug_2(api_client: TestClient, api_routes: AppRoutes, token,
           recipe_store: list[RecipeSiteTestCase]):
    slug_2 = api_client.post(api_routes.recipes_create_url,
                             json={"url": recipe_store[1].url},
                             headers=token)
    slug_2 = json.loads(slug_2.content)

    yield slug_2

    api_client.delete(api_routes.recipes_recipe_slug(slug_2))
Example #17
0
def test_delete_sign_up_link(api_client: TestClient, api_routes: AppRoutes,
                             token, active_link: SignUpToken, sign_up_user):
    response = api_client.delete(api_routes.users_sign_ups_token(
        active_link.token),
                                 headers=token)
    assert response.status_code == 200

    # Validate Token is Gone
    response = api_client.get(api_routes.users_sign_ups, headers=token)
    assert sign_up_user not in json.loads(response.content)
Example #18
0
def test_update_user_image(
    api_client: TestClient, api_routes: AppRoutes, test_image_jpg: Path, test_image_png: Path, token
):
    response = api_client.post(
        api_routes.users_id_image(2), files={"profile_image": test_image_jpg.open("rb")}, headers=token
    )

    assert response.status_code == 200

    response = api_client.post(
        api_routes.users_id_image(2), files={"profile_image": test_image_png.open("rb")}, headers=token
    )

    assert response.status_code == 200

    directory = app_dirs.USER_DIR.joinpath("2")
    assert directory.joinpath("profile_image.png").is_file()

    # Old profile images are removed
    assert 1 == len([file for file in directory.glob("profile_image.*") if file.is_file()])
Example #19
0
def slug_1(api_client: TestClient, api_routes: AppRoutes, token,
           recipe_store: list[RecipeTestData]):
    # Slug 1
    slug_1 = api_client.post(api_routes.recipes_create_url,
                             json={"url": recipe_store[0].url},
                             headers=token)
    slug_1 = json.loads(slug_1.content)

    yield slug_1

    api_client.delete(api_routes.recipes_recipe_slug(slug_1))
Example #20
0
def test_upload_chowdown_zip(api_client: TestClient, api_routes: AppRoutes,
                             chowdown_zip: Path, token):
    upload_url = api_routes.migrations_source_upload("chowdown")
    response = api_client.post(upload_url,
                               files={"archive": chowdown_zip.open("rb")},
                               headers=token)

    assert response.status_code == 200

    assert app_dirs.MIGRATION_DIR.joinpath("chowdown",
                                           chowdown_zip.name).is_file()
def test_create_by_url(api_client: TestClient, api_routes: AppRoutes,
                       recipe_data: RecipeTestData, token):

    api_client.delete(api_routes.recipes_recipe_slug(
        recipe_data.expected_slug),
                      headers=token)
    response = api_client.post(api_routes.recipes_create_url,
                               json={"url": recipe_data.url},
                               headers=token)
    assert response.status_code == 201
    assert json.loads(response.text) == recipe_data.expected_slug
Example #22
0
def test_upload_nextcloud_zip(api_client: TestClient, api_routes: AppRoutes,
                              nextcloud_zip, token):
    upload_url = api_routes.migrations_import_type_upload("nextcloud")
    response = api_client.post(upload_url,
                               files={"archive": nextcloud_zip.open("rb")},
                               headers=token)

    assert response.status_code == 200

    assert app_dirs.MIGRATION_DIR.joinpath("nextcloud",
                                           nextcloud_zip.name).is_file()
Example #23
0
def test_update_theme(api_client: TestClient, api_routes: AppRoutes, token,
                      new_theme):
    theme_colors = {
        "primary": "#E12345",
        "accent": "#012345",
        "secondary": "#973542",
        "success": "#5AB1BB",
        "info": "#4990BA",
        "warning": "#FF4081",
        "error": "#EF4432",
    }

    new_theme["colors"] = theme_colors
    new_theme["name"] = "New Theme Name"
    response = api_client.put(api_routes.themes_id(new_theme.get("id")),
                              json=new_theme,
                              headers=token)
    assert response.status_code == 200
    response = api_client.get(api_routes.themes_id(new_theme.get("id")))
    assert json.loads(response.content) == new_theme
Example #24
0
def test_delete_mealplan(api_client: TestClient, api_routes: AppRoutes, token):
    response = api_client.get(api_routes.meal_plans_all, headers=token)

    assert response.status_code == 200
    existing_mealplan = json.loads(response.text)
    existing_mealplan = existing_mealplan[0]

    plan_uid = existing_mealplan.get("uid")
    response = api_client.delete(api_routes.meal_plans_plan_id(plan_uid),
                                 headers=token)

    assert response.status_code == 200
Example #25
0
def test_create_theme(api_client: TestClient, api_routes: AppRoutes, new_theme,
                      token):

    response = api_client.post(api_routes.themes_create,
                               json=new_theme,
                               headers=token)
    assert response.status_code == 201

    response = api_client.get(api_routes.themes_id(new_theme.get("id")),
                              headers=token)
    assert response.status_code == 200
    assert json.loads(response.content) == new_theme
Example #26
0
def test_import_nextcloud_directory(api_client: TestClient,
                                    api_routes: AppRoutes, nextcloud_zip,
                                    token):
    selection = nextcloud_zip.name
    import_url = api_routes.migrations_import_type_file_name_import(
        "nextcloud", selection)
    response = api_client.post(import_url, headers=token)

    assert response.status_code == 200

    reports = json.loads(response.content)
    for report in reports:
        assert report.get("status") is True
Example #27
0
def test_import_chowdown_directory(api_client: TestClient,
                                   api_routes: AppRoutes, chowdown_zip: Path,
                                   token):
    delete_url = api_routes.recipes_recipe_slug("roasted-okra")
    api_client.delete(delete_url,
                      headers=token)  # TODO: Manage Test Data better
    selection = chowdown_zip.name

    import_url = api_routes.migrations_source_file_name_import(
        "chowdown", selection)
    response = api_client.post(import_url, headers=token)

    assert response.status_code == 200

    report = json.loads(response.content)
    assert report["failed"] == []

    expected_slug = "roasted-okra"

    recipe_url = api_routes.recipes_recipe_slug(expected_slug)
    response = api_client.get(recipe_url)
    assert response.status_code == 200
Example #28
0
def test_update_user(api_client: TestClient, api_routes: AppRoutes, token):
    update_data = {
        "id": 1,
        "fullName": "Updated Name",
        "email": "*****@*****.**",
        "group": "Home",
        "admin": True
    }
    response = api_client.put(api_routes.users_id(1),
                              headers=token,
                              json=update_data)

    assert response.status_code == 200
    assert json.loads(response.text).get("access_token")
Example #29
0
def test_new_user_signup(api_client: TestClient, api_routes: AppRoutes,
                         active_link: SignUpToken, sign_up_user):

    # Creation
    response = api_client.post(api_routes.users_sign_ups_token(
        active_link.token),
                               json=sign_up_user)
    assert response.status_code == 200

    # Login
    form_data = {
        "username": "******",
        "password": "******"
    }
    response = api_client.post(api_routes.auth_token, form_data)

    assert response.status_code == 200
Example #30
0
def test_rename(api_client: TestClient, api_routes: AppRoutes,
                recipe_data: RecipeSiteTestCase, token):
    recipe_url = api_routes.recipes_recipe_slug(recipe_data.expected_slug)
    response = api_client.get(recipe_url, headers=token)
    assert response.status_code == 200

    recipe = json.loads(response.text)
    new_name = recipe.get("name") + "-rename"
    new_slug = slugify(new_name)
    recipe["name"] = new_name

    response = api_client.put(recipe_url, json=recipe, headers=token)

    assert response.status_code == 200
    assert json.loads(response.text).get("slug") == new_slug

    recipe_data.expected_slug = new_slug