def setUp(self): with APP.app_context(): self.app = APP.test_client() self.request_headers = RequestHeaders( {'Authorization': 'Bearer ' + AuthToken.generate('testsource')}) self.log_file = 'test/fixtures/example-1.log' self.log_data = open(self.log_file, 'rb').read()
def setUp(self): with APP.app_context(): self.app = APP.test_client() self.request_headers = RequestHeaders({ 'Authorization': 'Bearer ' + AuthToken.generate('testsource') })
def init_database(): """Initialize the database""" with APP.app_context(): DB.drop_all() DB.create_all() # add a few entities for name in MOCK_DATA: entity = Entity(name) DB.session.add(entity) DB.session.commit()
def test_mailing(): ''' mailing functions ''' sender = TEST_USER[0]['email'] recipients = [TEST_USER[1]['email']] subject = 'Testsubject' body = 'Testbody' with APP.app_context(): with MAIL.record_messages() as outbox: mailing.send_email(sender=sender, subject=subject, recipients=recipients, body=body) assert outbox[0].sender == sender assert outbox[0].recipients == recipients assert outbox[0].subject == subject assert body in outbox[0].body
def test_category_paginator(self): """test funcionality of the paginator""" category = Category.query.order_by(func.random()).first() total_jokes = category.jokes.count() pages = math.ceil(total_jokes / PER_PAGE) remainder = total_jokes % PER_PAGE if remainder == 0: remainder = PER_PAGE with APP.app_context(): category_url = url_for('categories.category', name=category.name, _external=False) current_page_num = str(randint(1, pages)) url = APP.config[ 'SERVER_NAME'] + category_url + "page/" + current_page_num self.driver.get(url) jokes = self.driver.find_elements_by_class_name('joke') jokes_num = len(jokes) if current_page_num == pages: assert jokes_num == remainder else: assert jokes_num == PER_PAGE
def test_whatsup_post(client, test_user): with APP.app_context(): with MAIL.record_messages() as outbox: # add post login(client, test_user['email'], test_user['password']) add_whatsup_post(client, 'subject', 'body') # logout and try to access it logout(client) rv = client.get('/whatsup/1') assert rv.status_code == 302 # login again login(client, test_user['email'], test_user['password']) # add comment rv = add_whatsup_comment(client, 1, 'cömment1') assert rv.status_code == 200 assert 'Kommentar abgeschickt!' in rv.data # database entries rv = models.get_whatsup_post(1) assert rv.comments[0].body == 'cömment1'.decode('utf-8') assert rv.comments[0].post_id == 1 assert rv.comments[0].user_id == test_user['id'] # add 3 more comments sleep(1) add_whatsup_comment(client, 1, 'comment2') sleep(1) add_whatsup_comment(client, 1, 'comment3') sleep(1) add_whatsup_comment(client, 1, 'comment4') assert len(models.get_whatsup_post(1).comments) == 4 # create soup rv = client.get('/whatsup/1') soup = BeautifulSoup(rv.data) rv = soup.find_all('div', class_='media-body') # discussion icon counter assert '4' in rv[0].text # checking comment order assert 'comment4' in rv[1].text assert 'comment3' in rv[2].text assert 'comment2' in rv[3].text assert 'cömment1'.decode('utf-8') in rv[4].text # checking names assert '{} {}'.format( test_user['vorname'], test_user['name']) in rv[0].text.encode('utf-8') assert '{} {}'.format( test_user['vorname'], test_user['name']) in rv[1].text.encode('utf-8') assert '{} {}'.format( test_user['vorname'], test_user['name']) in rv[2].text.encode('utf-8') assert '{} {}'.format( test_user['vorname'], test_user['name']) in rv[3].text.encode('utf-8') assert '{} {}'.format( test_user['vorname'], test_user['name']) in rv[4].text.encode('utf-8') # check notification emails assert outbox[0].sender == '{} {} <{}>'.format( unidecode(test_user['vorname'].decode('utf-8')), unidecode( test_user['name'].decode('utf-8')), test_user['email']) assert outbox[0].subject == 'Kommentar in "{}"'.format('subject') assert '{} {} hat geschrieben:'.format( unidecode(test_user['vorname'].decode('utf-8')), unidecode(test_user['name'].decode('utf-8'))) in outbox[0].body assert 'cömment1'.decode('utf-8') in outbox[0].body assert '/whatsup/1' in outbox[0].body
def test_generate_auth_token(self): with APP.app_context(): auth_token = AuthToken.generate('client') assert len(auth_token) == 148
def test_verify_auth_token_fails(self): with APP.app_context(): self.assertFalse(AuthToken.verify('thisisfake'))
def test_verify_auth_token_succeeds(self): with APP.app_context(): auth_token = AuthToken.generate('client') response = AuthToken.verify(auth_token) self.assertTrue(response)
def setUp(self): self.app = APP.test_client() with APP.app_context(): DB.create_all()
def tearDown(self): with APP.app_context(): DB.session.remove() DB.drop_all()
print('users in room: ', room.users) # test room methods print() print('room.most_recent_video:') print(room.most_recent_video.data) print('room.online_users') room.online_users print('room.recent_history:') print(room.recent_history.data) except Exception as error: print('!! FAILED: ', error) # delete objects created print() print('cleaning up...') db.session.delete(user) db.session.delete(room) db.session.commit() print('success!!!') if __name__ == '__main__': with APP.app_context(): test_room_model(models.db)
def setUp(self): with APP.app_context(): self.app = APP.test_client() self.request_headers = RequestHeaders({'Authorization': 'None'})
def generate_api_token(client): with APP.app_context(): return AuthToken.generate(client)