Ejemplo n.º 1
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['CSRF_ENABLED'] = False
     #app.config['SECRET_KEY'] = 'my_precious'
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
     self.app = app.test_client()
     db.create_all()
Ejemplo n.º 2
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
         os.path.join(basedir, TEST_DB)
     self.app = app.test_client()
     db.create_all()
Ejemplo n.º 3
0
 def test_post_show_up(self):
     tester = app.test_client(self)
     response = tester.post(
             '/login',
             data = dict(username="******", password="******"),
             follow_redirects = True
     )
     self.assertIn(b'Hello from the shell', response.data)
Ejemplo n.º 4
0
 def test_correct_login(self):
     tester = app.test_client(self)
     response = tester.post(
             '/login', 
             data = dict(username="******", password="******"),
             follow_redirects = True
     )
     self.assertIn(b'You were logged in.', response.data)
Ejemplo n.º 5
0
 def test_logout(self):
     tester = app.test_client(self)
     tester.post('/login', 
         data=dict(username='******',password='******'), 
         follow_redirects=True
         )
     response = tester.get('/logout', follow_redirects=True)
     self.assertIn(b'You were just logged out', response.data)
Ejemplo n.º 6
0
 def setUp(self):
     # executes prior to each test
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + TEST_DB
     app.config['DEBUG'] = False
     self.app = app.test_client()
     db.create_all()
 def setUp(self):
   app.config['TESTING'] = True
   app.config['WTF_CSRF_ENABLED'] = False
   app.config['DEBUG'] = False
   app.config['SQLALCHEMY_DATABASE_PATH'] = 'sqlite:///' + os.path.join(basedir, TEST_DB)
   self.app = app.test_client()
   db.create_all()
   self.assertEquals(app.debug, False)
Ejemplo n.º 8
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
        os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
Ejemplo n.º 9
0
 def test_incorrect_login(self):
     tester = app.test_client(self)
     response = tester.post(
             '/login', 
             data = dict(username="******", password="******"),
             follow_redirects = True
     )
     self.assertIn(b'Invalid Credentials', response.data)
Ejemplo n.º 10
0
 def setUp(self):
     app.config.from_object('config.TestConfig')
     self.client = app.test_client()
     db.create_all()
     user = User("admin", "*****@*****.**", "admin")
     db.session.add(user)
     db.session.add(
         BlogPosts("Test post", "This is a test. Only a test.", user.id))
     db.session.commit()
Ejemplo n.º 11
0
    def setUp(self):
        app.config["TESTING"] = True
        app.config["WTF_CSRF_ENABLED"] = False
        app.config["DEBUG"] = False
        app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
Ejemplo n.º 12
0
def app():
    """session wide Flask application"""
    settings_override = {
        'DEBUG': False,
        'TESTING': True,
        'WTF_CSRF_ENABLED': False,
        'SQLALCHEMY_DATABASE_URI': TEST_DB_URI
    }
    _app.config.from_object(settings_override)
    return _app.test_client()
def app():
    """session wide Flask application"""
    settings_override = {
        'DEBUG': False,
        'TESTING': True,
        'WTF_CSRF_ENABLED': False,
        'SQLALCHEMY_DATABASE_URI': TEST_DB_URI
    }
    _app.config.from_object(settings_override)
    return _app.test_client()
Ejemplo n.º 14
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite'
        self.app = app.test_client()
        db.drop_all()
        db.create_all()

        self.assertEqual(app.debug, False)
Ejemplo n.º 15
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
Ejemplo n.º 16
0
  def setUp(self):
    app.config["TESTING"] = True
    # VERY IMPORTANT TO DISABLE!!!
    app.config["WTF_CSRF_ENABLED"] = False
    app.config["DEBUG"] = False
    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, TEST_DB)
    self.app = app.test_client()
    db.create_all()

    self.assertEqual(app.debug, False)
Ejemplo n.º 17
0
    def setUp(self):
        """
            Executing prior to each tasks.
            Create environnement where tests while be executing.
        """
        app.config.from_object('project._config.TestConfig')
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
Ejemplo n.º 18
0
 def test_post_invalid_position(self):
     tester = app.test_client(self)
     res = self.app.post('/api/v1/applicants',
                         data=json.dumps(
                             dict(school='VCU',
                                  position='cat caller',
                                  degree='eyesight')),
                         content_type='application/json',
                         follow_redirects=True)
     self.assertEqual(res.status_code, 400)
