def test_mail_valid_args(self): add_user2() self.login(email2, password2) with app.app_context(): self.assertRedirect( self.app.get(url_for('bs.mail', character_id=123, mail_id=456)), url_for('bs.dashboard'))
def test_unknown_character_id(self): add_user2() self.login(email2, password2) with app.app_context(): self.assertRedirect( self.app.get(url_for('bs.character', character_id=123)), url_for('bs.index'))
def login(self, email, password, target=None): with app.app_context(): url = url_for('bs.login') if target: url += '?next=' + target data = dict(email=email, password=password) return self.app.post(url, data=data, follow_redirects=True)
def test_mail_known_user_past(self): self.login(email, password) with app.app_context(): self.assertRedirect( self.app.get( url_for('bs.mail', character_id=character_id, mail_id=123)), url_for('bs.index'))
def test_maillist_foreign_id(self): # EVE character ID which does not belong to the active user. add_user2() self.login(email2, password2) with app.app_context(): self.assertRedirect( self.app.get(url_for('bs.maillist', character_id=chribba_id)), url_for('bs.dashboard'))
def test_mail_known_user_future(self): add_user3() self.login(email3, password3) with app.app_context(): self.assertRedirect( self.app.get( url_for('bs.mail', character_id=character_id, mail_id=123)), url_for('bs.dashboard'))
def test_remove_char_owner_mismatch(self): add_user3() self.login(email3, password3) with app.app_context(): self.assertRedirect( self.app.get( url_for('bs.rmcharacter', character_id=character_id)), url_for('bs.dashboard'))
def test_activate_valid(self): add_user4() with app.app_context(): self.assertRedirect( self.app.get( url_for('bs.activate', email=email4, token=activation_token)), url_for('bs.login'))
def test_callback(self): suffix = '?code=79ZuSjgpQQ34nVQUTqw1RpZMshfdK320q9Hdzh23UijlpLiMqjc-8ZRN7drWuFIF0' eml = self.new_user(password) self.login(eml, password) with app.app_context(): resp = self.app.get(url_for('sso.callback') + suffix, follow_redirects=True) self.assertTrue(b'Error obtaining authentication token' in resp.data)
def add_user2(): with app.app_context(): user = User() user.email = email2 user.password = password2 user.level = UserLevel.DEFAULT user.insert() return user
def add_user4(): with app.app_context(): user = User() user.email = email4 user.password = '******' user.activation_token = activation_token user.level = UserLevel.REGISTERED user.insert() return user
def test_eve_char_valid_ids(self): ids = set([chribba_id, eulynn_id]) with app.app_context(): self.inCache.eve_characters(ids) # populate cache cs = self.inCache.eve_characters(ids) self.assertEqual(len(ids), len(cs)) while cs: c = cs.pop() if c.eve_id == chribba_id: self.assertEqual(c.name, 'Chribba') elif c.eve_id == eulynn_id: self.assertEqual(c.name, 'Eulynn') else: self.fail(f'Unexpected ID {c.eve_id}')
def add_user3(): with app.app_context(): user = User() user.email = email3 user.password = password3 user.level = UserLevel.ADMIN character = Character() character.eve_id = character_id3 character.name = character_name3 character.token = json.dumps({ 'access_token': 'foo', 'expires_at': time.time() - 600, # Expired 10 minutes ago 'refresh_token': 'bar' }) user.characters = [character] user.insert() return user
def setUp(self): warnings.filterwarnings('ignore', message='unclosed <ssl\.SSLSocket ', category=ResourceWarning) warnings.filterwarnings( 'ignore', message='The psycopg2 wheel package will be renamed ', category=UserWarning) warnings.filterwarnings('ignore', message='update is deprecated.', category=DeprecationWarning) warnings.filterwarnings('ignore', message='save is deprecated.', category=DeprecationWarning) warnings.filterwarnings('ignore', message='remove is deprecated.', category=DeprecationWarning) app.config.from_object('bootini_star.config.Testing') self.app = app.test_client() with app.app_context(): user = User(ensure_indexes=True) user.email = email user.password = password user.level = UserLevel.DEFAULT character = Character() character.eve_id = character_id character.name = character_name character.token = { 'access_token': 'foo', 'expires_at': time.time() + 600, # Expires in 10 minutes 'refresh_token': 'bar' } user.characters = [character] self.assertIsNotNone(user.insert())
def signup(self, eml, pw, confirm=''): data = dict(email=eml, password=pw, confirm=confirm) with app.app_context(): return self.app.post(url_for('bs.signup'), data=data, follow_redirects=True)
def pwchange(self, current, pw, confirm=''): data = dict(current=current, password=pw, confirm=confirm) with app.app_context(): return self.app.post(url_for('bs.password'), data=data, follow_redirects=True)
def test_admin_unauthorised(self): self.login(email, password) with app.app_context(): self.assertRedirect(self.app.get(url_for('bs.admin')), url_for('bs.login'))
def test_admin_valid(self): add_user3() self.login(email3, password3) with app.app_context(): resp = self.app.get(url_for('bs.admin')) self.assertSubstr(CREATE_INDEXES, resp)
def test_good_character_id(self): add_user2() self.login(email2, password2) with app.app_context(): resp = self.app.get(url_for('bs.character', character_id=93779241)) self.assertTrue(b'Gallente Citizen 93779241' in resp.data)
def test_load_unknown_user(self): with app.app_context(): self.assertIsNone(user_loader(email2))
def test_activate_unknown_token(self): add_user4() with app.app_context(): self.assertRedirect( self.app.get(url_for('bs.activate', email=email4, token='bad')), url_for('bs.index'))
def test_signup_get(self): with app.app_context(): resp = self.app.get(url_for('bs.signup')) self.assertSubstr(forms.CPW_LABEL, resp)
def test_rm_mail_invalid_mail_id(self): self.login(email, password) with app.app_context(), self.assertRaises(ValueError): self.app.get(url_for('bs.rmmail', character_id=123, mail_id='bad'))
def test_signup_existing(self): add_user2() with app.app_context(): resp = self.signup(email2, password2, password2) self.assertSubstr(SIGNUP_FAILED, resp)
def test_change_pw_get(self): add_user2() self.login(email2, password2) with app.app_context(): resp = self.app.get(url_for('bs.password')) self.assertSubstr(forms.CURRENT_LABEL, resp)
def test_selfdestruct_get(self): add_user2() self.login(email2, password2) with app.app_context(): resp = self.app.get(url_for('bs.selfdestruct')) self.assertTrue(b'really want to delete your account' in resp.data)
def selfdestruct(self, eml, pw): data = dict(email=eml, password=pw) with app.app_context(): return self.app.post(url_for('bs.selfdestruct'), data=data, follow_redirects=True)
def test_activate_unknown_email(self): with app.app_context(): self.assertRedirect( self.app.get(url_for('bs.activate', email='bad', token='x')), url_for('bs.index'))
def test_index(self): with app.app_context(): resp = self.app.get(url_for('bs.index')) self.assertEqual(resp.status_code, 200)
def test_dashboard(self): add_user2() self.login(email2, password2) with app.app_context(): resp = self.app.get(url_for('bs.dashboard')) self.assertAppVersion(resp)