Example #1
0
    def test_if_verification_unssuccessul(self):
        with app.app_context():
            email = '*****@*****.**'
            expires = int(time.time()) + 86400
            fake_expire = int(time.time()) + 3600
            verification_code = generate_verification_code(
                "{email}{expires}".format(email=email, expires=expires))

            response = app.test_client().get(
                '/verify/{email}/{verification_code}/{expires}'.format(
                    email='*****@*****.**',
                    verification_code=verification_code,
                    expires=expires),
                follow_redirects=True)
            self.assertIn(b'Verification failed!', response.data)

            response = app.test_client().get(
                '/verify/{email}/{verification_code}/{expires}'.format(
                    email=email,
                    verification_code='wrong-code',
                    expires=expires),
                follow_redirects=True)
            self.assertIn(b'Verification failed!', response.data)

            response = app.test_client().get(
                '/verify/{email}/{verification_code}/{expires}'.format(
                    email=email,
                    verification_code=verification_code,
                    expires=fake_expire),
                follow_redirects=True)
            self.assertIn(b'Verification failed!', response.data)
Example #2
0
def test5():
    c = app.test_client()
    with c.session_transaction() as sess:
        sess['email'] = '*****@*****.**'
        sess['_fresh'] = True
    response = c.get("/profile")  #,query_string=dict(productId="9"))
    assert response.status_code == 200
Example #3
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)
Example #4
0
 def test_user_registration(self):
     tester=app.test_client(self)
     db.drop_all()
     db.create_all()
     tester.post('/registration',data=dict(username='******', email='*****@*****.**', password='******', confirm_password='******'))
     response = tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
     self.assertIn(b'Change Profile', response.data)
 def setUp(self):
     self.server = app.test_client()
     database.clear()
     self.user1 = database.create_user({'name': 'new user 1'})
     self.user2 = database.create_user({'name': 'new user 2'})
     self.headers_user1 = {'Authorization' : 'token %s' % self.user1['token']}
     self.headers_user2 = {'Authorization': 'token %s' % self.user2['token']}
Example #6
0
 def setUp(self):
     self.app = app.test_client()
     self.app.testing = True
     self.new_survey_data = {
         'survey_name': 'Opinions about lemons',
         'available_places': 30,
         'user_id': 5438
     }
     self.survey_response_success = {
         'survey_id': 654321,
         'user_id': 8756,
     }
     self.survey_response_fail = {
         'survey_id': 88765,
         'user_id': 8756,
     }
     self.all_surveys = [{
         "survey_name": "Test Survey",
         "survey_id": "098430",
         "available_places": 23,
         "user_id": "3214"
     }, {
         "survey_id": "820616",
         "survey_name": "Thoughts on Dogs",
         "available_places": 15,
         "user_id": "5438"
     }, {
         "survey_id": "292284",
         "survey_name": "Opinions about Trees",
         "available_places": 30,
         "user_id": "2483"
     }]
Example #7
0
    def setUp(self):
        """Set up test client and populate test database with test data
        """
        self.app = app.test_client()
        db.create_all()
        user = User(username="******", password="******")
        student = Student(student_id="ST001",
                          first_name="Hermione",
                          last_name="Granger",
                          email_address="*****@*****.**")
        teacher = Teacher(staff_id="TC001",
                          first_name="Minerva",
                          last_name="McGonagall",
                          email_address="*****@*****.**")
        subject = Subject(subject_id="SB001",
                          name="Transfiguration",
                          description="Teaches the art of changing the form "
                          "and appearance of an object or a person.")

        subject.major_students.append(student)
        teacher.subjects_taught.append(subject)

        db.session.add(user)
        db.session.add(student)
        db.session.add(teacher)
        db.session.add(subject)

        self.token = self.get_token()
def test_home_oauth_redirect():
    app.config['TESTING'] = False
    test_client = app.test_client()
    rsp = test_client.get('/')
    assert rsp.status == '302 FOUND'
    html = rsp.get_data(as_text=True)
    assert '<a href="/oauth2callback">/oauth2callback</a>' in html
def test_error():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.get('/error/TEST')
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert '<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> TEST' in html
Example #10
0
 def test_if_email_signup_form_renders(self):
     with captured_templates(app) as templates:
         response = app.test_client().get('/signup')
         self.assertEqual(response.status_code, 200)
         assert len(templates) == 1
         template, context = templates[0]
         assert template.name == 'mod_auth/signup.html'