Ejemplo n.º 19
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['DEBUG'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
         os.path.join(app.config['BASEDIR'], TEST_DB)
     self.app = app.test_client()
     with app.app_context():
         db.create_all()
     mail.init_app(app)
     self.assertEquals(app.debug, False)
Ejemplo n.º 20
0
    def setUp(self):
        """Executed prior to each test."""
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
 def setUp(self):
     """
         Executing prior to each tasks.
         Create environnement where tests while be executing.
     """
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
                                             os.path.join(basedir, TEST_DB)
     self.app = app.test_client()
     db.create_all()
Ejemplo n.º 22
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/test'
        self.app = app.test_client()
        db.drop_all()
        db.create_all()

        mail.init_app(app)
        self.assertEqual(app.debug, False)
Ejemplo n.º 23
0
 def test_post_app1(self):
     tester = app.test_client(self)
     res = self.app.post('/api/v1/applicants',
                         data=json.dumps(
                             dict(first_name='bar',
                                  last_name="Kirtfield",
                                  school='VCU',
                                  position='dev intern',
                                  degree='eyesight')),
                         content_type='application/json',
                         follow_redirects=True)
     self.assertEqual(res.status_code, 201)
Ejemplo n.º 24
0
 def test_wrong_method_put_in_get(self):
     tester = app.test_client(self)
     res = self.app.put('/api/v1/applicants',
                        data=json.dumps(
                            dict(first_name='bar',
                                 last_name="Kirtfield",
                                 school='VCU',
                                 position='dev engineer',
                                 degree='eyesight')),
                        content_type='application/json',
                        follow_redirects=True)
     self.assertEqual(res.status_code, 405)
Ejemplo n.º 25
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite'
        self.app = app.test_client()
        db.drop_all()
        db.create_all()

        # Disable sending emails during unit testing
        ma.init_app(app)
        self.assertEqual(app.debug, False)
Ejemplo n.º 26
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
            'testcode-db.db')
        self.app = app.test_client()
        db.drop_all()
        db.create_all()

        mail.init_app(app)
        self.assertEqual(app.debug, False)
Ejemplo n.º 27
0
def test_post_route__failure__bad_request():
    client = app.test_client()
    url = '/post/test'

    mock_request_headers = {'authorization-sha256': '123'}

    mock_request_data = {}

    response = client.post(url,
                           data=json.dumps(mock_request_data),
                           headers=mock_request_headers)
    assert response.status_code == 400
Ejemplo n.º 28
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
            basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)

        register(self, 'Michael', '*****@*****.**', 'python', 'python')
Ejemplo n.º 29
0
    def setUp(self):
        self.app.config['TESTING'] = True
        self.app.config['WTF_CSRF_ENABLED'] = False
        self.app.config[
            'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
                basedir, self.TEST_DB)
        self.app.config['DEBUG'] = False
        self.app = app.test_client()
        self.db.create_all()

        self.assertEquals(app.config['DEBUG'],
                          False,
                          msg='App cannot run in production with debug mode.')
Ejemplo n.º 30
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['MONGO_URI'] = 'monogodb://localhost' + \
            os.path.join(app.config['BASEDIR'], TEST_DB)
        self.app = app.test_client()
        db.drop_all()
        db.create_all()
 

        mail.init_app(app)
        self.assertEqual(app.debug, False)
Ejemplo n.º 31
0
    def setUp(self):
        """Set up."""
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        # Make sure we are testing in production mode

        self.assertEquals(app.debug, False)
Ejemplo n.º 32
0
	def setUp(self):
		app.config['TESTING'] = True
		app.config['WTF_CSRF_ENABLED'] = False
		app.config['DEBUG'] = False
		app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + \
			os.path.join(basedir, TEST_DB)
		self.app = app.test_client()
		db.create_all()

		self.assertEqual(app.debug, False)

		self.register('michael', '*****@*****.**', 'michaelherman', 'michaelherman')
		self.login('michael', 'michaelherman')
