Additional Event parsing tests (#148)

This commit is contained in:
Daniel Sockwell 2020-04-29 17:58:01 -04:00 committed by GitHub
parent d2b9fbe3b2
commit 4de9a94230
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 381 additions and 13 deletions

View File

@ -1,5 +1,5 @@
mod application;
mod attachment;
pub(super) mod attachment;
mod card;
mod poll;

View File

@ -3,20 +3,20 @@ use serde::{Deserialize, Serialize};
#[serde(deny_unknown_fields)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub(in super::super) struct Attachment {
pub(super) id: String,
pub(super) r#type: AttachmentType,
pub(super) url: String,
pub(super) preview_url: String,
pub(super) remote_url: Option<String>,
pub(super) text_url: Option<String>,
pub(super) meta: Option<serde_json::Value>,
pub(super) description: Option<String>,
pub(super) blurhash: Option<String>,
pub(in super::super) id: String,
pub(in super::super) r#type: AttachmentType,
pub(in super::super) url: String,
pub(in super::super) preview_url: String,
pub(in super::super) remote_url: Option<String>,
pub(in super::super) text_url: Option<String>,
pub(in super::super) meta: Option<serde_json::Value>, // TODO - is this the best type for the API?
pub(in super::super) description: Option<String>,
pub(in super::super) blurhash: Option<String>,
}
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub(super) enum AttachmentType {
pub(in super::super) enum AttachmentType {
Unknown,
Image,
Gifv,

View File

@ -1,11 +1,12 @@
use super::{super::*, *};
use checked_event::{
account::{Account, Field},
status::attachment::{Attachment, AttachmentType::*},
tag::Tag,
visibility::Visibility::*,
CheckedEvent::*,
*,
};
use serde_json::json;
use std::fs;
#[test]
@ -21,6 +22,22 @@ fn parse_redis_msg_to_event() -> Result<(), Box<dyn std::error::Error>> {
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_002.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_003.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_004.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_005.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_006.rs"
)),
];
while let (Ok(input), Some(output)) = (

View File

@ -1,6 +1,5 @@
use super::*;
use std::fs;
use std::path;
#[test]
fn parse_redis_subscribe() -> Result<(), RedisParseErr> {

99
test_data/event_003.rs Normal file
View File

@ -0,0 +1,99 @@
Event::TypeSafe(
Update {
payload: Status {
id: Id(
104072557586605107,
),
uri: "https://botsin.space/users/it_was_inevitable/statuses/104072557374505694".to_string(),
created_at: "2020-04-27T21:00:00.000Z".to_string(),
account: Account {
id: Id(
2160,
),
username: "it_was_inevitable".to_string(),
acct: "it_was_inevitable@botsin.space".to_string(),
url: "https://botsin.space/@it_was_inevitable".to_string(),
display_name: "Sentient Dwarf Fortress".to_string(),
note: "<p>It was inevitable.</p><p>Real quotes from Dwarf Fortress dwarves every 5 minutes.</p><p>Too fast? Try <span class=\"h-card\"><a href=\"https://botsin.space/@it_was_inevitable_slow\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>it_was_inevitable_slow</span></a></span>.</p><p><a href=\"https://botsin.space/tags/dwarffortress\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dwarffortress</span></a></p>".to_string(),
avatar: "https://instance.codesections.com/system/accounts/avatars/000/002/160/original/9d4fb963ee23aaef.gif?1585017843".to_string(),
avatar_static: "https://instance.codesections.com/system/accounts/avatars/000/002/160/static/9d4fb963ee23aaef.png?1585017843".to_string(),
header: "https://instance.codesections.com/system/accounts/headers/000/002/160/original/d52a62c64b18cac0.png?1585017845".to_string(),
header_static: "https://instance.codesections.com/system/accounts/headers/000/002/160/original/d52a62c64b18cac0.png?1585017845".to_string(),
locked: false,
emojis: [].to_vec(),
discoverable: Some(
true,
),
created_at: "2020-03-24T02:44:05.588Z".to_string(),
statuses_count: 171387,
followers_count: 384,
following_count: 4,
moved: None,
fields: Some(
[
Field {
name: "Overseer".to_string(),
value: "<span class=\"h-card\"><a href=\"https://mastodon.lubar.me/@ben\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>ben</span></a></span>".to_string(),
verified_at: None,
},
Field {
name: "Game".to_string(),
value: "<a href=\"http://bay12games.com/dwarves/\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">http://</span><span class=\"\">bay12games.com/dwarves/</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
Field {
name: "DFHack".to_string(),
value: "<a href=\"https://dfhack.org/bay12\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">dfhack.org/bay12</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
Field {
name: "Code".to_string(),
value: "<a href=\"https://git.io/fNjyH\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">git.io/fNjyH</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
].to_vec(),
),
bot: Some(
true,
),
source: None,
group: Some(
false,
),
last_status_at: Some(
"2020-04-27".to_string(),
),
},
content: "<p>I just wish to help somebody. I\'m uneasy.</p><p>— Mörul Zedotmedtob, Cook</p>".to_string(),
visibility: Public,
sensitive: false,
spoiler_text: "".to_string(),
media_attachments: [].to_vec(),
application: None,
mentions: [].to_vec(),
tags: [].to_vec(),
emojis: [].to_vec(),
reblogs_count: 0,
favourites_count: 0,
replies_count: 0,
url: Some(
"https://botsin.space/@it_was_inevitable/104072557374505694".to_string(),
),
in_reply_to_id: None,
in_reply_to_account_id: None,
reblog: None,
poll: None,
card: None,
language: Some(
"en".to_string(),
),
text: None,
favourited: None,
reblogged: None,
muted: None,
bookmarked: None,
pinned: None,
},
queued_at: None,
},
)

5
test_data/event_004.rs Normal file
View File

@ -0,0 +1,5 @@
Event::TypeSafe(
Delete {
payload: "104061222412800865".to_string(),
},
)

143
test_data/event_005.rs Normal file
View File

@ -0,0 +1,143 @@
Event::TypeSafe(
Update {
payload: Status {
id: Id(
104072561966487967,
),
uri: "https://newsbots.eu/users/telesur_es/statuses/104072561638766292".to_string(),
created_at: "2020-04-27T21:01:05.000Z".to_string(),
account: Account {
id: Id(
720,
),
username: "telesur_es".to_string(),
acct: "telesur_es@newsbots.eu".to_string(),
url: "https://newsbots.eu/@telesur_es".to_string(),
display_name: "teleSUR TV (Extraoficial)".to_string(),
note: "<p>Con más 40 corresponsales en el mundo, alzamos nuestra voz donde otros medios callan. teleSUR es la señal informativa de América Latina</p>".to_string(),
avatar: "https://instance.codesections.com/system/accounts/avatars/000/000/720/original/57b77baa5d424d0c.jpeg?1584097695".to_string(),
avatar_static: "https://instance.codesections.com/system/accounts/avatars/000/000/720/original/57b77baa5d424d0c.jpeg?1584097695".to_string(),
header: "https://instance.codesections.com/headers/original/missing.png".to_string(),
header_static: "https://instance.codesections.com/headers/original/missing.png".to_string(),
locked: false,
emojis: [].to_vec(),
discoverable: Some(
false,
),
created_at: "2020-03-13T11:08:17.249Z".to_string(),
statuses_count: 40648,
followers_count: 898,
following_count: 0,
moved: None,
fields: Some(
[
Field {
name: "Fuente".to_string(),
value: "<a href=\"https://twitter.com/telesurtv\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">twitter.com/telesurtv</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
Field {
name: "En inglés".to_string(),
value: "<span class=\"h-card\"><a href=\"https://newsbots.eu/@telesur_en\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>telesur_en</span></a></span>".to_string(),
verified_at: None,
},
Field {
name: "Operador".to_string(),
value: "<span class=\"h-card\"><a href=\"https://radical.town/@felix\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>felix</span></a></span>".to_string(),
verified_at: None,
},
Field {
name: "Codigo".to_string(),
value: "<a href=\"https://yerbamate.dev/nutomic/tootbot\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">yerbamate.dev/nutomic/tootbot</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
].to_vec(),
),
bot: Some(
true,
),
source: None,
group: Some(
false,
),
last_status_at: Some(
"2020-04-27".to_string(),
),
},
content: "<p>Autoridades internacionales de la <a href=\"https://newsbots.eu/tags/F%C3%B3rmulaUno\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>FórmulaUno</span></a> decidieron suspender el Gran Premio de <a href=\"https://newsbots.eu/tags/Francia\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Francia</span></a>, que se celebraría el próximo 28 de junio</p><p>Ante esta decisión, la primera parada del Campeonato del Mundo será el Gran Premio de Austria <a href=\"https://www.telesurtv.net/news/suspendido-gran-premio-francia-formula-uno-covid-20200427-0011.html\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"ellipsis\">telesurtv.net/news/suspendido-</span><span class=\"invisible\">gran-premio-francia-formula-uno-covid-20200427-0011.html</span></a>&nbsp;</p>".to_string(),
visibility: Public,
sensitive: true,
spoiler_text: "".to_string(),
media_attachments: [
Attachment {
id: "13283".to_string(),
r#type: Image,
url: "https://instance.codesections.com/system/media_attachments/files/000/013/283/original/0d148b189319d632.jpeg?1588021269".to_string(),
preview_url: "https://instance.codesections.com/system/media_attachments/files/000/013/283/small/0d148b189319d632.jpeg?1588021269".to_string(),
remote_url: Some(
"https://newsbots.eu/system/media_attachments/files/000/199/561/original/8f1042130e797306.jpeg".to_string(),
),
text_url: None,
meta: Some(
json!(
{
"original": {
"aspect": 1.7751479289940828,
"height": 338,
"size": "600x338",
"width": 600,
},
"small": {
"aspect": 1.7766666666666666,
"height": 300,
"size": "533x300",
"width": 533,
},
}
),
),
description: None,
blurhash: Some(
"U9Dcs{QU4mTGu2VFWAkpDinl%2%LxZ%Lxuxu".to_string(),
),
},
].to_vec(),
application: None,
mentions: [].to_vec(),
tags: [
Tag {
name: "FórmulaUno".to_string(),
url: "https://instance.codesections.com/tags/F%C3%B3rmulaUno".to_string(),
history: None,
},
Tag {
name: "francia".to_string(),
url: "https://instance.codesections.com/tags/francia".to_string(),
history: None,
},
].to_vec(),
emojis: [].to_vec(),
reblogs_count: 0,
favourites_count: 0,
replies_count: 0,
url: Some(
"https://newsbots.eu/@telesur_es/104072561638766292".to_string(),
),
in_reply_to_id: None,
in_reply_to_account_id: None,
reblog: None,
poll: None,
card: None,
language: Some(
"es".to_string(),
),
text: None,
favourited: None,
reblogged: None,
muted: None,
bookmarked: None,
pinned: None,
},
queued_at: None,
},
)

105
test_data/event_006.rs Normal file
View File

@ -0,0 +1,105 @@
Event::TypeSafe(
Update {
payload: Status {
id: Id(
104072567176319159,
),
uri: "https://botsin.space/users/UnitooWebRadio/statuses/104072559646747168".to_string(),
created_at: "2020-04-27T21:00:34.000Z".to_string(),
account: Account {
id: Id(
2161,
),
username: "UnitooWebRadio".to_string(),
acct: "UnitooWebRadio@botsin.space".to_string(),
url: "https://botsin.space/@UnitooWebRadio".to_string(),
display_name: "(BoT) Radio Unitoo".to_string(),
note: "<p><a href=\"https://www.unitoo.it/progetti/radio/\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"\">unitoo.it/progetti/radio/</span><span class=\"invisible\"></span></a><br>Follow <a href=\"https://botsin.space/tags/UnitooLiveRadio\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>UnitooLiveRadio</span></a><br>Una WebRadio Italiana che trasmette musica RoyaltyFree e che tratta tematiche inerenti al mondo del Software Libero e Open Source, Adatta ad ascoltatori di qualsiasi genere / credo / età.</p>".to_string(),
avatar: "https://instance.codesections.com/system/accounts/avatars/000/002/161/original/c1949ebb71a0bf25.png?1585156010".to_string(),
avatar_static: "https://instance.codesections.com/system/accounts/avatars/000/002/161/original/c1949ebb71a0bf25.png?1585156010".to_string(),
header: "https://instance.codesections.com/headers/original/missing.png".to_string(),
header_static: "https://instance.codesections.com/headers/original/missing.png".to_string(),
locked: false,
emojis: [].to_vec(),
discoverable: Some(
true,
),
created_at: "2020-03-24T02:48:10.344Z".to_string(),
statuses_count: 9460,
followers_count: 13,
following_count: 3,
moved: None,
fields: Some(
[
Field {
name: "Liberapay".to_string(),
value: "<a href=\"https://liberapay.com/UnitooWebRadio\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">liberapay.com/UnitooWebRadio</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
Field {
name: "Web Player".to_string(),
value: "<a href=\"https://radio.unitoo.it/public/liveradio\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">radio.unitoo.it/public/liverad</span><span class=\"invisible\">io</span></a>".to_string(),
verified_at: None,
},
Field {
name: "MP3 Link".to_string(),
value: "<a href=\"https://radio.unitoo.it/radio/8000/radio.mp3\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">radio.unitoo.it/radio/8000/rad</span><span class=\"invisible\">io.mp3</span></a>".to_string(),
verified_at: None,
},
Field {
name: "Site".to_string(),
value: "<a href=\"https://www.unitoo.it/progetti/radio/\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"\">unitoo.it/progetti/radio/</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
].to_vec(),
),
bot: Some(
true,
),
source: None,
group: Some(
false,
),
last_status_at: Some(
"2020-04-27".to_string(),
),
},
content: "<p>🎶 <a href=\"https://botsin.space/tags/NowPlaying\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>NowPlaying</span></a><br>War<br>by GoSoundtrack<br>Listeners: 0<br><a href=\"https://radio.unitoo.it/public/liveradio\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">radio.unitoo.it/public/liverad</span><span class=\"invisible\">io</span></a></p>".to_string(),
visibility: Public,
sensitive: false,
spoiler_text: "".to_string(),
media_attachments: [].to_vec(),
application: None,
mentions: [].to_vec(),
tags: [
Tag {
name: "nowplaying".to_string(),
url: "https://instance.codesections.com/tags/nowplaying".to_string(),
history: None,
},
].to_vec(),
emojis: [].to_vec(),
reblogs_count: 0,
favourites_count: 0,
replies_count: 0,
url: Some(
"https://botsin.space/@UnitooWebRadio/104072559646747168".to_string(),
),
in_reply_to_id: None,
in_reply_to_account_id: None,
reblog: None,
poll: None,
card: None,
language: Some(
"en".to_string(),
),
text: None,
favourited: None,
reblogged: None,
muted: None,
bookmarked: None,
pinned: None,
},
queued_at: None,
},
)