Пример #1
0
 def test_filtering(self):
     """
     Tests filtering with an empty query, so just displaying all the recipes
     """
     with app.test_request_context('/filter', method='GET'):
         resp = app.dispatch_request()
         self.assertIn('displaying', str(resp))
Пример #2
0
    def test_check_history_table(self):
        with app.test_request_context():
            tester=app.test_client(self)
            db.drop_all()
            db.create_all()
            tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******'))
            tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
            login_user(User.query.first())
            tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='80228'), follow_redirects=True)

            gallons = 975
            day = 1
            rates = []
            totals = []

            for quote in range(31):
                suggestRate, total = calculateRateAndTotal(gallons)
                rates.append(bytes(str(suggestRate),"ascii"))
                totals.append(bytes(str(total),"ascii"))
                tester.post('/quote',data=dict(gallonsRequested=str(gallons),deliveryDate='2020-07-'+str(day),deliveryAddress="123456123456 789456789456",rate=str(suggestRate),total=str(total),submit="True"), follow_redirects=True)
                gallons += 1
                day += 1

            response = tester.get('/history',content_type='html/text')

            for quote in range(31):
                self.assertIn(rates[quote],response.data)
                self.assertIn(totals[quote],response.data)
Пример #3
0
 def test_login_post(self):
     """
     Testing if loging in works properly
     """
     ### Unfortunetely does not give proper result due to issue with session testing. Template should contain "Login", it does not
     with app.test_request_context('/login',
                                   method='POST',
                                   data=dict(author_name="Kaja",
                                             password="******")):
         resp = app.dispatch_request()
         self.assertNotIn('Logout', str(resp))
     # Checking if works and displays expected message
     with app.test_request_context('/login',
                                   method='POST',
                                   data=dict(author_name="Kittykat",
                                             password="******")):
         resp = app.dispatch_request()
         self.assertIn('User does not exist', str(resp))
Пример #4
0
 def test_logout_redirect(self):
     with app.test_request_context():
         tester=app.test_client(self)
         db.drop_all()
         db.create_all()
         tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******'))
         tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
         login_user(User.query.first())
         response = tester.get('/logout',content_type='html/text', follow_redirects=True)
         self.assertIn(b"Login Here", response.data)
Пример #5
0
 def test_get_random_animal(self):
     ''' Test if function returns any value '''
     with app.test_request_context():
         self.assertIsNotNone(get_random_animal())
         '''Test if session variable is set (not empty)'''
         with app.test_client() as client:
             with client.session_transaction():
                 get_random_animal()
                 random_animal = session.get('random_animal')
                 self.assertIsNotNone(random_animal)
Пример #6
0
 def test_logout_redirect(self):
     with app.test_request_context():
         tester = app.test_client(self)
         tester.post('/home',
                     data=dict(username="******", password='******'),
                     follow_redirects=True)
         login_user(User.query.first())
         response = tester.get('/logout',
                               content_type='html/text',
                               follow_redirects=True)
         self.assertIn(b"Login Here", response.data)
Пример #7
0
 def test_rate_for_new_non_texans_with_more_than_1000_gallons(self):
     with app.test_request_context():
         tester=app.test_client(self)
         db.drop_all()
         db.create_all()
         tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******'))
         tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
         login_user(User.query.first())
         tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='80228'), follow_redirects=True)
         suggestRate, total = calculateRateAndTotal(1234)
         self.assertEqual(suggestRate,Decimal('1.74'))
         self.assertEqual(total,Decimal('2147.16'))
Пример #8
0
 def test_rate_for_old_texans_with_more_than_1000_gallons(self):
     with app.test_request_context():
         tester=app.test_client(self)
         db.drop_all()
         db.create_all()
         tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******'))
         tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
         login_user(User.query.first())
         tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Houston",state="TX",zipcode='77777'), follow_redirects=True)
         tester.post('/quote',data=dict(gallonsRequested="546",deliveryDate='2020-07-20',deliveryAddress="123456123456 Sample Drive",rate="2.00",total="1092",submit="True"), follow_redirects=True)
         suggestRate, total = calculateRateAndTotal(2002)
         self.assertEqual(suggestRate,Decimal('1.7'))
         self.assertEqual(total,Decimal('3403.4'))