Example #11
0
    def test_get_routes_no_params(self):
        tester = app.test_client(self)

        response = tester.get('/', content_type="html/text")
        self.assertEqual(response.status_code, 200)

        response = tester.get('/get_food_items', content_type="html/text")
        self.assertEqual(response.status_code, 200)

        response = tester.get('/add_food_item', content_type="html/text")
        self.assertEqual(response.status_code, 200)

        response = tester.get('/get_classification', content_type="html/text")
        self.assertEqual(response.status_code, 200)

        response = tester.get('/add_class', content_type="html/text")
        self.assertEqual(response.status_code, 200)

        response = tester.get('/dashboard', content_type="html/text")
        self.assertEqual(response.status_code, 200)

        response = tester.get('/about', content_type="html/text")
        self.assertEqual(response.status_code, 200)

        response = tester.get('/contact', content_type="html/text")
        self.assertEqual(response.status_code, 200)
def test_home_page():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.get('/')
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert '<h3>Search for an account to manage delegates for</h3>' in html
Example #13
0
def client():
    with app.test_client() as client:
        with app.app_context():
            app.init_app()
        yield client
        db.session.remove()
        db.drop_all()
def test_home_page():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.get('/')
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert '<h3>Search for an account to manage delegates for</h3>' in html
def test_get_delegate():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.get('/delegate/example.com/test.user')
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/example.com/test.user/delegation' in html
Example #16
0
    def test_get_routes_no_params_connect_to_correct_template(self):
        tester = app.test_client(self)

        response = tester.get('/', content_type="html/text")
        self.assertTrue(b'Nutrition Value App' in response.data)

        response = tester.get('/get_food_items', content_type="html/text")
        self.assertTrue(
            b'Click to check the details of each food item' in response.data)

        response = tester.get('/add_food_item', content_type="html/text")
        self.assertTrue(
            b'Add the details for the food item you want to add and click the "Add" button'
            in response.data)

        response = tester.get('/get_classification', content_type="html/text")
        self.assertTrue(
            b'The following is a list of food classifications in this data set'
            in response.data)

        response = tester.get('/add_class', content_type="html/text")
        self.assertTrue(b'Add a Food Class' in response.data)

        response = tester.get('/dashboard', content_type="html/text")
        self.assertTrue(b'Dashboard' in response.data)

        response = tester.get('/about', content_type="html/text")
        self.assertTrue(b'About this App' in response.data)

        response = tester.get('/contact', content_type="html/text")
        self.assertTrue(b'Contact Us' in response.data)
Example #17
0
    def test_post_correct_answer_and_receive_10_points(self):
        """ 
       Test 8. Test that a correct answer on the first question page will redirect to the second question page and 
       a score has been received.
        """
        data = dict(answer="tomorrow")

        with app.test_client(self) as client:
            with client.session_transaction() as session:
                session['score'] = 0
                session['page_number'] = 0
                session['message_display_number'] = 0
                session['display_points'] = 0
                session['last_incorrect_answer'] = ""

            response1 = client.get('/conundrum/user', content_type='html/text')
            self.assertEqual(response1.status_code, 200)
            self.assertIn('Question 1 of 10', str(response1.data))
            self.assertIn('0 points', str(response1.data))

            response2 = client.post('/conundrum/user',
                                    content_type='multipart/form-data',
                                    data=data)
            self.assertEqual(response2.status_code, 302)

            response3 = client.get('/conundrum/user', content_type='html/text')
            self.assertEqual(response3.status_code, 200)
            self.assertIn('Question 2 of 10', str(response3.data))
            self.assertNotIn('Question 1 of 10', str(response3.data))
            self.assertIn('10 points', str(response3.data))
Example #18
0
 def test_all_users(self):
     tester = app.test_client(self)
     response = tester.get('/api/users')
     data = json.loads(response.data.decode())
     data_email = data['Users'][0]["email"]
     self.assertEqual(response.status_code, 200)
     self.assertEqual(data_email, self.default_username)
Example #19
0
    def setUp(self):
        self.client = app.test_client()

        self.data = {
            "title": "prank",
            "description": "mayengz"
        }
Example #20
0
def client():
    """ Yields an testing app object.
    """
    app.config['TESTING'] = True

    with app.test_client() as client:
        yield client
