首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnitTesting肖丹数据

UnitTesting肖丹数据
EN

Stack Overflow用户
提问于 2017-03-06 20:52:46
回答 1查看 89关注 0票数 0

我想测试一下Shodan的数据。数据包括时间戳、爬虫ID、服务器操作系统等字段。这些内容在每次请求时都会发生变化。哇,我应该测试它们吗?

Shodan JSON数据:

代码语言:javascript
复制
{
    "city": "Mountain View",
    "region_code": "CA",
    "os": null,
    "tags": [],
    "ip": 134744072,
    "isp": "Google",
    "area_code": 650,
    "dma_code": 807,
    "last_update": "2017-03-04T13:54:57.176297",
    "country_code3": "USA",
    "country_name": "United States",
    "hostnames": [
        "google-public-dns-a.google.com"
    ],
    "postal_code": "94035",
    "longitude": -122.0838,
    "country_code": "US",
    "ip_str": "8.8.8.8",
    "latitude": 37.385999999999996,
    "org": "Google",
    "data": [
        {
            "_shodan": {
                "options": {},
                "id": null,
                "module": "dns-udp",
                "crawler": "122dd688b363c3b45b0e7582622da1e725444808"
            },
            "hash": -553166942,
            "os": null,
            "opts": {},
            "ip": 134744072,
            "isp": "Google",
            "port": 53,
            "hostnames": [
                "google-public-dns-a.google.com"
            ],
            "location": {
                "city": "Mountain View",
                "region_code": "CA",
                "area_code": 650,
                "longitude": -122.0838,
                "country_code3": "USA",
                "country_name": "United States",
                "postal_code": "94035",
                "dma_code": 807,
                "country_code": "US",
                "latitude": 37.385999999999996
            },
            "timestamp": "2017-03-04T13:54:57.176297",
            "domains": [
                "google.com"
            ],
            "org": "Google",
            "data": "\nRecursion: enabled",
            "asn": "AS15169",
            "transport": "udp",
            "ip_str": "8.8.8.8"
        }
    ],
    "asn": "AS15169",
    "ports": [
        53
    ]
}

我的测试文件:

代码语言:javascript
复制
def test_shodan_api():
    assert shodan_data == ???
EN

回答 1

Stack Overflow用户

发布于 2017-03-06 21:03:06

我假设您希望将实际收到的数据与录制的数据进行比较,并发现每次调用中的某些部分(时间戳)不同,因此您的完整数据永远不会与录制的数据完全匹配。

我建议从录制的数据和接收的数据中删除时间戳,并比较其余的数据:

代码语言:javascript
复制
del received_data['last_update']
del canned_data['last_update']  # you probably want to do this prior to canning the data ;-)

assert_equal(received_data, canned_data)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42626154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档