Skip to content

Commit d4d6b60

Browse files
committed
is it worky??
1 parent b6768f9 commit d4d6b60

File tree

33 files changed

+119
-120
lines changed

33 files changed

+119
-120
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cot-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tracing = "0.1.41"
4343

4444
[dev-dependencies]
4545
async-stream.workspace = true
46-
cot.workspace = true
46+
cot = { workspace = true, features = ["test"] }
4747
futures.workspace = true
4848
tokio = { workspace = true, features = ["macros"] }
4949

cot-core/src/openapi.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use std::future::Future;
1010
use std::marker::PhantomData;
1111
use std::pin::Pin;
1212

13-
use aide::openapi::{Operation, PathItem, StatusCode};
1413
use aide::openapi::{
15-
MediaType, Parameter, ParameterData, ParameterSchemaOrContent, PathStyle,
16-
QueryStyle, ReferenceOr, RequestBody,
14+
MediaType, Parameter, ParameterData, ParameterSchemaOrContent, PathStyle, QueryStyle,
15+
ReferenceOr, RequestBody,
1716
};
17+
use aide::openapi::{Operation, PathItem, StatusCode};
1818
use indexmap::IndexMap;
1919
use schemars::{JsonSchema, Schema, SchemaGenerator};
2020
use serde_json::Value;
@@ -127,7 +127,6 @@ pub trait AsApiRoute {
127127
) -> PathItem;
128128
}
129129

130-
131130
/// A trait that can be implemented for types that should be taken into
132131
/// account when generating OpenAPI paths.
133132
///
@@ -736,7 +735,6 @@ fn extract_is_required(object_item: &mut Schema) -> bool {
736735
}
737736
}
738737

739-
740738
fn param_with_name(param_name: String, schema: Schema, required: bool) -> ParameterData {
741739
ParameterData {
742740
name: param_name,
@@ -753,4 +751,4 @@ fn param_with_name(param_name: String, schema: Schema, required: bool) -> Parame
753751
explode: None,
754752
extensions: IndexMap::default(),
755753
}
756-
}
754+
}

cot-core/src/openapi/method.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
use std::fmt::{Debug, Formatter};
88

99
use aide::openapi::Operation;
10-
use crate::openapi::{
11-
AsApiOperation, AsApiRoute, BoxApiRequestHandler, RouteContext, into_box_api_request_handler
12-
};
13-
use crate::request::Request;
14-
use crate::router::method::{InnerHandler, InnerMethodRouter};
1510
use schemars::SchemaGenerator;
1611

1712
use crate::handler::RequestHandler;
13+
use crate::openapi::{
14+
into_box_api_request_handler, AsApiOperation, AsApiRoute, BoxApiRequestHandler, RouteContext,
15+
};
16+
use crate::request::Request;
1817
use crate::response::Response;
18+
use crate::router::method::{InnerHandler, InnerMethodRouter};
1919

