示例#1
0
    def set_workshop_step_for_user(user: ci_demo.User, step: int) -> None:
        """
        Saves a given workshop step for the given user and persists it in the database.

        :param user: The user to update the workshop step of.
        :param step: The new step for the user that needs to be persisted.
        :return: Nothing.
        """
        user.workshop_step = step
        ci_demo.db.session.commit()
示例#2
0
    def test_that_login_required_does_not_redirect_when_logged_in(self):
        with mock.patch('flask.g') as m_g:
            from ci_demo import app, User
            m_g.user = User()
            with app.test_request_context('/my_workshop'):
                from ci_demo import login_required

                wrapped_def = mock.MagicMock()
                wrapper = login_required(wrapped_def)

                wrapper()

                wrapped_def.assert_called_once()
示例#3
0
 def test_retrieve_next_hint_returns_the_first_hint(self):
     expected = TextHint(1, "foo")
     hints = WorkshopHints({1: [expected]})
     user = User()
     self.assertEqual(expected, retrieve_next_hint(user, 1, hints))
示例#4
0
 def test_retrieve_next_hint_returns_nothing_if_no_hints_are_left(self):
     hints = WorkshopHints({1: []})
     user = User()
     self.assertEqual(None, retrieve_next_hint(user, 1, hints))
示例#5
0
 def test_get_active_hints_returns_active_hints(self):
     u = User(workshop_step=2)
     u.hints = [UserHints(id=1), UserHints(id=2)]
     non_activated_hint = TextHint(1, "foo")
     activated_hint = TextHint(2, "foo")
     self.assertListEqual([activated_hint], get_active_hints(u, WorkshopHints({1: [non_activated_hint], 2: [activated_hint]})))
示例#6
0
 def test_get_active_hints_returns_no_active_hints_if_there_were_none_in_that_step(self):
     u = User(workshop_step=1)
     self.assertListEqual([], get_active_hints(u, WorkshopHints({})))
示例#7
0
 def test_get_active_hints_returns_no_active_hints_if_there_were_none_activated_yet(self):
     non_activated_hint = TextHint(1, "foo")
     hints_with_non_activated_hint = WorkshopHints({3: [non_activated_hint]})
     u = User(workshop_step=3)
     self.assertListEqual([], get_active_hints(u, hints_with_non_activated_hint))