From 4de9a942300f6757a1f9ce020510001d69637775 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Wed, 29 Apr 2020 17:58:01 -0400 Subject: [PATCH] Additional Event parsing tests (#148) --- src/response/event/checked_event/status.rs | 2 +- .../event/checked_event/status/attachment.rs | 20 +-- src/response/event/checked_event/test.rs | 19 ++- src/response/redis/msg/test.rs | 1 - test_data/event_003.rs | 99 ++++++++++++ test_data/event_004.rs | 5 + test_data/event_005.rs | 143 ++++++++++++++++++ test_data/event_006.rs | 105 +++++++++++++ 8 files changed, 381 insertions(+), 13 deletions(-) create mode 100644 test_data/event_003.rs create mode 100644 test_data/event_004.rs create mode 100644 test_data/event_005.rs create mode 100644 test_data/event_006.rs diff --git a/src/response/event/checked_event/status.rs b/src/response/event/checked_event/status.rs index 71773d2..c702132 100644 --- a/src/response/event/checked_event/status.rs +++ b/src/response/event/checked_event/status.rs @@ -1,5 +1,5 @@ mod application; -mod attachment; +pub(super) mod attachment; mod card; mod poll; diff --git a/src/response/event/checked_event/status/attachment.rs b/src/response/event/checked_event/status/attachment.rs index c4d4265..ec21de4 100644 --- a/src/response/event/checked_event/status/attachment.rs +++ b/src/response/event/checked_event/status/attachment.rs @@ -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, - pub(super) text_url: Option, - pub(super) meta: Option, - pub(super) description: Option, - pub(super) blurhash: Option, + 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, + pub(in super::super) text_url: Option, + pub(in super::super) meta: Option, // TODO - is this the best type for the API? + pub(in super::super) description: Option, + pub(in super::super) blurhash: Option, } #[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, diff --git a/src/response/event/checked_event/test.rs b/src/response/event/checked_event/test.rs index c961e3e..65d74c4 100644 --- a/src/response/event/checked_event/test.rs +++ b/src/response/event/checked_event/test.rs @@ -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> { 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)) = ( diff --git a/src/response/redis/msg/test.rs b/src/response/redis/msg/test.rs index 1a5aeee..3d6252e 100644 --- a/src/response/redis/msg/test.rs +++ b/src/response/redis/msg/test.rs @@ -1,6 +1,5 @@ use super::*; use std::fs; -use std::path; #[test] fn parse_redis_subscribe() -> Result<(), RedisParseErr> { diff --git a/test_data/event_003.rs b/test_data/event_003.rs new file mode 100644 index 0000000..a60dc0a --- /dev/null +++ b/test_data/event_003.rs @@ -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: "

It was inevitable.

Real quotes from Dwarf Fortress dwarves every 5 minutes.

Too fast? Try @it_was_inevitable_slow.

#dwarffortress

".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: "@ben".to_string(), + verified_at: None, + }, + Field { + name: "Game".to_string(), + value: "http://bay12games.com/dwarves/".to_string(), + verified_at: None, + }, + Field { + name: "DFHack".to_string(), + value: "https://dfhack.org/bay12".to_string(), + verified_at: None, + }, + Field { + name: "Code".to_string(), + value: "https://git.io/fNjyH".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: "

I just wish to help somebody. I\'m uneasy.

— Mörul Zedotmedtob, Cook

".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, + }, +) \ No newline at end of file diff --git a/test_data/event_004.rs b/test_data/event_004.rs new file mode 100644 index 0000000..769b4e5 --- /dev/null +++ b/test_data/event_004.rs @@ -0,0 +1,5 @@ +Event::TypeSafe( + Delete { + payload: "104061222412800865".to_string(), + }, +) \ No newline at end of file diff --git a/test_data/event_005.rs b/test_data/event_005.rs new file mode 100644 index 0000000..8dbb218 --- /dev/null +++ b/test_data/event_005.rs @@ -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: "

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

".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: "https://twitter.com/telesurtv".to_string(), + verified_at: None, + }, + Field { + name: "En inglés".to_string(), + value: "@telesur_en".to_string(), + verified_at: None, + }, + Field { + name: "Operador".to_string(), + value: "@felix".to_string(), + verified_at: None, + }, + Field { + name: "Codigo".to_string(), + value: "https://yerbamate.dev/nutomic/tootbot".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: "

Autoridades internacionales de la #FórmulaUno decidieron suspender el Gran Premio de #Francia, que se celebraría el próximo 28 de junio

Ante esta decisión, la primera parada del Campeonato del Mundo será el Gran Premio de Austria https://www.telesurtv.net/news/suspendido-gran-premio-francia-formula-uno-covid-20200427-0011.html 

".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, + }, +) \ No newline at end of file diff --git a/test_data/event_006.rs b/test_data/event_006.rs new file mode 100644 index 0000000..98b2565 --- /dev/null +++ b/test_data/event_006.rs @@ -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: "

https://www.unitoo.it/progetti/radio/
Follow #UnitooLiveRadio
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à.

".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: "https://liberapay.com/UnitooWebRadio".to_string(), + verified_at: None, + }, + Field { + name: "Web Player".to_string(), + value: "https://radio.unitoo.it/public/liveradio".to_string(), + verified_at: None, + }, + Field { + name: "MP3 Link".to_string(), + value: "https://radio.unitoo.it/radio/8000/radio.mp3".to_string(), + verified_at: None, + }, + Field { + name: "Site".to_string(), + value: "https://www.unitoo.it/progetti/radio/".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: "

🎶 #NowPlaying
War
by GoSoundtrack
Listeners: 0
https://radio.unitoo.it/public/liveradio

".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, + }, +) \ No newline at end of file