Example #21
0
 def test_correct_redirection_after_successful_login_short_username(self):
     tester = app.test_client(self)
     response = tester.post('/home',
                            data=dict(username='******'),
                            follow_redirects=True)
     self.assertIn(b'Field must be between 2 and 25 characters long.',
                   response.data)
Example #22
0
 def test_correct_redirection_after_successful_login_short_password(self):
     tester = app.test_client(self)
     response = tester.post('/home',
                            data=dict(password='******'),
                            follow_redirects=True)
     self.assertIn(b'Field must be between 6 and 30 characters long.',
                   response.data)
Example #23
0
 def test_invalid_login(self):
     tester = app.test_client(self)
     response = tester.post('/home',
                            data=dict(username="******", password='******'),
                            follow_redirects=True)
     self.assertIn(b'Login failed. Check username and password',
                   response.data)
Example #24
0
    def test_post_incorrect_answer_and_have_one_less_attempt(self):
        """ 
       Test 9. Test that a incorrect answer will redirect to the same page with one less attempt.
        """
        data = dict(answer="today")

        with app.test_client(self) as client:
            with client.session_transaction() as session:
                session['score'] = 0
                session['page_number'] = 0
                session['message_display_number'] = 0
                session['display_points'] = 0
                session['last_incorrect_answer'] = ""

            response1 = client.get('/conundrum/user', content_type='html/text')
            self.assertEqual(response1.status_code, 200)
            self.assertIn('Attempts Left:</b> 5', str(response1.data))
            self.assertIn('0 points', str(response1.data))

            response2 = client.post('/conundrum/user',
                                    content_type='multipart/form-data',
                                    data=data)
            self.assertEqual(response2.status_code, 302)

            response3 = client.get('/conundrum/user', content_type='html/text')
            self.assertEqual(response3.status_code, 200)
            self.assertIn('Attempts Left:</b> 4', str(response3.data))
            self.assertNotIn('Attempts Left:</b> 5', str(response3.data))
            self.assertIn('0 points', str(response3.data))
Example #25
0
    def test_user_score_on_the_leaderboard(self):
        """ 
       Test 10. Test that the users score reaches the leaderbored. This test should be a result of 90 out of 100 
       however, this test recognises the incorrect answer from the last test
        """
        data = dict(answer="Skull")

        with app.test_client(self) as client:
            with client.session_transaction() as session:
                session['score'] = 80
                session['page_number'] = 9
                session['message_display_number'] = 0
                session['display_points'] = 0
                session['last_incorrect_answer'] = ""

            response1 = client.get('/conundrum/user', content_type='html/text')
            self.assertEqual(response1.status_code, 200)
            self.assertIn("Question 10 of 10", str(response1.data))
            self.assertIn('80 points', str(response1.data))

            response2 = client.post('/conundrum/user',
                                    content_type='multipart/form-data',
                                    data=data)
            self.assertEqual(response2.status_code, 302)
            self.assertIn('/conundrum/leaderboard/user', response2.location)

            response3 = client.get('/conundrum/leaderboard/user',
                                   content_type='html/text')
            self.assertEqual(response3.status_code, 200)
            self.assertIn("your score is:  88 out of 100", str(response3.data))
Example #26
0
 def test_login_correct(self):
     tester = app.test_client(self)
     response = tester.post('/login',
                            data=dict(email='*****@*****.**',
                                      password='******'),
                            follow_redirects=True)
     self.assertEqual(response.status_code, 200)
Example #27
0
 def test_successful_login(self):
     self.SetUp()
     tester = app.test_client(self)
     response = tester.post('/api/login',
                            headers={'Authorization': self.auth})
     data = json.loads(response.data.decode())
     self.assertTrue("token" in data.keys())
def test_get_delegate():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.get('/delegate/example.com/test.user')
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/example.com/test.user/delegation' in html
def test_home_oauth_redirect():
    app.config['TESTING'] = False
    test_client = app.test_client()
    rsp = test_client.get('/')
    assert rsp.status == '302 FOUND'
    html = rsp.get_data(as_text=True)
    assert '<a href="/oauth2callback">/oauth2callback</a>' in html
