def test_sort_by_author_name(self): R({ 'name': 'Recipe 1', 'state': 'PUBLISHED', 'author': model.User(username='******', email='*****@*****.**') }) R({ 'name': 'Recipe 2', 'state': 'PUBLISHED', 'author': model.User(username='******', email='*****@*****.**') }) R({ 'name': 'Recipe 3', 'state': 'PUBLISHED', 'author': model.User(username='******', email='*****@*****.**') }) R({ 'name': 'Recipe 4', 'state': 'PUBLISHED', 'author': model.User(username='******', email='*****@*****.**') }) R({ 'name': 'Recipe 5', 'state': 'PUBLISHED', 'author': model.User(username='******', email='*****@*****.**') }) model.commit() self._get({'order_by': 'author'}) self._eq('pages', 1) self._eq('current_page', 1) self._eq('offset', 0) self._eq('perpage', 25) self._eq('total', 5) self._eq('order_by', 'author') self._eq('direction', 'DESC') assert len(self._ns['recipes']) == 5 assert self._ns['recipes'][0].name == 'Recipe 3' assert self._ns['recipes'][1].name == 'Recipe 2' assert self._ns['recipes'][2].name == 'Recipe 5' assert self._ns['recipes'][3].name == 'Recipe 4' assert self._ns['recipes'][4].name == 'Recipe 1' self._get({'order_by': 'author', 'direction': 'ASC'}) self._eq('pages', 1) self._eq('current_page', 1) self._eq('offset', 0) self._eq('perpage', 25) self._eq('total', 5) self._eq('order_by', 'author') self._eq('direction', 'ASC') assert len(self._ns['recipes']) == 5 assert self._ns['recipes'][0].name == 'Recipe 1' assert self._ns['recipes'][1].name == 'Recipe 4' assert self._ns['recipes'][2].name == 'Recipe 5' assert self._ns['recipes'][3].name == 'Recipe 2' assert self._ns['recipes'][4].name == 'Recipe 3'
def test_printed_first_name(self): assert model.User(first_name='Ryan', last_name='Petrello', username='******').printed_first_name == 'Ryan' assert model.User( first_name='', last_name='Petrello', username='******').printed_first_name == 'ryanpetrello' assert model.User( username='******').printed_first_name == 'ryanpetrello'
def test_abbreviated_name(self): assert model.User( first_name='Ryan', last_name='Petrello', username='******').abbreviated_name == 'Ryan P.' assert model.User( first_name='Ryan', last_name='', username='******').abbreviated_name == 'ryanpetrello' assert model.User( username='******').abbreviated_name == 'ryanpetrello'
def test_author_copy_with_overrides(self): model.Recipe(name='Rocky Mountain River IPA', author=model.User()) model.commit() recipe = model.Recipe.query.first() recipe.duplicate({'author': model.User()}) model.commit() assert model.Recipe.query.count() == 2 assert model.User.query.count() == 2 r1, r2 = model.Recipe.get(1), model.Recipe.get(2) assert r1.author and r2.author assert r1.author != r2.author
def test_setting_change(self): user = model.User(username=u'ryanpetrello', password=u'testing123', email=u'*****@*****.**') user.settings['default_ibu_formula'] = 'rager' assert user.user_settings['default_ibu_formula']._value == '"rager"'
def test_setting_add(self): user = model.User(username=u'ryanpetrello', password=u'testing123', email=u'*****@*****.**') user.settings['example'] = 5.5 assert user.user_settings['example']._value == '5.5'
def test_default_creation(self): user = model.User(username=u'ryanpetrello', password=u'testing123', email=u'*****@*****.**') assert user.settings['default_ibu_formula'] == 'tinseth' assert user.settings['default_recipe_volume'] == 5 assert user.settings['default_recipe_type'] == 'MASH' assert user.settings['brewhouse_efficiency'] == .75
def test_view_draft_recipe_async(self): model.Recipe(name='Rocky Mountain River IPA', author=model.User(first_name='Ryan', last_name='Petrello'), state="DRAFT") model.commit() response = self.get('/recipes/1/rocky-mountain-river-ipa/', status=404) assert response.status_int == 404
def test_valid_login(self): model.User(username='******', password='******') model.commit() response = self.post('/login', params={ 'username': '******', 'password': '******' }) assert response.request.environ['beaker.session']['user_id'] == 1
def test_unauthorized_lookup_other_user(self): """ If the recipe has an author, and we're logged in as another user, we should *not* have access to edit the recipe. """ model.Recipe(name='American IPA', slugs=[model.RecipeSlug(name='American IPA')], author=model.User()) model.commit() response = self.get('/recipes/1/american-ipa/builder', status=401) assert response.status_int == 401
def test_valid_sha256_login(self): salt = 'example' model.User(username='******', _password=sha256('secret' + salt).hexdigest()) model.commit() response = self.post('/login', params={ 'username': '******', 'password': '******' }) assert response.request.environ['beaker.session']['user_id'] == 1
def test_invalid_credentials(self): model.User(username='******', password='******') model.commit() response = self.post('/login', params={ 'username': '******', 'password': '******' }) assert response.status_int == 200 assert len(self.get_form(response).errors) assert 'user_id' not in response.request.environ['beaker.session']
def test_author_copy(self): model.Recipe(name='Rocky Mountain River IPA', author=model.User()) model.commit() recipe = model.Recipe.query.first() recipe.duplicate() model.commit() assert model.Recipe.query.count() == 2 assert model.User.query.count() == 1 r1, r2 = model.Recipe.get(1), model.Recipe.get(2) assert r1.author == r2.author == model.User.get(1)
def test_password_conversion(self): user = model.User(username=u'ryanpetrello', password=u'testing123', email=u'*****@*****.**') salt = user.password.split(':')[0] hashed = model.User.__hash_password__('testing123', salt) assert user.password == hashed user.password = '******' salt = user.password.split(':')[0] hashed = model.User.__hash_password__('tryagain', salt) assert user.password == hashed
def test_view_published_recipe(self): model.User(email='*****@*****.**') model.Recipe(name='Rocky Mountain River IPA', author=model.User.get(1), state="PUBLISHED") model.commit() response = self.get('/recipes/1/rocky-mountain-river-ipa/') assert response.status_int == 200 assert len(model.Recipe.query.first().views) == 0 response = self.post('/recipes/1/rocky-mountain-river-ipa/index.json', status=200) assert response.status_int == 200 assert len(model.Recipe.query.first().views) == 1
def _post(self, **kw): username = kw['username'] password = kw['password'] email = kw['email'].replace(' ', '') user = model.User(username=username, password=password, email=email) if request.context['trial_recipe']: request.context['trial_recipe'].author = user remove_trial_recipe() request.context['__signup_email__'] = email request.context['__signup_username__'] = username pecan.redirect('/login?welcome')
def setUp(self): super(TestAuthenticatedApp, self).setUp() # # Make a user and authenticate as them. # dcmodel.User(username='******', password='******', email='*****@*****.**') dcmodel.commit() response = self.post('/login', params={ 'username': '******', 'password': '******' }) assert 'user_id' in response.request.environ['beaker.session']
def test_password_reset(self, fake_send): (fake_send.expects_call().with_args( '*****@*****.**', 'forgot', 'Reset Your Draughtcraft Password', { 'name': 'Ryan', 'code': arg.any() })) model.User(first_name=u'Ryan', email=u'*****@*****.**') model.commit() response = self.post('/forgot/', params={'email': model.User.get(1).email}) assert model.PasswordResetRequest.query.count() == 1 assert response.status_int == 302 assert response.headers['Location'].endswith('/login')
def test_choose_new_password_expired(self): model.User(username='******', password='******', first_name=u'Ryan', email=u'*****@*****.**') model.commit() response = self.post('/forgot/reset/ABC123', params={ 'email': '*****@*****.**', 'password': '******', 'password_confirm': 'newpass' }) assert response.status_int == 200 assert model.PasswordResetRequest.query.count() == 0 assert model.User.validate('ryan', 'newpass') is None assert model.User.validate('ryan', 'testing') == model.User.query.first()
def test_choose_new_password_invalid_email(self): model.User(username='******', password='******', first_name=u'Ryan', email=u'*****@*****.**') model.commit() model.PasswordResetRequest(code='ABC123', user=model.User.get(1)) self.post('/forgot/reset/ABC123', params={ 'email': '*****@*****.**', 'password': '******', 'password_confirm': 'newpass' }) assert model.PasswordResetRequest.query.count() == 1 assert model.User.validate('ryan', 'newpass') is None assert model.User.validate('ryan', 'testing') == model.User.query.first()
def test_choose_new_password(self): model.User(username='******', first_name=u'Ryan', email=u'*****@*****.**') model.commit() model.PasswordResetRequest(code='ABC123', user=model.User.get(1)) response = self.post('/forgot/reset/ABC123', params={ 'email': '*****@*****.**', 'password': '******', 'password_confirm': 'newpass' }) assert response.status_int == 302 assert response.headers['Location'].endswith('/login') assert model.PasswordResetRequest.query.count() == 0 assert model.User.validate('ryan', 'newpass') == model.User.query.first()
def test_ibu_formula_selection_with_author(self): """ The IBU calculation formula used should be whatever the recipe's author has specified. """ user = model.User() recipe = model.Recipe( name='Rocky Mountain River IPA', gallons=5, author=user ) model.HopAddition( recipe=recipe, hop=model.Hop(name='Cascade'), amount=.0625, # 1 oz unit='POUND', duration=timedelta(minutes=30), alpha_acid=5.5, form='LEAF', use='BOIL' ) model.HopAddition( recipe=recipe, hop=model.Hop(name='Centennial'), amount=.0625, # 1 oz unit='POUND', duration=timedelta(minutes=60), alpha_acid=5.5, form='LEAF', use='BOIL' ) assert user.settings['default_ibu_formula'] == 'tinseth' assert recipe.calculations.ibu == recipe.calculations.tinseth user.settings['default_ibu_formula'] = 'rager' assert recipe.calculations.ibu == recipe.calculations.rager user.settings['default_ibu_formula'] = 'daniels' assert recipe.calculations.ibu == recipe.calculations.daniels
def test_trial_recipe_conversion(self): """ Create a recipe as a guest. After login, the recipe should belong to the authenticated user. """ params = { 'name': 'Rocky Mountain River IPA', 'type': 'MASH', 'volume': 25, 'unit': 'GALLON' } self.post('/recipes/create', params=params) assert model.Recipe.query.count() == 1 assert model.Recipe.get(1).author is None # Create a new user model.User(username='******', password='******') model.commit() # Log in as the new user assert len(model.User.get(1).recipes) == 0 response = self.post('/login', params={ 'username': '******', 'password': '******' }) assert response.request.environ['beaker.session']['user_id'] == 1 # # The recipe should have been attached to the new user, and the # `trial_recipe_id` record should have been removed from the session. # assert len(model.User.get(1).recipes) == 1 assert 'trial_recipe_id' not in response.request.environ[ 'beaker.session']
def test_gravatar(self): user = model.User(username=u'ryanpetrello', password=u'testing123', email=u' [email protected] ') assert user.gravatar == "https://www.gravatar.com/avatar/%s?d=404" % ( md5('*****@*****.**').hexdigest())
def R(kwargs): recipe = model.Recipe(**kwargs) if 'author' not in kwargs: recipe.author = model.User.query.first() or model.User( email='*****@*****.**') return recipe
def test_full_name(self): assert model.User(first_name='Ryan', last_name='Petrello').full_name == 'Ryan Petrello'
def test_efficiency(self): assert model.Recipe().efficiency == .75 user = model.User() model.UserSetting(user=user, name='brewhouse_efficiency', value=.80) assert model.Recipe(author=user).efficiency == .80
def test_json_value(self): user = model.User(username=u'ryanpetrello', password=u'testing123', email=u'*****@*****.**') assert user.user_settings['default_ibu_formula']._value == '"tinseth"' assert user.user_settings['default_recipe_volume']._value == '5'