我需要测试功能的哪些方面?

时间:2019-01-04 12:39:40

标签: python unit-testing testing

我具有以下build_settings_message函数,我有点困惑应该如何为其编写单元测试。我需要检查哪些方面?

def build_settings_message(team_id):
    team = SlackTeam.objects.find_by_id(team_id)
    domain = Site.objects.get_current().domain

    attachments = [
        _build_manage_admins(),
        _build_checks_available(team, domain)
    ]

    return {
        'text': "Here is my settings page",
        'attachments': attachments
    }


def _build_manage_admins():
    return {
        "fallback": "Manage admins",
        "color": "#85cdff",
        "callback_id": "admins_controls",
        "title": "Admins",
        "footer": "Users that could remove and edit any checks ",
        "actions": [
            {
                "name": "manage",
                "text": ":key: Manage Admins",
                "type": "button",
                "value": "manage"
            }
        ]
    }


def _build_checks_available(team, domain):
    return {
        "title": "Items available",
        "footer": ("You have got *{} of {}* items for "
                   "check *available*.").format(
                       team.checks_used, team.checks_available),
        "actions": [
            {
                "text": "Open Dashboard",
                "type": "button",
                "url": 'https://' + domain + reverse('dashboard')
            }
        ]
    }

1 个答案:

答案 0 :(得分:1)

您必须mock SlackTeamSite并返回teamdomain的一些虚假但真实的值,然后验证该值build_settings_message返回的是正确的(基于teamdomain)。

请务必检查边缘情况,例如没有团队,重复的域等。