def test_reorder(self): with current_app.test_request_context(): reorder_question_list([ex.nq2["_id"], ex.nq1["_id"]]) self.assertEqual(ex.nq2["_id"], get_question_by_idx(0)["_id"]) self.assertEqual(ex.nq1["_id"], get_question_by_idx(1)["_id"]) with current_app.test_request_context(): self.assertEqual(ex.nq2["_id"], get_question_by_idx(0)["_id"]) self.assertEqual(ex.nq1["_id"], get_question_by_idx(1)["_id"])
def test_reorder_endpoint(self, client): res = client.post('/questions/reorder', data=json.dumps({ "new_list": [str(ex.nq2["_id"]), str(ex.nq1["_id"])] }), content_type='application/json') self.assertEqual(200, res.status_code) self.assertEqual(ex.nq2["_id"], get_question_by_idx(0)["_id"]) self.assertEqual(ex.nq1["_id"], get_question_by_idx(1)["_id"])
def test_enable_question_endpoint(self, client): new_id = get_db().questions.insert_one({"stuff": True}).inserted_id res = client.post('/questions/enable', data={ "qid": str(new_id), "idx": 0 }) self.assertEqual(200, res.status_code) self.assertEqual(new_id, get_question_by_idx(0)["_id"])
file_path = os.path.join(application.root_path, "templates", pth) values["q"] = int(os.stat(file_path).st_mtime) return url_for(endpoint, **values) # Adds a "file_url_for" global in the templates # allows them to get the url for a templated html page def file_url_for(name, **kwargs): return dated_url_for("page", path=name, **kwargs) application.add_template_global(file_url_for, "file_url_for") # This allows the jinja templates to get todays question directly. application.add_template_global((lambda: pli.get_question_by_idx(0)), "get_todays_question") application.add_template_global( (lambda: pli.get_question_by_idx(0)["choices"]), "get_todays_choices") application.add_template_global(current_user, "current_user") application.add_template_global(pli.get_login_form, "get_login_form") application.add_template_global(pli.PliUser.get, "get_user_by_uid") # This allows the jinja templates to get todays whats new cards application.add_template_global(pli.WhatsNewCard.get_frontpage_cards, "get_wn_cards") # This allows the jinja templates to get the list of all whats new cards application.add_template_global(pli.WhatsNewCard.list_wn_cards, "list_all_wn_cards")
def test_disable3(self): self.assertFalse(disable_question_in_list(ObjectId())) self.assertEqual(ex.nq1["_id"], get_question_by_idx(0)["_id"]) self.assertEqual(ex.nq2["_id"], get_question_by_idx(1)["_id"])
def test_disable2(self): insert_question({}) self.assertTrue(disable_question_in_list(ex.nq2["_id"])) self.assertEqual(ex.nq1["_id"], get_question_by_idx(0)["_id"]) self.assertTrue("question" not in get_question_by_idx(1))
def assertIdKey(self, idx, expect): self.assertEqual(expect, get_question_by_idx(idx)["_id"])
def assertNumKey(self, idx, expect): self.assertEqual(expect, get_question_by_idx(idx)["num"])
def test_insert_random(self): insert_question({"new": True}, idx=1) self.assertTrue(get_question_by_idx(1)["new"])
def test_hd_right_ele(self): self.assertEquals(ex.nq1["_id"], get_question_by_idx(0)["_id"])