Example #30
0
    def setUp(self):
        """ Create test database and set up test client """
        self.app = app.test_client()
        db.create_all()
        user = User(username="******", password="******")
        bucketlist1 = Bucketlist(title="Knowledge Goals",
                                 description="Things to learn",
                                 created_by=1)
        bucketlist2 = Bucketlist(title="Adventures",
                                 description="Awesome adventures to go on",
                                 created_by=1)
        item1 = Item(title="Learn to Cook",
                     description="Cook at least 10 different meals",
                     created_by=1,
                     bucketlist_id=1)
        item2 = Item(title="Swim with Dolphins",
                     description="Go swimming with dolphins in Watamu",
                     created_by=1,
                     bucketlist_id=2)

        db.session.add(user)
        db.session.add(bucketlist1)
        db.session.add(bucketlist2)
        db.session.add(item1)
        db.session.add(item2)
        db.session.commit()
def test_error():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.get('/error/TEST')
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert '<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> TEST' in html
 def setUp(self):
     self.tb = testbed.Testbed()
     self.tb.activate()
     self.tb.setup_env(USER_EMAIL='*****@*****.**', USER_ID='1', USER_IS_ADMIN='0', overwrite=True)
     self.tb.init_user_stub()
     self.tb.init_datastore_v3_stub()
     self.tb.init_memcache_stub()
     self.tc = app.test_client()
Example #33
0
def client():
    app.config['TESTING'] = True
    client = app.test_client()

    with app.app_context():
        create_tables()

    yield client
Example #34
0
    def setUpClass(cls):
        base_dir = os.path.dirname(os.path.abspath(__file__))
        with open(os.path.join(base_dir, 'logging.json'), 'rt') as f:
            config = json.load(f)
        logging.config.dictConfig(config)

        app.config['TESTING'] = True
        cls.client = app.test_client()
Example #35
0
  def test_clouds(self):
    tester = app.test_client(self)

    response = tester.get('/clouds.json', content_type='application/json')

    self.assertEqual(response.status_code, 200)
    self.assertEqual(response.data, json.dumps(['Altocumulus', 'Altostratus',
      'Cumulonimbus', 'Nimbostratus']))
Example #36
0
 def test_index_data(self):
     tester = app.test_client(self)
     response = tester.post(
         '/post',
         data=json.dumps({'repository_name': ["danistefanovic/build-your-own-x"]}),
         content_type='application/json',
     )
     self.assertTrue(b'Stargazer Count' in response.data)
def test_add_delegate():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.post('/delegateto/example.com/danger', data={'newdelegate': 'test.use'})
    assert rsp.status == '302 FOUND'
    html = rsp.get_data(as_text=True)
    assert '<a href="/errgetdelegate/example.com/danger/Not%20a%20valid%20email%20address">/errgetdelegate/example.com/danger/Not%20a%20valid%20email%20address</a>' in html
    rsp = test_client.post('/delegateto/example.com/danger', data={'newdelegate': '*****@*****.**'})
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert 'https://apps-apis.google.com/a/feeds/emailsettings' in html
def test_search():
    app.config['TESTING'] = True
    test_client = app.test_client()
    rsp = test_client.post('/search', data={'finddelegate': '*****@*****.**'})
    assert rsp.status == '302 FOUND'
    html = rsp.get_data(as_text=True)
    assert '<a href="/delegate/example.com/test.user">' in html
    rsp = test_client.post('/search', data={'finddelegate': 'test.use'})
    assert rsp.status == '200 OK'
    html = rsp.get_data(as_text=True)
    assert 'Not a valid email address!' in html
Example #39
0
    def setUp(self):
        self.app = app.test_client()

        app.config['SQLALCHEMY_DATABASE_URI'] = \
            'postgresql+psycopg2://%(username)s:%(password)s@localhost/%(database_name)s' % {
                'username': Config.DB_USER,
                'password': Config.DB_PASSWORD,
                'database_name': Config.TEST_DATABASE_URI
            }
        app.config['TESTING'] = True

        db.create_all()
Example #40
0
import unittest
Example #41
0
 def setUp(self):
     app.config.from_object('config.TestConfig')
     init_db()
     self.client = app.test_client()
Example #42
0
 def setUp(self):
     app.config['WTF_CSRF_ENABLED'] = False
     self.app = app.test_client()
Example #43
0
	def setUp(self):
		self.tester = app.test_client(self)
 def setUpClass(cls):
     flask_app.debug = True
     cls.app_client = flask_app.test_client()
 def setUp(self):
     app.config['DEBUG'] = True
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.service_url = jsonrpc.service_url
Example #46
0
 def setUp(self):
     self.app = app.test_client()