Esempio n. 1
0
    def test_exercise_history(self):
        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            result = client.get("/exercisehistory")
            json_data = self.get_json(result)
            print(json_data)
            self.assertIsNotNone(json_data, "There should be json data here, not a none value")
            self.assertTrue("history" in json_data, "There should be a history key in the json")
Esempio n. 2
0
    def test_exercise_history(self):
        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            result = client.get("/exercisehistory")
            json_data = self.get_json(result)
            print(json_data)
            self.assertIsNotNone(
                json_data, "There should be json data here, not a none value")
            self.assertTrue("history" in json_data,
                            "There should be a history key in the json")
Esempio n. 3
0
    def test_delete_resource(self):
        test_resource_id = 1
        mock = MagicMock(return_value="FINISHED")
        self.fm.delete_resource = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            test_dict = dict(resource_id=test_resource_id)
            data = self.make_json_text(test_dict)
            headers = {"Content-type": "application/json"}
            res = client.post("/deleteresource", headers=headers, data=data)
            mock.assert_called_with(self.test_user_id, test_resource_id)
Esempio n. 4
0
    def test_get_exercises(self):
        import model
        empty_list = []
        mock = MagicMock(return_value=empty_list)
        model.get_all_exercises = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            result = client.get("/exercises")
            json_data = self.get_json(result)
            mock.assert_called_with(self.test_user_id)
            self.assertTrue("exercises" in json_data)
Esempio n. 5
0
    def test_delete_exercise(self):
        test_exercise_id = 1
        test_dict = dict(exercise_id=test_exercise_id)
        mock = MagicMock()
        self.fm.delete_exercise = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            headers = {"Content-type": "application/json"}
            data = self.make_json_text(test_dict)
            client.post("/deleteexercise", headers=headers, data=data)
            mock.assert_called_with(self.test_user_id, test_exercise_id)
Esempio n. 6
0
    def test_user_info(self):

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id
                sess["display_name"] = self.test_display_name

            res = client.get("/userinfo")
            json_data = self.get_json(res)
            print(json_data)
            self.assertIn("displayName", json_data)
            self.assertIn("email", json_data)
            self.assertEqual(self.test_user_id, json_data["email"])
            self.assertEqual(self.test_display_name, json_data["displayName"])
Esempio n. 7
0
    def test_get_exercises(self):
        empty_list = []
        mock = MagicMock(return_value=empty_list)
        self.fm.get_all_exercises = mock
        tag_arg = None

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            result = client.get("/exercises")
            json_data = self.get_json(result)
            mock.assert_called_with(self.test_user_id, tag_arg)
            self.assertTrue("exercises" in json_data)
Esempio n. 8
0
    def test_user_info(self):

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id
                sess["display_name"] = self.test_display_name

            res = client.get("/userinfo")
            json_data = self.get_json(res)
            print(json_data)
            self.assertIn("displayName", json_data)
            self.assertIn("email", json_data)
            self.assertEqual(self.test_user_id, json_data["email"])
            self.assertEqual(self.test_display_name, json_data["displayName"])
Esempio n. 9
0
    def test_delete_resource(self):
        test_resource_id = 1
        mock = MagicMock(return_value="FINISHED")
        import model
        model.delete_resource = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            test_dict = dict(resource_id=test_resource_id)
            data = self.make_json_text(test_dict)
            headers={"Content-type":"application/json"}
            res = client.post("/deleteresource", headers=headers, data=data)
            mock.assert_called_with(self.test_user_id, test_resource_id)
Esempio n. 10
0
    def test_get_resources(self):
        empty_list = []
        mock = MagicMock(return_value=empty_list)
        self.fm.get_resources_for_exercise = mock
        test_exercise_id = "40"

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            resource_url = "/resourcesforexercise/{}".format(test_exercise_id)
            result = client.get(resource_url)
            json_data = self.get_json(result)
            self.assertTrue("resources" in json_data)
            mock.assert_called_with(test_exercise_id, self.test_user_id)