Пример #9
0
 def test_rate_for_old_non_texans_with_more_than_1000_gallons(self):
     with app.test_request_context():
         tester=app.test_client(self)
         db.drop_all()
         db.create_all()
         tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******'))
         tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
         login_user(User.query.first())
         tester.post('/profile',data=dict(name="bob",address1='123456123456',address2="789456789456",city="Denver",state="CO",zipcode='80228'), follow_redirects=True)
         tester.post('/quote',data=dict(gallonsRequested="899",deliveryDate='2020-07-20',deliveryAddress="123456123456 789456789456",rate="1.73",total="1555.27",submit="True"), follow_redirects=True)
         suggestRate, total = calculateRateAndTotal(2255)
         self.assertEqual(suggestRate,Decimal('1.72'))
         self.assertEqual(total,Decimal('3878.6'))
Пример #10
0
    def test_check_links_ADMIN(self):
        with app.test_request_context():
            tester = app.test_client(self)
            tester.post('/home',
                        data=dict(username="******", password='******'),
                        follow_redirects=True)
            login_user(User.query.first())
            response = tester.get('/links', content_type='html/text')
            userType = User.query.first().type

            if (userType == "ADMIN"):
                self.assertIn(b'Manage User Accounts', response.data)
                self.assertIn(b'Assign Roles', response.data)
                self.assertIn(b'Help Desk', response.data)
Пример #11
0
    def test_redirection_to_profile_from_registration(self):
        with app.test_request_context():
            tester=app.test_client(self)
            db.drop_all()
            db.create_all()
            hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8')
            user = User(username="******", email="*****@*****.**", password=hashed_password)
            db.session.add(user)
            db.session.commit()
            login_user(user)

            tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
            response = tester.get('/registration',content_type='html/text', follow_redirects=True)
            self.assertIn(b'Change Profile', response.data)
Пример #12
0
    def test_check_links_SALES_ADMIN(self):
        with app.test_request_context():
            tester = app.test_client(self)
            tester.post('/home',
                        data=dict(username="******", password='******'),
                        follow_redirects=True)
            login_user(User.query.first())
            response = tester.get('/links', content_type='html/text')
            userType = User.query.first().type

            if (userType == "SALES_ADMIN"):
                self.assertIn(b'Sales Reports', response.data)
                self.assertIn(b'Sales Leads', response.data)
                self.assertIn(b'Sales Demo', response.data)
Пример #13
0
    def test_check_links_FINANCE_ADMIN(self):
        with app.test_request_context():
            tester = app.test_client(self)
            tester.post('/home',
                        data=dict(username="******", password='******'),
                        follow_redirects=True)
            login_user(User.query.first())
            response = tester.get('/links', content_type='html/text')
            userType = User.query.first().type

            if (userType == "FINANCE_ADMIN"):
                self.assertIn(b'Finance Reports', response.data)
                self.assertIn(b'Accounts Payable', response.data)
                self.assertIn(b'Accounts Receivale', response.data)
                self.assertIn(b'Tax', response.data)
Пример #14
0
 def test_redirection_to_quote_if_profile_exists(self):
     with app.test_request_context():
         tester=app.test_client(self)
         db.drop_all()
         db.create_all()
         hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8')
         user = User(username="******", email="*****@*****.**", password=hashed_password)
         db.session.add(user)
         db.session.commit()
         login_user(user)
         profile = Profile(name="bob", address1="Sample Drive", address2="", city="Houston",state="TX", zipcode="77777", user_id=current_user.id)
         db.session.add(profile)
         db.session.commit()
         response = tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
         self.assertIn(b'Get Your Quote', response.data)
Пример #15
0
    def test_check_links_HR_ADMIN(self):
        with app.test_request_context():
            tester = app.test_client(self)
            tester.post('/home',
                        data=dict(username="******", password='******'),
                        follow_redirects=True)
            login_user(User.query.first())
            response = tester.get('/links', content_type='html/text')
            userType = User.query.first().type

            if (userType == "HR_ADMIN"):
                self.assertIn(b'New Hire On-boarding', response.data)
                self.assertIn(b'Benefits', response.data)
                self.assertIn(b'Payroll', response.data)
                self.assertIn(b'Off-boarding', response.data)
                self.assertIn(b'HR Reports', response.data)
