Beispiel #1
0
def test_display_stats_action_message(tp0):
    action = dict(profile_url="/profile/url",
                  unit_source="Some unit source",
                  unit_url="/unit/url",
                  displayname="Some user",
                  check_name="some-check",
                  checks_url="/checks/url",
                  check_display_name="Some check")
    stats = StatsDisplay(tp0)

    for i in [2, 3, 4, 6, 7, 8, 9]:
        _action = action.copy()
        _action["type"] = i
        message = stats.get_action_message(_action)
        assert (("<a href='%s' class='user-name'>%s</a>" %
                 (action["profile_url"], action["displayname"])) in message)
        if i != 4:
            assert (("<a href='%s'>%s</a>" %
                     (action["unit_url"], action["unit_source"])) in message)
        if i in [6, 7]:
            assert (("<a href='%s'>%s</a>" %
                     (action["checks_url"], action["check_display_name"]))
                    in message)

    for i in [1, 5]:
        for _i in [0, 1, 2, 3, 4, 5]:
            _action = action.copy()
            _action["type"] = i
            _action["translation_action_type"] = _i
            message = stats.get_action_message(_action)
            assert (("<a href='%s' class='user-name'>%s</a>" %
                     (action["profile_url"], action["displayname"]))
                    in message)
            assert (("<a href='%s'>%s</a>" %
                     (action["unit_url"], action["unit_source"])) in message)
Beispiel #2
0
 def stats(self):
     vf_stats = ({} if not self.vfolders_data_view else StatsDisplay(
         self.object.tp, stats=self.vfolders_data_view.stats).stats)
     stats = (dict(vfolders=vf_stats["children"]) if vf_stats else {})
     stats_ob = (self.object.tp
                 if self.object.tp_path == "/" else self.object)
     _stats = stats_ob.data_tool.get_stats(user=self.request.user)
     stats.update(StatsDisplay(stats_ob, stats=_stats).stats)
     return stats
Beispiel #3
0
def _test_stats_display(obj):
    stats = StatsDisplay(obj)
    assert stats.context == obj
    stat_data = obj.data_tool.get_stats()
    assert stats.stat_data == stat_data.copy()
    stats.add_children_info(stat_data)
    if stat_data.get("last_submission"):
        stat_data["last_submission"]["msg"] = (
            stats.get_action_message(
                stat_data["last_submission"]))
    StatsDisplay(obj).localize_stats(stat_data)
    assert stat_data == stats.stats
Beispiel #4
0
def _test_stats_display(obj):
    stats = StatsDisplay(obj)
    assert stats.context == obj
    stat_data = obj.data_tool.get_stats()
    assert stats.stat_data == stat_data.copy()
    stats.add_lastaction_info(stat_data)
    stats.add_lastupdated_info(stat_data)
    stats.add_children_info(stat_data)
    assert stat_data == stats.stats
Beispiel #5
0
def test_display_stats_action_message(tp0):
    action = dict(
        profile_url="/profile/url",
        unit_source="Some unit source",
        unit_url="/unit/url",
        displayname="Some user",
        check_name="some-check",
        checks_url="/checks/url",
        check_display_name="Some check")
    stats = StatsDisplay(tp0)

    for i in [2, 3, 4, 6, 7, 8, 9]:
        _action = action.copy()
        _action["type"] = i
        message = stats.get_action_message(_action)
        assert (
            ("<a href='%s' class='user-name'>%s</a>"
             % (action["profile_url"], action["displayname"]))
            in message)
        if i != 4:
            assert (
                ("<a href='%s'>%s</a>"
                 % (action["unit_url"], action["unit_source"]))
                in message)
        if i in [6, 7]:
            assert (
                ("<a href='%s'>%s</a>"
                 % (action["checks_url"], action["check_display_name"]))
                in message)

    for i in [1, 5]:
        for _i in [0, 1, 2, 3, 4, 5]:
            _action = action.copy()
            _action["type"] = i
            _action["translation_action_type"] = _i
            message = stats.get_action_message(_action)
            assert (
                ("<a href='%s' class='user-name'>%s</a>"
                 % (action["profile_url"], action["displayname"]))
                in message)
            assert (
                ("<a href='%s'>%s</a>"
                 % (action["unit_url"], action["unit_source"]))
                in message)
Beispiel #6
0
def _test_stats_display(obj):
    stats = StatsDisplay(obj)
    assert stats.context == obj
    stat_data = obj.data_tool.get_stats()
    assert stats.stat_data == stat_data.copy()
    stats.add_children_info(stat_data)
    if stat_data.get("last_submission"):
        stat_data["last_submission"]["msg"] = (stats.get_action_message(
            stat_data["last_submission"]))
    StatsDisplay(obj).localize_stats(stat_data)
    assert stat_data == stats.stats
Beispiel #7
0
 def stats(self):
     stats_ob = (self.object.tp
                 if self.object.tp_path == "/" else self.object)
     return StatsDisplay(
         stats_ob,
         stats=stats_ob.data_tool.get_stats(user=self.request.user)).stats