-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de859bd
commit 3d74989
Showing
13 changed files
with
1,265 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
|
||
from extractor.extract import WPExtractor | ||
|
||
|
||
def _assert_extractor_valid(extractor: WPExtractor): | ||
assert isinstance(extractor.posts, pd.DataFrame) | ||
assert isinstance(extractor.media, pd.DataFrame) | ||
assert isinstance(extractor.tags, pd.DataFrame) | ||
assert isinstance(extractor.categories, pd.DataFrame) | ||
assert isinstance(extractor.users, pd.DataFrame) | ||
assert isinstance(extractor.pages, pd.DataFrame) | ||
|
||
|
||
def _assert_output_valid(out_dir: Path): | ||
assert (out_dir / "posts.json").is_file() | ||
assert (out_dir / "media.json").is_file() | ||
assert (out_dir / "tags.json").is_file() | ||
assert (out_dir / "categories.json").is_file() | ||
assert (out_dir / "users.json").is_file() | ||
assert (out_dir / "pages.json").is_file() | ||
|
||
|
||
def test_extract_no_scrape(datadir): | ||
extractor = WPExtractor( | ||
json_root=datadir / "json", | ||
) | ||
|
||
extractor.extract() | ||
_assert_extractor_valid(extractor) | ||
|
||
out_dir = datadir / "out_json" | ||
out_dir.mkdir() | ||
extractor.export(out_dir) | ||
_assert_output_valid(out_dir) | ||
|
||
|
||
def test_extract_scrape(datadir): | ||
extractor = WPExtractor( | ||
json_root=datadir / "json", | ||
scrape_root=datadir / "scrape" | ||
) | ||
|
||
extractor.extract() | ||
_assert_extractor_valid(extractor) | ||
|
||
assert 'translations' in extractor.posts.columns | ||
|
||
out_dir = datadir / "out_json" | ||
out_dir.mkdir() | ||
extractor.export(out_dir) | ||
_assert_output_valid(out_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
[ | ||
{ | ||
"id": 1, | ||
"count": 3, | ||
"description": "About Test Category One", | ||
"link": "https://example.org/test-category-one/", | ||
"name": "Test Category One", | ||
"slug": "test-category-one", | ||
"taxonomy": "category", | ||
"parent": 0, | ||
"meta": [], | ||
"yoast_head": "<!-- whole load of stuff -->", | ||
"yoast_head_json": { | ||
"title": "Test Category One - example.org", | ||
"robots": { | ||
"index": "index", | ||
"follow": "follow", | ||
"max-snippet": "max-snippet:-1", | ||
"max-image-preview": "max-image-preview:large", | ||
"max-video-preview": "max-video-preview:-1" | ||
}, | ||
"canonical": "https://example.org/test-category-one/", | ||
"og_locale": "en_US", | ||
"og_type": "article", | ||
"og_title": "Test Category One - example.org", | ||
"og_url": "https://example.org/test-category-one/", | ||
"og_site_name": "example.org", | ||
"twitter_card": "summary_large_image", | ||
"schema": "..." | ||
}, | ||
"_links": { | ||
"self": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/categories/1" | ||
} | ||
], | ||
"collection": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/categories" | ||
} | ||
], | ||
"about": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/taxonomies/category" | ||
} | ||
], | ||
"wp:post_type": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/posts?categories=1" | ||
} | ||
], | ||
"curies": [ | ||
{ | ||
"name": "wp", | ||
"href": "https://api.w.org/{rel}", | ||
"templated": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"id": 2, | ||
"count": 3, | ||
"description": "About Test Category Two", | ||
"link": "https://example.org/fr/test-category-two/", | ||
"name": "Test Category Two", | ||
"slug": "test-category-two", | ||
"taxonomy": "category", | ||
"parent": 0, | ||
"meta": [], | ||
"yoast_head": "<!-- whole load of stuff -->", | ||
"yoast_head_json": { | ||
"title": "Test Category One - example.org", | ||
"robots": { | ||
"index": "index", | ||
"follow": "follow", | ||
"max-snippet": "max-snippet:-1", | ||
"max-image-preview": "max-image-preview:large", | ||
"max-video-preview": "max-video-preview:-1" | ||
}, | ||
"canonical": "https://example.org/fr/test-category-two/", | ||
"og_locale": "en_FR", | ||
"og_type": "article", | ||
"og_title": "Test Category Three - example.org", | ||
"og_url": "https://example.org/fr/test-category-two/", | ||
"og_site_name": "example.org", | ||
"twitter_card": "summary_large_image", | ||
"schema": "..." | ||
}, | ||
"_links": { | ||
"self": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/categories/1" | ||
} | ||
], | ||
"collection": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/categories" | ||
} | ||
], | ||
"about": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/taxonomies/category" | ||
} | ||
], | ||
"wp:post_type": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/posts?categories=2" | ||
} | ||
], | ||
"curies": [ | ||
{ | ||
"name": "wp", | ||
"href": "https://api.w.org/{rel}", | ||
"templated": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"id": 3, | ||
"count": 3, | ||
"description": "About Test Category Three", | ||
"link": "https://example.org/fr/test-category-three/", | ||
"name": "Test Category Three", | ||
"slug": "test-category-three", | ||
"taxonomy": "category", | ||
"parent": 2, | ||
"meta": [], | ||
"yoast_head": "<!-- whole load of stuff -->", | ||
"yoast_head_json": { | ||
"title": "Test Category Three - example.org", | ||
"robots": { | ||
"index": "index", | ||
"follow": "follow", | ||
"max-snippet": "max-snippet:-1", | ||
"max-image-preview": "max-image-preview:large", | ||
"max-video-preview": "max-video-preview:-1" | ||
}, | ||
"canonical": "https://example.org/fr/test-category-three/", | ||
"og_locale": "en_US", | ||
"og_type": "article", | ||
"og_title": "Test Category One - example.org", | ||
"og_url": "https://example.org/fr/test-category-three/", | ||
"og_site_name": "example.org", | ||
"twitter_card": "summary_large_image", | ||
"schema": "..." | ||
}, | ||
"_links": { | ||
"self": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/categories/3" | ||
} | ||
], | ||
"collection": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/categories" | ||
} | ||
], | ||
"about": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/taxonomies/category" | ||
} | ||
], | ||
"wp:post_type": [ | ||
{ | ||
"href": "https://example.org/wp-json/wp/v2/posts?categories=3" | ||
} | ||
], | ||
"curies": [ | ||
{ | ||
"name": "wp", | ||
"href": "https://api.w.org/{rel}", | ||
"templated": true | ||
} | ||
] | ||
} | ||
} | ||
] |
Oops, something went wrong.