示例#1
0
def render_hunt(request, given_id):
    """
        :param: HttpRequest, interger id
        :rtype: HttpResponse
        This function gets triggered with the appropriate hunt id once a user chooses
        hunt from the categories page. It sets the hunt's data (title and starting location),
        and stores the items data in global var TEMP list.
        Finally, it renders the hunt's welcome page.
    """
    global TEMP
    global glob_hunt_id
    glob_hunt_id = given_id
    hunt_dict = set_HuntsData(given_id)
    TEMP = set_ItemsData(given_id)
    hunt_title = hunt_dict["hunt title"]
    hunt_start = hunt_dict["hunt start"]
    uname = request.user.username
    init_huntprog(given_id, uname)
    return render_to_response("hunts/hunt.html", {"title": hunt_title, "start_pt": hunt_start, "user": request.user})
示例#2
0
 def test_init_huntprog(self):
     """
         **test_init_huntprog** tests if huntprog already exists if so check that nothing is done, else check that a create function is called
     """
     with patch("hunts.models.Hunts.objects.filter") as filt:
         with patch("hunts.models.HuntProg.objects.filter") as filt1:
             with patch("hunts.models.HuntProg.objects.create") as cr:
                 filt.return_value = ["a list"]
                 filt1.return_value = MagicMock()
                 attrs = {"count.return_value": 0}
                 filt1.return_value.configure_mock(**attrs)
                 attrs = {"save.return_value": None}
                 cr.configure_mock(**attrs)
                 h_id = "test"
                 uname = "testu"
                 models.init_huntprog(h_id, uname)
                 assert cr.called
                 cr.reset_mock()
                 attrs = {"count.return_value": 1}
                 filt1.return_value.configure_mock(**attrs)
                 models.init_huntprog(h_id, uname)
                 assert not (cr.called)