1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use bumble::wrapper::{self, core::Uuid16};
16 use pyo3::{intern, prelude::*, types::PyDict};
17 use std::collections;
18
19 #[pyo3_asyncio::tokio::test]
company_ids_matches_python() -> PyResult<()>20 async fn company_ids_matches_python() -> PyResult<()> {
21 let ids_from_python = Python::with_gil(|py| {
22 PyModule::import(py, intern!(py, "bumble.company_ids"))?
23 .getattr(intern!(py, "COMPANY_IDENTIFIERS"))?
24 .downcast::<PyDict>()?
25 .into_iter()
26 .map(|(k, v)| {
27 Ok((
28 Uuid16::from_be_bytes(k.extract::<u16>()?.to_be_bytes()),
29 v.str()?.to_str()?.to_string(),
30 ))
31 })
32 .collect::<PyResult<collections::HashMap<_, _>>>()
33 })?;
34
35 assert_eq!(
36 wrapper::assigned_numbers::COMPANY_IDS
37 .iter()
38 .map(|(id, name)| (*id, name.to_string()))
39 .collect::<collections::HashMap<_, _>>(),
40 ids_from_python,
41 "Company ids do not match -- re-run gen_assigned_numbers?"
42 );
43 Ok(())
44 }
45