2020
/// A version of [`MethodRouter`](crate::router::method::MethodRouter) that
2121
/// supports OpenAPI.
@@ -520,10 +520,10 @@ mod tests {
520520
use cot::test::TestRequestBuilder;
521521

522522
use super::*;
523-
use crate::Method;
524523
use crate::error::MethodNotAllowed;
525524
use crate::request::extractors::Path;
526525
use crate::response::{IntoResponse, Response};
526+
use crate::{Method, StatusCode};
527527

528528
async fn test_handler(method: Method) -> crate::Result<Response> {
529529
Html::new(method.as_str()).into_response()

cot-core/src/request.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ pub struct AppName(pub String);
282282
#[cfg(test)]
283283
mod tests {
284284
use super::*;
285+
use crate::request::extractors::Path;
286+
use crate::Body;
285287

286288
#[test]
287289
fn path_params() {

cot-core/src/request/extractors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,15 @@ impl FromRequestHead for Method {
268268
/// ```
269269
pub use cot_macros::FromRequestHead;
270270

271+
271272
use crate::impl_into_cot_error;
272273

273274
#[cfg(test)]
274275
mod tests {
276+
use cot::form::Form;
275277
use cot::html::Html;
278+
use cot::request::extractors::RequestForm;
279+
use cot::reverse;
276280
use cot::router::{Route, Router, Urls};
277281
use cot::test::TestRequestBuilder;
278282
use serde::Deserialize;

cot-core/src/response.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub use into_response::{
6767
IntoResponse, WithBody, WithContentType, WithExtension, WithHeader, WithStatus,
6868
};
6969

70+
7071
use crate::{Body, StatusCode};
7172

7273
const RESPONSE_BUILD_FAILURE: &str = "Failed to build response";
@@ -146,39 +147,9 @@ impl ResponseExt for Response {
146147

147148
#[cfg(test)]
148149
mod tests {
149-
use cot::headers::JSON_CONTENT_TYPE;
150-
151150
use super::*;
152-
use crate::body::BodyInner;
153151
use crate::response::{Response, ResponseExt};
154152

155-
#[test]
156-
#[cfg(feature = "json")]
157-
fn response_new_json() {
158-
#[derive(serde::Serialize)]
159-
struct MyData {
160-
hello: String,
161-
}
162-
163-
let data = MyData {
164-
hello: String::from("world"),
165-
};
166-
let response = cot::json::Json(data).into_response().unwrap();
167-
assert_eq!(response.status(), StatusCode::OK);
168-
assert_eq!(
169-
response.headers().get(http::header::CONTENT_TYPE).unwrap(),
170-
JSON_CONTENT_TYPE
171-
);
172-
match &response.body().inner {
173-
BodyInner::Fixed(fixed) => {
174-
assert_eq!(fixed, r#"{"hello":"world"}"#);
175-
}
176-
_ => {
177-
panic!("Expected fixed body");
178-
}
179-
}
180-
}
181-
182153
#[test]
183154
fn response_new_redirect() {
184155
let location = "http://example.com";

cot-core/src/router.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ use derive_more::with_trait::Debug;
3131
use tracing::debug;
3232

3333
use crate::error::NotFound;
34-
use crate::handler::{BoxRequestHandler, RequestHandler, into_box_request_handler};
34+
use crate::handler::{into_box_request_handler, BoxRequestHandler, RequestHandler};
3535
use crate::request::{AppName, PathParams, Request, RequestHead, RouteName};
3636
use crate::response::Response;
3737
use crate::router::path::{CaptureResult, PathMatcher, ReverseParamMap};
38-
use crate::{Error, Result, impl_into_cot_error};
38+
use crate::{impl_into_cot_error, Error, Result};
3939

4040
pub mod method;
4141
pub mod path;
@@ -784,10 +784,14 @@ impl Debug for RouteInner {
784784

785785
#[cfg(test)]
786786
mod tests {
787+
use cot::reverse;
788+
use cot::test::TestRequestBuilder;
789+
787790
use super::*;
788-
use crate::StatusCode;
791+
use crate::html::Html;
789792
use crate::request::Request;
790793
use crate::response::{IntoResponse, Response};
794+
use crate::StatusCode;
791795

792796
struct MockHandler;
793797

@@ -798,10 +802,10 @@ mod tests {
798802
}
799803

800804
#[cfg(feature = "openapi")]
801-
impl cot::openapi::AsApiRoute for MockHandler {
805+
impl crate::openapi::AsApiRoute for MockHandler {
802806
fn as_api_route(
803807
&self,
804-
_route_context: &cot::openapi::RouteContext<'_>,
808+
_route_context: &crate::openapi::RouteContext<'_>,
805809
_schema_generator: &mut schemars::SchemaGenerator,
806810
) -> aide::openapi::PathItem {
807811
aide::openapi::PathItem::default()

cot/src/admin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
use std::any::Any;
77
use std::marker::PhantomData;
88

9-
use askama::Template;
10-
use async_trait::async_trait;
11-
use bytes::Bytes;
129
use crate::error::NotFound;
1310
use crate::html::Html;
1411
use crate::request::extractors::{FromRequestHead, Path, StaticFiles, UrlQuery};
1512
use crate::request::{Request, RequestExt, RequestHead};
1613
use crate::response::{IntoResponse, Response};
1714
use crate::reverse_redirect;
1815
use crate::router::{Router, Urls};
16+
use askama::Template;
17+
use async_trait::async_trait;
18+
use bytes::Bytes;
1919
/// Implements the [`AdminModel`] trait for a struct.
2020
///
2121
/// This is a simple method for adding a database model to the admin panel.

cot/src/auth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use std::any::Any;
1313
use std::borrow::Cow;
1414
use std::sync::{Arc, Mutex, MutexGuard};
1515

16+
use crate::error::error_impl::impl_into_cot_error;
17+
use crate::request::{Request, RequestExt};
1618
/// backwards compatible shim for form Password type.
1719
use async_trait::async_trait;
1820
use chrono::{DateTime, FixedOffset};
19-
use crate::error::error_impl::impl_into_cot_error;
20-
use crate::request::{Request, RequestExt};
2121
use derive_more::with_trait::Debug;
2222
#[cfg(test)]
2323
use mockall::automock;

0 commit comments

Comments
 (0)