예제 #1
0
파일: tests.py 프로젝트: aFku/task_ox
    def test_if_user_created_correctly_from_json(self):
        user = main.User(single_user[0], {})

        with supp_stderr():
            check = main.User({}, {})   # need to suppress stderr, because empty object has not id attribute

        check_attr = (("id", 1), ("name", "Leanne Graham"), ("username", "Bret"), ("email", "*****@*****.**"),
                      ("address", {"street": "Kulas Light", "suite": "Apt. 556", "city": "Gwenborough",
                                   "zipcode": "92998-3874", "geo": {"lat": "-37.3159", "lng": "81.1496"}}))
        for key, value in check_attr:
            check.__setattr__(key, value)
        self.assertEqual(user, check)
예제 #2
0
 def test_check_points(self):
     pavel = main.User('1')
     response = self.api.users.get(user_ids=1, fields='city, home_town, sex, bdate, books, '
                                                         'interests, movies, music, personal')
     pavel2 = pavel.get_info(response[0])
     result = main.check_points(pavel, pavel2)
     self.assertTrue(result > 0)
예제 #3
0
파일: bot.py 프로젝트: kuksag/cfdata
def begin_work(message):
    handle = message.text
    user = main.User(handle)

    if user.profile is None:
        bot.send_message(chat_id=message.chat.id,
                         text='Хэндл "{}" не найден'.format(handle))
        return
    if not user.build():
        print("Что-то не так")
        return

    bot.send_photo(chat_id=message.chat.id,
                   photo=main.draw_pie(
                       user.languages,
                       figure_name="Статистика по языкам программирования",
                       legend_name="Языки программирования"),
                   caption=main.build_str(main.sort_dict(user.languages)))
    bot.send_photo(chat_id=message.chat.id,
                   photo=main.draw_pie(user.tags,
                                       figure_name="Статистика по задачам",
                                       legend_name="Тэги"),
                   caption=main.build_str(main.sort_dict(user.tags)))
    bot.send_photo(chat_id=message.chat.id,
                   photo=main.draw_pie(user.verdicts,
                                       figure_name="Статистика по вердиктам",
                                       legend_name="Вердикты"),
                   caption=main.build_str(main.sort_dict(user.verdicts)))
    bot.send_message(
        chat_id=message.chat.id,
        text="Всего решалось задач: {}\nВсего решено правильно: {}".format(
            len(user.attempted), len(user.solved)))
예제 #4
0
    def OnPrivateMessage(self, user, message):
        #print user.nickname + "!" + user.ident + "@" + user.hostname + ": " + message
        owner = is_owner(user)
        if owner and message.lower() == 'turn off':
            self._bot.go_to_state('Off')
            return
        elif owner and message.lower() == 'what state':
            self._bot.send_message(user.nickname, self._bot.state.name)
            return
        elif owner and message.lower() == 'what players':
            for player in players.iterkeys():
                tempuser = players[player]
                self._bot.send_message(
                    user.nickname, player + ': ' + tempuser.nickname + "!" +
                    tempuser.ident + "@" + tempuser.hostname)
        elif owner and message.lower() == 'demoderate':
            self._bot.unmoderate_channel(gamechannel)

        messagetokens = message.split()
        if messagetokens[0].lower() == 'replace' and len(
                messagetokens[0]) == 3:
            if not nickname_in_game(messagetokens[1].lower()):
                return
            olduser = players[messagetokens[1].lower()]
            newuser = main.User(messagetokens[2], "", "")
            replace_user(olduser, newuser, self._bot)
            return
예제 #5
0
def test_leave_board():
    board = main.MessageBoard()
    board = main.MessageBoard(status="public")
    user = main.User('Me', main.WhatsAppObserver)
    board.add_subscriber(user)
    assert (user in board.event_manager.users)
    board.remove_subscriber(user)
    assert (user not in board.event_manager.users)
예제 #6
0
파일: testing.py 프로젝트: j-chad/prodigy
 def test_register_form_username_taken_same_school(self):
     main.db.session.add(main.User('myusername', 'greatpassword', main.School.query.get(1)))
     main.db.session.commit()
     form = main.RegisterForm(username="******",
                              password="******",
                              confirm_password="******",
                              school=main.School.query.get(1))
     self.assertFalse(form.validate())
