Esempio n. 1
0
 def test_unlock_all_hints_for_step_unlocks_all_hints_for_the_user(self):
     u = self.create_user()
     hint = TextHint(1, "activated")
     user_hint = UserHints(id=hint.id, user_id=u.id)
     db.session.add(user_hint)
     db.session.commit()
     new_hint = TextHint(2, "not activated")
     self.assertIsNone(UserHints.query.filter(UserHints.id == new_hint.id).first())
     unlock_all_hints_for_step(1, u, WorkshopHints({1: [hint, new_hint]}))
     self.assertIsNotNone(UserHints.query.filter(UserHints.id == new_hint.id).first())
Esempio n. 2
0
from passlib.apps import custom_app_context as pwd_context
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Length
from xhtml2pdf import pisa

from hint import Hint, WorkshopHints

app = flask.Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', '')
app.config['SECRET_KEY'] = 'foo-bar'
app.config['CSRF_SESSION_KEY'] = 'foo-bar'
db = SQLAlchemy(app)

workshop_hints = WorkshopHints()


class User(db.Model):
    """
    Represents a user in the database.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), unique=True)
    password = db.Column(db.String(255), nullable=False)
    workshop_step = db.Column(db.Integer, default=1, nullable=False)
    hints = relationship("UserHints", back_populates="user")

    def is_password_valid(self, password: str) -> bool:
        """
        Checks if the entered password matches the stored hash.
Esempio n. 3
0
 def test_that_getting_hints_for_an_known_step_returns_an_empty_list(self):
     h = WorkshopHints()
     self.assertNotEqual(0, len(h.get_hints_for_step(GITHUB)))
Esempio n. 4
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))
Esempio n. 5
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))
Esempio n. 6
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]})))
Esempio n. 7
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({})))
Esempio n. 8
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))