Esempio n. 11
0
    def test_delete_exercise(self):
        import model
        test_exercise_id = 1
        test_dict = dict(exercise_id=test_exercise_id)
        mock = MagicMock()
        model.delete_exercise = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            headers = {"Content-type": "application/json"}
            data = self.make_json_text(test_dict)
            client.post("/deleteexercise", headers=headers, data=data)
            mock.assert_called_with(self.test_user_id, test_exercise_id)
Esempio n. 12
0
    def test_get_resources(self):
        import model
        empty_list = []
        mock = MagicMock(return_value=empty_list)
        model.get_resources_for_exercise = mock
        test_exercise_id = "40"

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            resource_url = "/resourcesforexercise/{}".format(test_exercise_id)
            result = client.get(resource_url)
            json_data = self.get_json(result)
            self.assertTrue("resources" in json_data)
            mock.assert_called_with(test_exercise_id, self.test_user_id)
Esempio n. 13
0
    def test_changebegin_time(self):
        # response = self.app.get('/login')
        # activityId = self.app.
        response = app.test_client().post('/marketing_activity/change_activity_begintime', data={"activityid": "410"})
        name = "testname"
        t = Category(name)
        db.session.add(t)
        db.session.commit()
        # json_dict = json.loads(json_data)
        print("ok")
        print(response)
        self.assertEqual('<Response streamed [302 FOUND]>','{}'.format(response))
        # self.assertEqual(json_dict['errcode'], -1, '状态码返回错误')



        # assert b'<Response streamed [200 OK]>' == '{}'.format(expected)



# params = [
#     (2, 3, 5),
#     (4, 5, 9),
#     (6, 7, 12)
# ]
#



#
# @pytest.fixture(scope="module")
# def test_01_BORROWER_INFO():
#     print("guess it")
#
#
# @pytest.fixture(params=[1, 2, 3])
# def test_data(request):
#     return request.param
#
#
# def test_not_2(test_data):
#     assert test_data != 2
#
#
# @pytest.mark.parametrize('a, b, expected', params)
# def test_01_BORROWER_INFO():
#     print("guess it")
Esempio n. 14
0
    def test_add_exercise(self):
        test_question = "Test Question?"
        test_answer = "Test Answer"
        test_dict = dict(new_question=test_question, new_answer=test_answer)

        mock = MagicMock()
        self.fm.add_exercise = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            headers = {"Content-type": "application/json"}
            data = self.make_json_text(test_dict)
            client.post("/addexercise", headers=headers, data=data)
            mock.assert_called_with(test_question, test_answer,
                                    self.test_user_id)
Esempio n. 15
0
    def test_add_score(self):
        test_exercise_id = 1
        test_score = 1
        test_dict = dict(exercise_id=test_exercise_id, score=test_score)
        mock = MagicMock(return_value=dict(result="success"))
        self.fm.add_attempt = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id
                sess["display_name"] = self.test_display_name

            headers = {"Content-type": "application/json"}
            data = self.make_json_text(test_dict)
            client.post("/addscore", headers=headers, data=data)
            mock.assert_called_with(test_exercise_id, test_score,
                                    self.test_user_id)
Esempio n. 16
0
    def test_change_tags(self):
        mock = MagicMock(return_value=None)
        self.fm.change_tags = mock
        test_tag_list = "python"
        test_exercise_id = 42

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            test_dict = dict(tag_changes=test_tag_list,
                             exercise_id=test_exercise_id)
            json_data = self.make_json_text(test_dict)
            headers = {"Content-type": "application/json"}
            res = client.post("/changetags", headers=headers, data=json_data)
            mock.assert_called_with(test_tag_list, self.test_user_id,
                                    test_exercise_id)
Esempio n. 17
0
    def test_add_score(self):
        import model
        test_exercise_id = 1
        test_score = 1
        test_dict = dict(exercise_id=test_exercise_id, score=test_score)
        mock = MagicMock(return_value=dict(result="success"))
        model.add_attempt = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id
                sess["display_name"] = self.test_display_name

            headers = {"Content-type": "application/json"}
            data = self.make_json_text(test_dict)
            client.post("/addscore", headers=headers, data=data)
            mock.assert_called_with(test_exercise_id, test_score)