예제 #7
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_get_card_success(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add_all((
            state_obj,
            user_obj,
            main.Card(user_obj, 'q1', 'a1'),
            main.Card(user_obj, 'q2', 'a2'),
        ))
        card_obj_1 = main.Card(user_obj, 'q3', 'a3')
        card_obj_2 = main.Card(user_obj, 'q4', 'a4')
        main.db.session.add_all((
            card_obj_1,
            card_obj_2,
            main.Card(user_obj, 'q5', 'a5')
        ))
        state_obj.user = user_obj
        state_obj._State__current_card_seed = 608731  # [3, 4, 5, 2, 1]
        main.db.session.commit()
        print(card_obj_1.id, card_obj_2.id)

        with self.subTest('get first card'):
            with self.client as c:
                c.set_cookie('localhost', 'game-state', state_obj.id)
                response = c.get(flask.url_for('get_card_api', n=1))
                self.assert200(response)
                self.assertEqual(response.json['id'], card_obj_1.id)

        with self.subTest('get current card'):
            with self.client as c:
                c.set_cookie('localhost', 'game-state', state_obj.id)
                response = c.get(flask.url_for('get_card_api', n=0))
                self.assert200(response)
                self.assertEqual(response.json['id'], card_obj_1.id)

        with self.subTest('get next card'):
            with self.client as c:
                c.set_cookie('localhost', 'game-state', state_obj.id)
                response = c.get(flask.url_for('get_card_api', n=1))
                self.assert200(response)
                self.assertEqual(response.json['id'], card_obj_2.id)

        with self.subTest('get current card (next)'):
            with self.client as c:
                c.set_cookie('localhost', 'game-state', state_obj.id)
                response = c.get(flask.url_for('get_card_api', n=0))
                self.assert200(response)
                self.assertEqual(response.json['id'], card_obj_2.id)

        with self.subTest('overflow iterator'):
            state_obj._State__current_card_iter = 5
            main.db.session.commit()
            with self.client as c:
                c.set_cookie('localhost', 'game-state', state_obj.id)
                response = c.get(flask.url_for('get_card_api', n=1))
                self.assert200(response)
                self.assertIn(response.json['id'], [i.id for i in main.Card.query.all()])
예제 #8
0
 def setUp(self):
     main.app.config[
         'SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/tmp.sqlite'
     main.app.config['TESTING'] = True
     self.app = main.app.test_client()
     main.db = main.SQLAlchemy(main.app)
     user = main.User('test')
     main.db.init_app(main.app)
     main.db.create_all()
     main.db.session.commit()
예제 #9
0
def test_request_advance(name, payscale, requested_advance_amount,
                         expected_output):

    User_test = main.User(name, payscale)
    flag = User_test.request_advance(requested_advance_amount)
    if not (isinstance(expected_output, bool)):
        print(
            "\n\n\t\t\tFault in test case. Enter a valid expected output\n\n")
    else:
        assert flag == expected_output
예제 #10
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_answer_no_cards(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add_all((state_obj, user_obj))
        state_obj.user = user_obj
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.post(flask.url_for('answer_card_api'), data={'a': "a1"})
            self.assert400(response)
예제 #11
0
파일: testing.py 프로젝트: j-chad/prodigy
 def test_login_form_success(self):
     main.db.session.add(main.User(username="******",
                                   password="******",
                                   school=main.School.query.get(1)))
     form = main.LoginForm(username="******",
                           password="******",
                           school=main.School.query.get(1))
     with self.subTest("validates"):
         self.assertTrue(form.validate())
     with self.subTest("returns user"):
         self.assertIsInstance(form.user, main.User)
예제 #12
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_index_logged_in_redirect(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        state_obj.user = user_obj
        main.db.session.add_all((state_obj, user_obj))
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.get(flask.url_for('index'))
        self.assertRedirects(response, flask.url_for('cards'))
예제 #13
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_play_empty(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add_all((state_obj, user_obj))
        state_obj.user = user_obj
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.get(flask.url_for('play'))
        self.assert400(response)
예제 #14
0
파일: testing.py 프로젝트: j-chad/prodigy
 def test_login_form_fail_school(self):
     main.db.session.add(main.User(username="******",
                                   password="******",
                                   school=main.School.query.get(1)))
     form = main.LoginForm(username="******",
                           password="******",
                           school=main.School.query.get(2))
     with self.subTest("doesn't validates"):
         self.assertFalse(form.validate())
     with self.subTest("doesn't apply user"):
         self.assertIsNone(form.user)
예제 #15
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_remove_card_get_fail(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        card_obj = main.Card(user_obj, 'q1', 'a1')
        main.db.session.add_all((state_obj, user_obj, card_obj))
        state_obj.user = user_obj
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.get(flask.url_for('remove_card_api'), data={'id': card_obj.id})
        self.assert405(response)
        self.assertEqual(main.Card.query.filter_by(user=user_obj).count(), 1)
예제 #16
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_answer_missing_arg(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        card_obj = main.Card(user_obj, 'q1', 'a1')
        main.db.session.add_all((state_obj, user_obj, card_obj))
        state_obj.user = user_obj
        state_obj._State__current_card_iter = 0
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.post(flask.url_for('answer_card_api'))
            self.assert400(response)
예제 #17
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_add_card_get_fail(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add_all((state_obj, user_obj))
        state_obj.user = user_obj
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.get(flask.url_for('add_card_api'), data={
                "q": "q1",
                "a": "a1"
            })
        self.assertEqual(response.status_code, 405)
예제 #18
0
파일: register.py 프로젝트: addNaNs/NegyTV
def create_account(username, name, surname, password, repeat_password,
                   tk_root):
    if password.get() != repeat_password.get():
        print("Not matching passwords")
        return
    all_users = pickle.load(open('./users.obj', 'rb'))
    for i, user in enumerate(all_users):
        if user.username == username.get():
            print("Username is taken")
            return
    all_users.append(
        main.User(username.get(), name.get(), surname.get(), password.get()))
    pickle.dump(all_users, open('./users.obj', 'wb'))
    print("Account created successfully")
    tk_root.quit()
예제 #19
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_answer_card_success(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        card_obj = main.Card(user_obj, 'q1', 'a1')
        main.db.session.add_all((state_obj, user_obj, card_obj))
        state_obj.user = user_obj
        state_obj._State__current_card_iter = 0
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.post(flask.url_for('answer_card_api'), data={'a': 'a1'})
            self.assert200(response)
            self.assertTrue(response.json['correct'])
            self.assertIn('score', response.json)
예제 #20
0
def home():
    # Activity form
    user = main.User()
    decision = main.Decision()
    test_dict = {}
    user_question_list = utils.json_loader('user_questions.json')
    decision_question_list = utils.json_loader('decision_questions.json')

    for idx in range(len(user_question_list)):
        id_ = user_question_list[idx]['id']
        # creates list of questions to populate the page with
        test_dict[f'question_{id_}'] = user_question_list[idx]

    for idx in range(len(decision_question_list)):
        id_ = decision_question_list[idx]['id']
        # creates list of questions to populate the page with
        test_dict[f'question_{id_}'] = decision_question_list[idx]

    # When submit is clicked
    if request.method == "POST":

        # loop through questions and store respective answers
        for idx in range(len(user_question_list)):
            id_ = user_question_list[idx]['id']
            try:
                user_question_list[idx]['response'] = request.form[
                    f'response_{id_}']
            except:
                raise ValueError

        for idx in range(len(decision_question_list)):
            id_ = decision_question_list[idx]['id']
            try:
                decision_question_list[idx]['response'] = request.form[
                    f'response_{id_}']
            except:
                pass

        user.parse_responses(user_question_list)
        user.calculate_risk()
        decision.parse_responses(decision_question_list)
        decision.evaluate_responses()

    # Inputted values will be outputted to the screen when submit button is clicked [test]
    return render_template("home.html",
                           content=test_dict,
                           risk_score=user.risk,
                           feedback=decision.response_list)
예제 #21
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_get_card_no_cards_fail(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add_all((state_obj, user_obj))
        state_obj.user = user_obj
        main.db.session.commit()

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.get(flask.url_for('get_card_api') + '?n=1')
            self.assertEqual(response.status_code, 204)

        with self.client as c:
            c.set_cookie('localhost', 'game-state', state_obj.id)
            response = c.get(flask.url_for('get_card_api') + '?n=0')
            self.assertEqual(response.status_code, 204)
예제 #22
0
파일: testing.py 프로젝트: j-chad/prodigy
 def test_login_success(self):
     main.db.session.add(main.User(username="******",
                                   password="******",
                                   school=main.School.query.get(1)))
     main.db.session.commit()
     response = self.client.post(flask.url_for('login'), data={
         'username': "******",
         'password': "******",
         'school'  : '1'
     })
     with self.subTest("redirects"):
         self.assertRedirects(response, flask.url_for('cards'))
     with self.subTest("changes state"):
         state = self.client.cookie_jar._cookies['localhost.local']['/']['game-state'].value
         state_obj = main.State.query.get(state)
         self.assertIsNotNone(state_obj)
         self.assertIsNotNone(state_obj.user)
예제 #23
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_state_card(self):
        state_obj = main.State()
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add_all((state_obj, user_obj))

        state_obj.user = user_obj
        state_obj._State__current_card_seed = 259720  # [2, 3, 4, 1]
        main.db.session.add(main.Card(state_obj.user, "card 1", "1"))
        card_2 = main.Card(state_obj.user, "card 2", "2")
        main.db.session.add(card_2)
        main.db.session.add(main.Card(state_obj.user, "card 3", "3"))
        main.db.session.add(main.Card(state_obj.user, "card 4", "4"))

        main.db.session.commit()

        self.assertIs(state_obj.next_card(), card_2)
        self.assertIsNotNone(state_obj._State__current_card_iter)
        self.assertIs(state_obj.card, card_2)
예제 #24
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_require_login_success(self):
        state_obj = main.State()
        main.db.session.add(state_obj)

        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add(user_obj)

        state_obj.user = user_obj
        main.db.session.commit()

        @main.state_handler
        @main.require_login
        def func(state):
            with self.subTest("test_state_passed"):
                self.assertIs(state, state_obj)
            self.assertIsNotNone(state.user)
            return '', 200

        with self.app.test_request_context(headers=Headers([('Cookie', 'game-state={};'.format(state_obj.id))])):
            response = func()
            with self.subTest('test_state_passed_through'):
                self.assertIn("game-state={}".format(state_obj.id), response.headers['set-cookie'])
            self.assert200(response)
예제 #25
0
파일: tests.py 프로젝트: aFku/task_ox
def create_user_list(user_source, post_source):
    relation = main.make_relation(create_post_list(post_source))
    return [main.User(user, relation) for user in user_source]
예제 #26
0
def test_join_private_board():
    board = main.MessageBoard()
    board = main.MessageBoard(status="private", password="******")
    user = main.User('Me', main.WhatsAppObserver)
    board.add_subscriber(user, 'test')
    assert (user in board.event_manager.users)
예제 #27
0
def test_fail_join_private_board():
    board = main.MessageBoard()
    board = main.MessageBoard(status="private", password="******")
    user = main.User('Me', main.WhatsAppObserver)
    assert (board.add_subscriber(user, "test") == "Wrong Password")
예제 #28
0
def test_update():
    user = main.User('Me', main.WhatsAppObserver)
    assert (user.observer == main.WhatsAppObserver)
    user.update(main.EmailObserver)
    assert (user.observer == main.EmailObserver)
예제 #29
0
def test_message_received():
    board = main.MessageBoard()
    board = main.MessageBoard(status="public")
    user = main.User('Me', main.WhatsAppObserver)
    board.add_subscriber(user)
    board.add_message("Hello World")
예제 #30
0
파일: testing.py 프로젝트: j-chad/prodigy
    def test_user_check_password_false(self):
        user_obj = main.User("myusername", "mypassword", main.School.query.get(1))
        main.db.session.add(user_obj)
        main.db.session.commit()

        self.assertFalse(user_obj.check_password("notmypassword"))