我是 Android/Retrofit 和 Moshi 的新手。我正在尝试对我的 API 进行 POST 调用,但在序列化方面遇到问题Date。如果您发现任何其他需要纠正的地方,请指出,因为我仍在学习。谢谢
interface ApiInterface {
@Headers("token: ${Config.API_TOKEN}", "Content-Type: application/json")
@POST("/api/signup")
fun signUpNoEmail(@Body userInfo: UserInfo) : Call<SignUpJson>
}
object ApiService {
private val SERVICE : ApiInterface
init {
val retrofit = Retrofit.Builder()
.baseUrl(Config.BASE_URL)
.addConverterFactory(MoshiConverterFactory.create())
.build()
SERVICE = retrofit.create(ApiInterface::class.java)
}
fun signUpNoEmail(userInfo: UserInfo) : Call<SignUpJson> = SERVICE.signUpNoEmail(userInfo)
Run Code Online (Sandbox Code Playgroud)
SignUpJson.kt
@JsonClass(generateAdapter = true)
data class SignUpJson(val vpn_code: String, val expiry_date: Date)
@JsonClass(generateAdapter = true)
data class UserInfo(val username: String)
Run Code Online (Sandbox Code Playgroud)
主要活动:
val userInfo = UserInfo(username = …Run Code Online (Sandbox Code Playgroud) 我有一个名为database.py 的类,其中包含一个名为generate_token() 的函数。我想模拟它并返回一个固定值321。这样我就可以看到该方法被调用并返回了返回值。
我该如何嘲笑呢?这是我尝试过的。
@pytest.mark.asyncio
async def test_successful_register_returns_device_token(monkeypatch):
async def mock_generate_token():
return "321"
m = AsyncMock(mock_generate_token)
m.return_value = "321"
async with AsyncClient(app=app, base_url="http://127.0.0.1") as ac:
monkeypatch.setattr(database, "generate_token", m)
response = await ac.post(
"/register/",
headers={},
json={},
)
assert response.status_code == 201
assert "device_token" in response.json()
assert response.json()["device_token"] == "321"
Run Code Online (Sandbox Code Playgroud) 我试图将 a 放入ConstraintLayouta 内NestedScrollView,但有一条线将ConstraintLayout. 我不能在那条看不见的线下面放置任何东西。我已经尝试了几个小时,但找不到问题所在。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.core.widget.NestedScrollView
android:id="@+id/premium_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BFFFFFFF"
android:focusableInTouchMode="true"
android:tag="layout/fragment_premium"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PremiumFragment">
<ImageView
android:id="@+id/launcher_id"
android:layout_width="185dp"
android:layout_height="185dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="20dp"
android:contentDescription="TODO"
app:layout_constraintBottom_toTopOf="@+id/premium_text_id"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/launch_premium" />
<TextView
android:id="@+id/premium_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="220dp"
android:text="@string/launch_to_premium"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="383dp"
android:layout_height="196dp"
android:layout_marginTop="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/premium_text_id" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</layout>
Run Code Online (Sandbox Code Playgroud) 我正在使用 SqlAlchemy 1.4.18(异步),我相信我遇到了无法解释的竞争条件。底层数据库是Postgres与asyncpg由SQLAlchemy的内部使用。
我在 SQL Alchemy Core 中有以下插入函数。
async def create_device(
device_id: str,
device_type: DeviceType,
account_type: AccountType = AccountType.FREE,
expires_at: Optional[datetime] = None,
account_id: Optional[int] = None,
is_banned: bool = False,
last_login_at: Optional[datetime] = None,
) -> datetime:
if expires_at is None:
expires_at = datetime.utcnow().replace(second=0, microsecond=0) + timedelta(
days=7
)
async with engine.begin() as conn:
await conn.execute(
DeviceTable.insert().values(
id=device_id,
type=device_type,
expires_at=expires_at,
account_type=account_type,
account_id=account_id,
is_banned=is_banned,
last_login_at=last_login_at,
),
)
return expires_at
Run Code Online (Sandbox Code Playgroud)
单元测试自行成功运行。但是,当我在测试类中运行所有测试时,此测试每次都会失败。
@pytest.mark.asyncio
@patch("service.email_service.EmailService.confirm_token")
async def test_confirm_email_already_confirmed(self, mock_token, …Run Code Online (Sandbox Code Playgroud) 我想扩展选项卡控件以具有可关闭的选项卡项.
我找到了Kent的这个WPF解决方案: 在WPF TabControl上 - 我可以在标签标题旁边添加内容吗?
我在Blend中打开了现有silverlight tabcontrol的副本.但是,该结构与WPF tabcontrol看起来完全不同.我无法直接进入Silverlight控件模板.
有谁知道我的好资源?
我相信当你输入一个你喜欢的文本框时,大多数人都会遇到这种情况,根据已输入的内容过滤ViewCollection.
它在WPF中非常直接,只需将UpdateSourceTrigger更改为Text绑定到PropertyChanged即可.
正如您所料,Silverlight没有它.只有默认和显式.
我有想法将交互行为绑定到文本框的TextChanged事件.你会推荐这种方法还是有更好的方法?
silverlight updatesourcetrigger propertychanged silverlight-4.0
我创建了一个新的Silverlight应用程序,它在服务器端的CLientBin下创建了一个XAp文件.
但是,将现有项目复制到同一文件夹并将其添加到解决方案后,不会为此程序集生成XAP文件.
我错过了什么?
非常感谢,
我是Powershell脚本的新手.
我试图从cmd运行powershell脚本
powershell.exe Set-ExecutionPolicy Unrestricted
powershell.exe .\startup.ps1
Run Code Online (Sandbox Code Playgroud)
我需要在PowerShell脚本中使用两行.
%WINDIR%\system32\inetsrv\appcmd.exe add apppool /name:"VCPool" /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"
%WINDIR%\system32\inetsrv\appcmd.exe set app "WebRole_IN_0_VC/" /applicationPool:"VCPool"
Run Code Online (Sandbox Code Playgroud)
我可以在ps1文件中简单地这样写吗?
& %WINDIR%\system32\inetsrv\appcmd.exe add apppool /name:"VCPool" /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"
Run Code Online (Sandbox Code Playgroud)
非常感谢
在ASP.NET MVC中,我可以像这样定义一个textBox编辑器并给它一个样式.
@Html.TextBoxFor(m => m.Notes[i].Notes, new { style = "width: 500px;" });
Run Code Online (Sandbox Code Playgroud)
如何将样式移动到Site.css文件,并从上面的代码中引用它?
.myStyle {
width: 500px;
}
Run Code Online (Sandbox Code Playgroud)
我试过这个编译但似乎不起作用:
@Html.TextBoxFor(m => m.Notes[i].Notes, "myStyle");
Run Code Online (Sandbox Code Playgroud) 我最近改用git.
在我之前和第一次使用git之后的提交中,我注意到它在提交期间也列出了pyc文件.我没有想到任何事情,并提出并推动他们.
现在我意识到他们在开发过程中不断更新,并且非常讨厌在列表中看到它们.它只会产生太多噪音.
我做了一些研究并echo "*.pyc" >> .gitignore在项目目录中做了.
尽管pyc文件仍然显示,但这并没有帮助.可能是因为我之前已经提交了那些pyc文件,我不能再忽略它们了吗?(因为他们现在被跟踪,状态再次发生变化)如果是这样我永远被诅咒,或者仍然希望从存储库中删除事后的文件?
谢谢
silverlight ×3
android ×2
python ×2
asp.net-mvc ×1
asyncpg ×1
css ×1
fastapi ×1
git ×1
kotlin ×1
linux ×1
moshi ×1
postgresql ×1
powershell ×1
pytest ×1
python-3.9 ×1
retrofit ×1
sqlalchemy ×1
xaml ×1
xap ×1