Пример #16
0
    def test_check_links_TECH_ADMIN(self):
        with app.test_request_context():
            tester = app.test_client(self)
            tester.post('/home',
                        data=dict(username="******", password='******'),
                        follow_redirects=True)
            login_user(User.query.first())
            response = tester.get('/links', content_type='html/text')
            userType = User.query.first().type

            if (userType == "TECH_ADMIN"):
                self.assertIn(b'Application Monitoring', response.data)
                self.assertIn(b'Tech Support', response.data)
                self.assertIn(b'App Development', response.data)
                self.assertIn(b'App Admin', response.data)
                self.assertIn(b'Release Management', response.data)
Пример #17
0
def authorization():
    '''用户验证'''
    code = request.args.get('code')
    api = WeixinAPI(appid=APP_ID,
                    app_secret=APP_SECRET,
                    redirect_uri=REDIRECT_URI)
    auth_info = api.exchange_code_for_access_token(code=code)
    api = WeixinAPI(access_token=auth_info['access_token'])
    resp = api.user(openid=auth_info['openid'])

    with app.test_request_context():
        if check_user(auth_info['openid']):
            requests.post(data=resp)
        else:
            requests.put(data=resp)

    return jsonify(code=0)
Пример #18
0
    def test_add_to_user_data_file(self):
        ''' Test if functions inserts entry in file is added to user_data file based on arguments passed'''
        with app.test_request_context():
            clear_user_data_json()
            add_new_user('test_username')
            with app.test_client() as client:
                with client.session_transaction():
                    session['random_animal'] = {"title": "test_animal_title"}
                    add_to_user_data_file('test_username', 'animals')
                    add_to_user_data_file('test_username', 'correctlyGuessed')
                    add_to_user_data_file('test_username', 'passed')

                    self.assertIn("test_animal_title",
                                  open_user_data_json()[0]["animals"])
                    self.assertIn("test_animal_title",
                                  open_user_data_json()[0]["correctlyGuessed"])
                    self.assertIn("test_animal_title",
                                  open_user_data_json()[0]["passed"])
Пример #19
0
 def test_create_player(self):
     """
     Test that the a session is created and populated with a value for username and appended to player_info [] list as dictionary
     """
     with app.test_client() as c:
         with c.session_transaction() as sess:
             sess['username'] = '******'
             with app.test_request_context():
                 self.assertEqual(run.create_player(sess['username']),
                                  [{
                                      'username': '******',
                                      'score': 0,
                                      'attempt': 0,
                                      "wrong": 0,
                                      "riddle_number": 0,
                                      "attempt_total": 0,
                                      "restart": False,
                                      "resume": False
                                  }])
Пример #20
0
 def test_check_username(self):
     with self.app as c:
         with c.session_transaction() as sess:  #creates session
             sess['username'] = '******'
             with app.test_request_context():
                 username = '******'
                 usernames = []
                 if not usernames and username == 'bob' and sess['username']:
                     self.assertTrue(run.check_username(username))
                 username = '******'
                 usernames = []
                 if usernames and username == 'bob' and not sess['username']:
                     self.assertFalse(run.check_username(username))
                 username = '******'
                 usernames = ['bob']
                 if usernames and username == 'bob' and sess['username']:
                     self.assertTrue(run.check_username(username))
                 username = '******'
                 usernames = ['bob']
                 if not usernames and username == 'bob':
                     self.assertFalse(run.check_username(username))
Пример #21
0
#!/usr/bin/python3
from run import app
from datetime import datetime
import traceback
import models.merge as merge
import models.delete as delete
import models.link as link

with app.test_request_context():

    # grab all pending tasks ordered by creation time
    tasks = sorted(
        merge.Merge.getPending(app.data.driver.db)
        + delete.Delete.getPending(app.data.driver.db)
        + link.Link.getPending(app.data.driver.db)
    )
    
    # now, perform the first one if it exists
    if tasks: 
        try:
            tasks[0].do().commit()
            print(
                'Task %s (%s) run successfully at %s for %s'
                % (
                    tasks[0].getId(),
                    tasks[0].collection,
                    datetime.now(),
                    tasks[0].getOwner().get('name')
                )
            )
        except Exception as e:
Пример #22
0
    def test_rendering_add_page(self):

        with app.test_request_context('add_recipe', method='GET'):
            resp = app.dispatch_request()
            self.assertEqual(resp._status_code, 302)
Пример #23
0
from run import app
from flask import url_for

# --------------------------------------------------------
# Testing
# --------------------------------------------------------
with app.test_request_context():
    print(url_for('join_room', room_id=123))