Exemplo n.º 1
0
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()
Exemplo n.º 2
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"
Exemplo n.º 3
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))
Exemplo n.º 4
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))
Exemplo n.º 5
0
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
0
def test_delete(api_client: TestClient, api_routes: AppRoutes,
                recipe_data: RecipeSiteTestCase, token):
    recipe_url = api_routes.recipes_recipe_slug(recipe_data.expected_slug)
    response = api_client.delete(recipe_url, headers=token)
    assert response.status_code == 200