Esempio n. 18
0
    def test_add_exercise(self):
        import model
        test_question = "Test Question?"
        test_answer = "Test Answer"
        test_dict = dict(new_question=test_question, new_answer=test_answer)

        mock = MagicMock()
        model.add_exercise = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            headers = {"Content-type": "application/json"}
            data = self.make_json_text(test_dict)
            client.post("/addexercise", headers=headers, data=data)
            mock.assert_called_with(test_question, test_answer, self.test_user_id)
Esempio n. 19
0
    def test_add_resource(self):
        test_caption = "Simeon Franklin Guide to Python Decorators (12 steps)"
        test_url = "http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/"
        test_exercise_id = 11
        mock = MagicMock()
        import model
        model.add_resource = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            headers = {"Content-type": "application/json"}
            args_dict = dict(new_caption=test_caption, new_url=test_url, exercise_id=test_exercise_id)
            data = self.make_json_text(args_dict)
            client.post("/addresource", headers=headers, data=data)
            mock.assert_called_with(test_caption, test_url, self.test_user_id, test_exercise_id)
Esempio n. 20
0
    def test_add_resource(self):
        test_caption = "Simeon Franklin Guide to Python Decorators (12 steps)"
        test_url = "http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/"
        test_exercise_id = 11
        mock = MagicMock()
        self.fm.add_resource = mock

        with app.test_client() as client:
            with client.session_transaction() as sess:
                sess["email"] = self.test_user_id

            headers = {"Content-type": "application/json"}
            args_dict = dict(new_caption=test_caption,
                             new_url=test_url,
                             exercise_id=test_exercise_id)
            data = self.make_json_text(args_dict)
            client.post("/addresource", headers=headers, data=data)
            mock.assert_called_with(test_caption, test_url, self.test_user_id,
                                    test_exercise_id)
Esempio n. 21
0
 def setUp(self):
     print 'whole sentiment detection test set up'
     self.app = app.test_client()
Esempio n. 22
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()        
Esempio n. 23
0
# -*- coding: utf-8 -*-
import time
import json
from view import app

app = app.test_client()

def timeit(method):
    def timed(*args, **kw):
        ts = time.time()
        result = method(*args, **kw)
        te = time.time()
        print '%r args: %s %2.2f sec' % (method.__name__, args, te - ts)
        return result
    return timed


def date2ts(datestr):
    return int(time.mktime(time.strptime(datestr, '%Y-%m-%d  %H:%M:%S')))

@timeit
def emotion_data_simulation_test(timestamp, query_str=None):
    if query_str:
        rv = app.get('/moodlens/data/global/?query=' + query_str + '&ts=' + str(timestamp))
    else:
        rv = app.get('/moodlens/data/global/?ts=' + str(timestamp))
    rv_data = json.loads(rv.data)
    print rv_data['happy'][1], rv_data['angry'][1], rv_data['sad'][1]
    return rv_data['happy'][1] + rv_data['angry'][1] + rv_data['sad'][1]

@timeit
Esempio n. 24
0
 def test_welcome_page(self):
     with app.test_client() as client:
         res = client.get("/")
         self.assertTrue("302" in res.status)
Esempio n. 25
0
 def test_welcome_page(self):
     with app.test_client() as client:
         res = client.get("/")
         self.assertTrue("302" in res.status)
Esempio n. 26
0
 def setUp(self):
     print 'Profile Module test set up'
     self.app = app.test_client()
Esempio n. 27
0
 def setup_class(self):
     """测试开始时候执行, 用来做准备工作,一般用来初始化资源。"""
     app.config['TESTING'] = True  # 这将会使得处理请求时的错误捕捉失效,以便于在进行对应用发出请求的测试时获得更好的错误反馈。
     # 测试客户端将会给我们一个通向应用的简单接口,我们可以激发 对向应用发送请求的测试,并且此客户端也会帮我们记录 Cookie 的 动态。
     self.app = app.test_client()
     self.db = db