Ejemplo n.º 33
0
    def setUp(self):
        """TODO: Docstring for setup.
        :returns: TODO

        """
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(BASE_DIR, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
Ejemplo n.º 34
0
 def testUpdateUser3(self):
     with app.test_client() as client:
         data = {
             "uid": "111111BE8m70phdEeRtvjN38bNGEDfhHV2",
             "email": "*****@*****.**",
             "dob": "1998-10-18",
             "fullname": "Hiếu Lương",
             "is_vegetarian": False,
             "avatar": "https://graph.facebook.com/1332042503669281/picture"
         }
         res = client.put(DEFAULT_PATH.format('/user'),
                          data=json.dumps(data),
                          headers=AUTH_HEADERS)
         self.assertEqual(402, res.status_code)
Ejemplo n.º 35
0
    def setUp(self):
        # 更新配置
        app.config.update(TESTING=True,
                          SQLALCHEMY_DATABASE_URL='sqlte:///:memory:')

        db.create_all()
        user = User(username='******', name='Test')
        user.set_password('123456')
        movie = Movie(title='test mvoie', year='2020')

        db.session.add_all([user, movie])
        db.session.commit()

        self.client = app.test_client()  # 测试客户端
        self.runner = app.test_cli_runner()  # 创建测试命令运行器
Ejemplo n.º 36
0
 def testRatingSurvey1(self):
     with app.test_client() as client:
         data = {
             "rating": [{
                 "meta_tag_id": 1,
                 "tag_ids": [4221, 4503]
             }, {
                 "meta_tag_id": 2,
                 "tag_ids": [4222, 4224]
             }]
         }
         res = client.post(DEFAULT_PATH.format('/rating'),
                           data=json.dumps(data),
                           headers=AUTH_HEADERS)
         self.assertEqual(201, res.status_code)
Ejemplo n.º 37
0
    def setUp(self):
        """
            Executing prior to each tasks.
            Create environnement where tests while be executing.
            Start server without the debug mode.
        """
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
                                                os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
Ejemplo n.º 38
0
def client():
    db_fd, app.config['DATABASE'] = tempfile.mkstemp()
    app.config['TESTING'] = True
    client = app.test_client()

    with app.app_context():
        # Drop all of the existing database tables
        db.drop_all()
        # create the database and the database table
        db.create_all()

    yield client

    print("client end")
    os.close(db_fd)
    os.unlink(app.config['DATABASE'])
Ejemplo n.º 39
0
    def setUp(self):
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
        self.app = app.test_client()
        db.create_all()

        game1 = game_info(game_name="test1_name",
                          game_description="test1_desc",
                          user="******",
                          Tickets=1)
        game2 = game_info(game_name="test2_name",
                          game_description="test2_desc",
                          user="******",
                          Tickets=2)

        db.session.add(game1)
        db.session.add(game2)
        db.session.commit()
Ejemplo n.º 40
0
def app(request):
    # `TESTING` set to True, `DEBUG` to False,
    # `SQLALCHEMY_DATABASE_URI` leading to testing postgres database
    _app.config.from_pyfile('testing_config.py')
    # Not using SQLite for testing, because there are problems with
    # summing timedelta.

    test_client = _app.test_client()

    ctx = _app.app_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return test_client
Ejemplo n.º 41
0
def test_post_route__success():
    client = app.test_client()
    url = '/post/test'

    mock_request_headers = {'authorization-sha256': '123'}

    mock_request_data = {
        'request_id': '123',
        'payload': {
            'py': 'pi',
            'java': 'script'
        }
    }

    response = client.post(url,
                           data=json.dumps(mock_request_data),
                           headers=mock_request_headers)
    assert response.status_code == 200
Ejemplo n.º 42
0
def test_post_route__failure__unauthorized():
    client = app.test_client()
    url = '/post/test'

    mock_request_headers = {}

    mock_request_data = {
        'request_id': '123',
        'payload': {
            'py': 'pi',
            'java': 'script'
        }
    }

    response = client.post(url,
                           data=json.dumps(mock_request_data),
                           headers=mock_request_headers)
    assert response.status_code == 401
Ejemplo n.º 43
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['DEBUG'] = False
     # app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
     #     os.path.join(app.config['BASEDIR'], TEST_DB)
     self.app = app.test_client()
     self.app.post('/api/v1/applicants',
                   data=json.dumps(
                       dict(first_name='bar',
                            last_name="Kirtfield",
                            school='VCU',
                            position='dev intern',
                            degree='eyesight')),
                   content_type='application/json',
                   follow_redirects=True)
     self.app.post('/api/v1/applicants',
                   data=json.dumps(
                       dict(first_name='Ryan',
                            last_name="Kirtfield",
                            school='Penn State',
                            position='dev intern',
                            degree='mathematics')),
                   content_type='application/json',
                   follow_redirects=True)
     self.app.post('/api/v1/applicants',
                   data=json.dumps(
                       dict(first_name='Little',
                            last_name="John",
                            school='VT',
                            position='dev intern',
                            degree='Health')),
                   content_type='application/json',
                   follow_redirects=True)
     self.app.post('/api/v1/applicants',
                   data=json.dumps(
                       dict(first_name='Lion',
                            last_name="Welsh",
                            school='Harvard',
                            position='dev intern',
                            degree='good')),
                   content_type='application/json',
                   follow_redirects=True)
Ejemplo n.º 44
0
    def setUp(self) -> None:
        """ Setup method that runs before each test """
        # Overriding flask app settings
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['WTF_CSRF_CHECK_DEFAULT'] = False

        # Using local sqlite db instead of the one used in the project
        db_path = os.path.join(basedir, 'tests', 'db_test.sqlite')
        if os.path.exists(db_path):
            os.remove(db_path)

        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_path

        db.create_all()
        populate_departments()
        populate_employees()

        # Creating client for making requests
        self.client = app.test_client()
Ejemplo n.º 45
0
 def test_add_recipe(self):
     self.register_user()
     app_client = app.test_client()
     app_client.post('/register',
                     data=dict(email='*****@*****.**', password='******', confirm='FlaskIsAwesome'),
                     follow_redirects=True)
     app_client.post('/login',
                     data=dict(email='*****@*****.**', password='******'),
                     follow_redirects=True)
     response = app_client.post('/add',
                                buffered=True,
                                content_type='multipart/form-data',
                                data={'recipe_title': 'Local Dev2',
                                      'recipe_description': 'Setup Dev Laptop With Ease',
                                      'recipe_type': 'Ops',
                                      'recipe_steps': 'Step 1 Step 2 Step 3',
                                      'recipe_ingredients': 'Bits & Bytes',
                                      'recipe_inspiration': 'http://www.redhat.com/',
                                      'recipe_image': (BytesIO(b'my file contents'), 'image001.jpg')},
                                follow_redirects=True)
     self.assertIn(b'New recipe, Local Dev2, added!', response.data)
Ejemplo n.º 46
0
 def test_edit_recipe_fields(self):
     self.add_recipes()
     app_client = app.test_client()
     app_client.post('/login',
                     data=dict(email='*****@*****.**',
                               password='******'),
                     follow_redirects=True)
     response = app_client.get('/edit/3', follow_redirects=True)
     self.assertIn(b'Edit Recipe', response.data)
     self.assertIn(b'Tacos', response.data)
     response = app_client.post('/edit/3',
                                buffered=True,
                                content_type='multipart/form-data',
                                data={
                                    'recipe_title':
                                    'Tacos2',
                                    'recipe_description':
                                    'Ground beef tacos',
                                    'recipe_type':
                                    'Lunch',
                                    'recipe_public':
                                    'True',
                                    'recipe_rating':
                                    '8',
                                    'recipe_steps':
                                    'Step 1 Step 2 Step 3',
                                    'recipe_ingredients':
                                    'Ingredient #1 Ingredient #2',
                                    'recipe_inspiration':
                                    'http://www.foodnetwork.com/blaa',
                                    'recipe_dairy_free':
                                    'True',
                                    'recipe_soy_free':
                                    'True',
                                    'recipe_image':
                                    (BytesIO(b'my file contents'),
                                     'image001.jpg')
                                },
                                follow_redirects=True)
     self.assertIn(b'Recipe has been updated for Tacos2.', response.data)
Ejemplo n.º 47
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['DEBUG'] = False
     self.app = app.test_client()
Ejemplo n.º 48
0
 def test_index(self):
     tester = app.test_client(self)
     response = tester.get('/login', content_type='html/text')
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 49
0
 def testDeleteHistory(self):
     with app.test_client() as client:
         res = client.delete(DEFAULT_PATH.format('/history/10'),
                             headers=AUTH_HEADERS)
         self.assertEqual(401, res.status_code)