예제 #1
0
def flask_client(context, *args, **kwargs):
    # context.db, app.config['DATABASE'] = tempfile.mkstemp()
    app.testing = True
    context.client = app.test_client()
    # with app.app_context():
    #     init_db()
    yield context.client
예제 #2
0
 def test_get_all_entries(self):
     self.tester = app.test_client(self)
     self.api_route= 'mydiary/api/v1/entries'
     response = self.tester.get(self.api_route)
     self.assertEqual(response.status_code, 200)
     self.assertIn("movies", str(response.data))
     self.assertIn('application/json', str(response.headers))
예제 #3
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['MONGODB_DB'] = TEST_DB
     self.app = app.test_client()
     self.collection = 'clients'
     self.api_url = 'http://{host}:{port}/clients/'.format(host=SERVER_HOST,
                                                           port=SERVER_PORT)
def client():
    app.config['UPLOAD_FOLDER'] = os.getenv('UPLOAD_DIRECTORY',
                                            'app/persistent/')
    create_directory(app.config['UPLOAD_FOLDER'])
    app.config['TESTING'] = True
    client = app.test_client()
    return client
예제 #5
0
    def test_wav_to_mp3_sampling_rate(self):
        cli = app.test_client()
        with open('./tests/assets/test.wav', 'rb') as f:
            r = cli.post('/wav_to_mp3',
                         content_type='multipart/form-data',
                         data={
                             'wav': f,
                             'bitrate': '16k'
                         },
                         buffered=True)

            self.assertEqual(200, r.status_code)
            default_bitrate_data_size = len(r.data)

        with open('./tests/assets/test.wav', 'rb') as f:
            r = cli.post('/wav_to_mp3',
                         content_type='multipart/form-data',
                         data={
                             'wav': f,
                             'bitrate': '16k',
                             'sampling_rate': '24000',
                             'sample_fmt': 'flt'
                         },
                         buffered=True)

            self.assertEqual(200, r.status_code)
            higher_bitrate_data_size = len(r.data)

        self.assertTrue(default_bitrate_data_size != higher_bitrate_data_size)
def test_view_scores_ctl():
    tester = app.test_client()
    response = tester.post('/scores',
                           data={'groupname': 'ctl'},
                           follow_redirects=True)
    assert response.status_code == 200
    assert 'TomT Score' in str(response.data)
예제 #7
0
 def test_explore_data(self):
     with app.test_client() as c:
         req = requests.Request
         req.data = '{"compound_name": "Atorvastatin"}'
         resp = c.get('/data/explore')
         self.assertEqual(resp.status_code, 200)
         self.assertEqual(resp.default_mimetype, 'text/html')
