Django:测试成功加载静态文件
Is it possible to test successful loading of static page components in Django automatic test?
是否可以在Django自动测试中测试成功加载静态页面组件?
For example, using django test client, besides testing the client.get('x').status_code
to be 200, I want to test if all page's static resources (linked css and js files) are successfully loaded.
例如,使用django测试客户端,除了测试client.get('x')。status_code为200之外,我想测试是否所有页面的静态资源(链接的css和js文件)都已成功加载。
If its not possible using client
, Is there a plugin or suplementary test system, e.g. Selenium, to enable such type of tests?
如果不能使用客户端,是否有插件或补充测试系统,例如硒,能够进行这类测试吗?
2 个解决方案
#1
3
I guess you want to find out if django's staticfile finder is able to find your static resources.
我想你想知道django的静态文件查找器能否找到你的静态资源。
Consider your app name is my_app
. You have a folder called static
inside it. You again have a folder called my_app
inside it which contains your static resource, let's say some image named 'test.jpg'.
考虑您的应用名称是my_app。你有一个名为static的文件夹。你再次在其中有一个名为my_app的文件夹,其中包含你的静态资源,比方说一些名为'test.jpg'的图像。
myapp
|-- __init__.py
`-- models.py
`-- static
`-- myapp
`-- test.jpg
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
class TestStaticFiles(TestCase):
"""Check if app contains required static files"""
def test_images(self):
abs_path = finders.find('myapp/test.jpg')
self.assertTrue(staticfiles_storage.exists(abs_path))
finders
looks inside static/
subdirectory of all apps to find the static resource.
finders查看所有应用程序的static /子目录内部以查找静态资源。
更多相关文章
- Python进阶----类的结构(公有成员 , 私有成员(私有属性,私有方法
- Appium基于Python APP自动化测试框架
- 初学者的Selenium自动化测试指南,基于Python(五)——常用键盘事件
- 基于Python的XSS测试工具XSStrike使用方法
- [caffe(二)]Python加载训练caffe模型并进行测试2
- LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---IBM 的 lin
- Kali Linux渗透测试 131 拒绝服务--NTP 放大攻击
- 如何静态构建qt5
- Linux-自己创建动态库静态库