예제 #8
0
 def setUp(self):
     app.config[
         'SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost:5432/postgres'
     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
     with app.app_context():
         db.init_app(app)
     self.app = app.test_client()
     self.app_context = app.app_context
예제 #9
0
 def test_entry_update(self):
    self.tester = app.test_client(self)
    self.api_route= 'mydiary/api/v1/entries/1'
    self.entry_update= {'title':'school','content':'today school was amaizing'}
    response = self.tester.put(self.api_route,data=json.dumps(self.entry_update),
    content_type="application/json")
    self.assertEqual(response.status_code, 200)
    self.assertIn("school", str(response.data))
예제 #10
0
 def test_entry_post(self):
    self.tester = app.test_client(self)
    self.api_route= 'mydiary/api/v1/entries'
    self.payload = {'title':'beach','content':'today i had fun at the beach',"date": '12-8-2018'}
    response = self.tester.post(self.api_route,data=json.dumps(self.payload),
    content_type="application/json")
    self.assertEquals(response.status_code,201)
    self.assertIn("beach", str(response.data))
예제 #11
0
    def setUp(self):
        app.config.update(TESTING=True)
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()

        db.create_all()
        db.session.commit()
예제 #12
0
    def test_merge_out_wav(self):
        cli = app.test_client()
        r = cli.post('/merge?out=wav', content_type='multipart/form-data', data=self.data, buffered=True)
        assert 200 == r.status_code
        self.assertEqual(b'RIFF', r.data[:4])

        audio_size = len(r.data)
        assert self.expected_lower_bound <= audio_size
        assert self.expected_upper_bound >= audio_size
예제 #13
0
 def setUp(self):
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///aafood-test.db'
     app.config['TESTING'] = True
     self.app = app.test_client()
     with app.app_context():
         db.init_app(app)
         db.create_all()
         q = len(Term.query.all())
         print(q)
예제 #14
0
    def test_wav_to_ogg(self):
        cli = app.test_client()
        with open('./tests/assets/test.wav', 'rb') as f:
            r = cli.post('/wav_to_ogg', content_type='multipart/form-data', data={
                'wav': f
            }, buffered=True)

            self.assertEqual(200, r.status_code)
            self.assertEqual(b'OggS', r.data[:4])
def test_incorrect_group_name_flash_message():
    tester = app.test_client()
    response = tester.post('/scores', data={'groupname': 'fakeName'})
    with tester.session_transaction() as session:
        flash_message = dict(session['_flashes']).get('invalid group')

    assert response.status_code == 302
    assert flash_message is not None
    assert flash_message == 'No group with this name!'
예제 #16
0
 def setUp(self):
     """
     The initial app configuration
     :return: app
     """
     DB['*****@*****.**'] = 'test_password'
     self.app = app.test_client()
     with self.app as app_:
         with app_.session_transaction() as sess:
             sess['user'] = '******'
예제 #17
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = POSTGRESQL_TEST_DB
     self.app = app.test_client()
     db.drop_all()
     db.get_engine(app).connect().execute(
         'DROP FUNCTION IF EXISTS post_search_vector_update();')
     db.create_all()
     self._populate_db_with_users()
예제 #18
0
 def setUp(self):
     app.config['TESTING'] = True
     self.client = app.test_client()
     self.ride_offers = [
         ride.Ride("Isaac", "Mpererwe", "Kamwokya", 10000),
         ride.Ride("Rose", "Kampala Road", "Mpererwe", 15000),
         ride.Ride("Catherine", "Ibanda", "Kampala", 50000),
         ride.Ride("Anita", "Entebbe", "Kampala", 20000)
     ]
     rides.extend(self.ride_offers)
예제 #19
0
    def setUp(self):
        self.app = app.test_client()
        with self.app as app_:
            with app_.session_transaction() as sess:
                sess['user'] = '******'

        DB['activities'] = [
            {'user': '******', 'description': 'Test activity',
             'created': datetime.date(2017, 7, 19),
             'activity_key': '11111111', 'key': '00000000'}
        ]
예제 #20
0
    def test_wav_to_mp3_with_silence(self):
        cli = app.test_client()
        with open('./tests/assets/test.wav', 'rb') as f:
            r = cli.post('/wav_to_mp3', content_type='multipart/form-data', data={
                'wav': f,
                'silence': '5',
            }, buffered=True)

            self.assertEqual(200, r.status_code)
            self.assertEqual(b'ID3', r.data[:3])
            audio= BytesIO(r.data)
            duration = MP3(audio).info.length
            self.assertTrue(5 < duration)
예제 #21
0
 def setUp(self):
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///aafood-test.db'
     app.config['REDIS_URL'] = 'redis://localhost:6379/30'
     app.config['TESTING'] = True
     self.app = app.test_client()
     with app.app_context():
         db.init_app(app)
         if os.path.exists('app/aafood.db') == True:
             #TODO: 未來的 DB 從 production 複製過去
             shutil.copyfile('app/aafood.db', 'app/aafood-test.db')
         if os.path.exists("app/aafood-test.db") == False:
             db.create_all()
             add_data()
         redis_store.init_app(app)
예제 #22
0
def client():
    file_level_handle, TEST_DB_PATH = tempfile.mkstemp(suffix='.db',
                                                       prefix='test_db')
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + TEST_DB_PATH

    db.init_app(app)

    with app.test_client() as client:
        with app.app_context():
            db.create_all()
        yield client

    os.close(file_level_handle)
    print('TEST DB PATH', TEST_DB_PATH)
    os.unlink(TEST_DB_PATH)
 def test_data_explore_with_download(self):
     with app.test_client() as c:
         # create a sample request
         request = PayloadRequest()
         request.export = "true"
         request.join_style = "inner"
         request.single_file = "false"
         request.limit = 25
         datalist = DataList()
         datalist.view_name = "compounds"
         datalist.column_list = ["drug_id"]
         datalist.filters = []
         request.data_list = [datalist]
         resp = c.post('/data/explore', data=request.to_json(), content_type='application/json')
         self.assertEqual(resp.status_code, 200)
         self.assertGreater(len(resp.get_data()), 0)
예제 #24
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['DEBUG'] = False
     app.config[
         'SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format(
             user="******",
             pw="admin",
             url="127.0.0.1:5432",
             db="cryptocartera-test")
     self.app = app.test_client()
     with app.app_context():
         # db.drop_all()
         db.create_all()
         moneda = Moneda(moneda="BTC")
         db.session.add(moneda)
         db.session.commit()
예제 #25
0
 def setUp(self, random_climatics_patched):
     self.app = app.test_client()
     self.year = datetime.utcnow().year
     self.payload = {
         'São Paulo': {
             str(self.year): {
                 '{}-01-01'.format(self.year): 'Cold',
                 '{}-01-02'.format(self.year): 'Partly Cloudy',
                 '{}-01-03'.format(self.year): 'Cold',
                 '{}-01-04'.format(self.year): 'Cold',
                 '{}-01-05'.format(self.year): 'Hot',
             }
         },
         'Rio de Janeiro': {
             str(self.year): {
                 '{}-01-01'.format(self.year): 'Partly Cloudy',
                 '{}-01-02'.format(self.year): 'Cold',
                 '{}-01-03'.format(self.year): 'Hot',
                 '{}-01-04'.format(self.year): 'Fair',
                 '{}-01-05'.format(self.year): 'Cold'
             }
         },
         'Porto Alegre': {
             str(self.year): {
                 '{}-01-01'.format(self.year): 'Partly Cloudy',
                 '{}-01-02'.format(self.year): 'Cold',
                 '{}-01-03'.format(self.year): 'Hot',
                 '{}-01-04'.format(self.year): 'Fair',
                 '{}-01-05'.format(self.year): 'Fair'
             }
         },
         'Pernambuco': {
             str(self.year): {
                 '{}-01-01'.format(self.year): 'Hot',
                 '{}-01-02'.format(self.year): 'Hot',
                 '{}-01-03'.format(self.year): 'Hot',
                 '{}-01-04'.format(self.year): 'Hot',
                 '{}-01-05'.format(self.year): 'Hot'
             }
         }}
     random_climatics_patched.return_value = self.payload
     self.city_id = 1
     self.random_climatics = RandomClimaticsConditions(self.year)
     self.random_climatics.save_dicit_with_random_climatics_conditions_in_a_file()
 def test_data_explore_filters_and_export(self):
     with app.test_client() as c:
         # create a sample request
         request = PayloadRequest()
         request.export = "true"
         request.single_file = "true"
         request.join_style = "inner"
         request.limit = 25
         datalist = DataList()
         datalist.view_name = "compounds"
         datalist.column_list = ["atc_level_4"]
         filter_object = Filter()
         filter_object.column_name = "atc_level_4"
         filter_object.operator = "matches"
         filter_object.target = "RESPIRATORY SYSTEM"
         datalist.filters = [filter_object]
         request.data_list = [datalist]
         resp = c.post('/data/explore', data=request.to_json(), content_type='application/json')
         self.assertEqual(resp.status_code, 200)
         self.assertGreater(len(resp.get_data()), 0)
    def test_merge_out_mp3_tempo(self):
        cli = app.test_client()

        data = self._load_data(tempo=1.0)
        r = cli.post('/merge?out=mp3',
                     content_type='multipart/form-data',
                     data=data,
                     buffered=True)
        assert 200 == r.status_code
        len1 = MP3(BytesIO(r.data)).info.length
        # assert b'ID3' == r.data[:3]

        data = self._load_data(tempo=1.3)
        r = cli.post('/merge?out=mp3',
                     content_type='multipart/form-data',
                     data=data,
                     buffered=True)
        assert 200 == r.status_code
        # assert b'ID3' == r.data[:3]
        len2 = MP3(BytesIO(r.data)).info.length
        assert len1 > len2 * 1.25
예제 #28
0
 def setUp(self):
     self.app = app.test_client()
     self.app.testing = True
예제 #29
0
def client():
    app.config["TESTING"] = True
    with app.test_client() as client:
        yield client
예제 #30
0
def test_login(client):
    response = app.test_client().get("/")
    assert response.status_code == 200
예제 #31
0
 def setUp(self):
     self.app = app.test_client()
     self.app.testing = True
예제 #32
0
 def setUp(self):
     # Clear entry in the database
     setupDatabase()
     app.config.from_object('config.TestingConfig')
     self.app = app.test_client()
     self.register_user()
예제 #33
0
 def setUp(self):
     app.config.from_object('config.TestingConfig')
     self.app = app.test_client()
예제 #34
0
 def setUp(self):
     self.cliente = app.test_client()