Beispiel #1
0
    def test_get_notfound(self):

        self.test_app = app.test_client()

        response = self.test_app.get('/12b07c79-92e1-4e6b-a4b7-49dd2bdba9a3', content_type='application/json')

        self.assertEqual(response.status_code, 404)
Beispiel #2
0
 def setUp(self):
     """
     Setup app and database before test suite
     """
     self.app = app.test_client()
     db = connect("bowlingdb")
     db.drop_database("bowlingdb")
Beispiel #3
0
    def test_get_found(self):

        self.test_app = app.test_client()

        response = self.test_app.get('/ebddbb7d-29f3-4cb8-877f-313d1d6e296f', content_type='application/json')

        self.assertEqual(response.status_code, 200)
        self.assertIsNotNone(response.data)
Beispiel #4
0
 def setUpClass(cls):
     os.environ['TESTING'] = 'true'
     from api import app, db
     cls.app = app.test_client()
     db.create_all()
     # add default user
     db.session.add(User(email='*****@*****.**', name='tests', password=pw_hash('password1234'), token='THISISTESTTOKEN'))
     db.session.commit()
Beispiel #5
0
    def test_index(self):

        self.test_app = app.test_client()

        response = self.test_app.get('/', content_type='application/json')

        self.assertEqual(response.status_code, 200)

        self.assertIsNotNone(response.data)
Beispiel #6
0
 def setUp(self):
     self.app = app.test_client()
     self.pair = dict(
         date="2000-01-01 12:00:00",
         rte="193",
         dir="0",
         on_stop="10764",
         off_stop="10770",
         user_id="testuser"
     )
Beispiel #7
0
    def setUp(self):
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        app.config['TESTING'] = True
        self.client = app.test_client()
        db.create_all()

        global satshabad
        global fateh
        satshabad = fixtures.make_user("satshabad")
        fateh = fixtures.make_user("fateh")
Beispiel #8
0
    def test_post(self):

        self.test_app = app.test_client()

        data = {}
        data['key'] = ''
        data['value'] = 'value'

        response = self.test_app.post('/', content_type='application/json', data=json.dumps(data))

        self.assertEqual(response.status_code, 201)
Beispiel #9
0
    def setUpClass(cls):
        global db
        #store = FilesystemStore('session')
        #KVSessionExtension(store, app)
        
        # Load the debug config
        app.config.from_pyfile('../config.defaults.py')
        app.config.from_pyfile('../config_debug.py')
        app.secret_key = app.config['SECRET_KEY']
        db = Database(app.config)

        cls._setup_database()
        app.testing = True
        cls.app = app.test_client(use_cookies=True)
    def setUp(self):
        self.user = helper.fixture(cls=models.User, persist=True, username=u'root', password='******')
        self.account = helper.fixture(cls=models.Account, persist=True, name='citibank', user=self.user)
        amount = -10.0
        for i in range(10):
            amount = amount - 5
            helper.fixture(cls=models.Transaction, persist=True, user=self.user, account=self.account, amount=amount, transaction_date='2012-10-01')

        # total = -375
        helper.fixture(cls=models.Transaction, persist=True, user=self.user, account=self.account, amount=-25.0, transaction_date='2012-01-01')
        helper.fixture(cls=models.Transaction, persist=True, user=self.user, account=self.account, amount=10.0, transaction_date='2012-01-02')
        helper.fixture(cls=models.Transaction, persist=True, user=self.user, account=self.account, amount=10.0, transaction_date='2012-01-03')
        helper.fixture(cls=models.Transaction, persist=True, user=self.user, account=self.account, amount=-10.0, transaction_date='2012-01-04')
        helper.fixture(cls=models.Transaction, persist=True, user=self.user, account=self.account, amount=-10.0, transaction_date='2012-01-05')

        helper.fixture(cls=models.Transaction, persist=True, user=self.user, account=self.account, amount=-99.9, transaction_date='2011-05-10')
        self.app = app.test_client()
        self.app.post('/api/v1/authentication/login', data='{"username": "******", "password": "******"}', follow_redirects=True)
Beispiel #11
0
    def setUp(self):
        """
        Setup app, database, and create a game before test cases
        """
        self.app = app.test_client()
        db = connect("bowlingdb")
        db.drop_database("bowlingdb")

        # add a game
        new_players = [
            "Calvin Johnson",
            "Michael Jordan"
        ]
        players = []
        for num, name in enumerate(new_players):
            players.append(Player(player_id=(num + 1), name=name))
        game = Game(players=players)
        game_info = game.save()
        self.valid_id = str(game_info.id)
Beispiel #12
0
 def setUp(self):
     app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
     app.config['TESTING'] = True
     self.app = app.test_client()
     db.create_all()
     tmpzsh = Shell(name='zsh', path='/usr/bin/zsh')
     db.session.add(tmpzsh)
     db.session.commit()
     tmpbash = Shell(name='bash', path='/bin/bash')
     db.session.add(tmpbash)
     db.session.commit()
     tmpAdmin = Access(name='admin', description='Grant SuperUser privileges on host')
     db.session.add(tmpAdmin)
     db.session.commit()
     tmpUser = Access(name='user', description='Normal User Access to host')
     db.session.add(tmpUser)
     db.session.commit()
     tmpGroup = Group(name='WebServers')
     db.session.add(tmpGroup)
     db.session.commit()
Beispiel #13
0
 def setUp(self):
     self.show_results = False
     self.pp = PrettyPrinter(indent=4)
     self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
     self.d = "2014-8-23"
     self.t = "11:37"
     app.config['TESTING'] = True
     self.app = app.test_client()
     DB.engine.execute('''   
                             DROP TABLE IF EXISTS fun;
                             DROP TABLE IF EXISTS roster;
                             DROP TABLE IF EXISTS bat;
                             DROP TABLE IF EXISTS espys;
                             DROP TABLE IF EXISTS game;
                             DROP TABLE IF EXISTS team;
                             DROP TABLE IF EXISTS player;
                             DROP TABLE IF EXISTS sponsor;
                             DROP TABLE IF EXISTS league;
                     ''')
     DB.create_all()
Beispiel #14
0
 def setUp(self):
     self.app = app.test_client()
     uuid = str(uuid4())
     self.on_scan = dict(
         uuid=uuid,
         date="2000-01-01 12:00:00",
         rte="9",
         dir="0",
         lon="-122.5",
         lat="45.5",
         mode="on",
         user_id="testuser"
     )
     self.off_scan = dict(
         uuid=uuid,
         date="2000-01-01 12:30:00",
         rte="9",
         dir="0",
         lon="-122.5",
         lat="45.5",
         mode="off",
         user_id="testuser"
     )
Beispiel #15
0
 def setUp(self):
     # creates a test client
     self.app = app.test_client()
     # propagate the exceptions to the test client
     self.app.testing = True
 def test_index(self):
   response = app.test_client().get('/')
   self.assertEqual(response.status_code, 200)
Beispiel #17
0
 def setUp(self):
     #create a test app that every test case can use
     app.config['TESTING'] = True
     self.api = app.test_client()
Beispiel #18
0
 def test_no_connection(self):
     tester = app.test_client(self)
     response = tester.get('/data/', content_type=('html/text'))
     self.assertIn('ConnectionError', response.status)
Beispiel #19
0
 def test_divide_missing_value(self):
     tester = app.test_client(self)
     response = tester.get('/divide?value1=1', content_type='application/json')
     self.assertEqual(json.loads(response.data.decode('utf-8')), {"Error": "Lose Key","status": 406})
Beispiel #20
0
 def setUp(self):
     self.app = app.test_client()
Beispiel #21
0
    def setUp(self):

        app.config.from_object('config')
        self.app = app.test_client()
 def setUp(self):
     app.debug = True
     app.testing = True
     self.client = app.test_client()
     self.maxDiff = 2000
 def __init__(self, *args, **kwargs):
     super(TestAPITagResourceByValue, self).__init__(*args, **kwargs)
     self.base_url = '/api/tags/values'
     self.app = app.test_client()
Beispiel #24
0
def test_api():
    with app.test_client() as c:
        response = c.get("/api/")
        assert response.status_code == 200
Beispiel #25
0
 def test_getDevices_connection(self):
     print("\n--------------------------------")
     print("New test:", self, "\n")
     tester = app.test_client(self)
     response = tester.get('/getDevices')
     self.assertEqual(response.status_code, 200)
Beispiel #26
0
 def test_wrongPath(self):
     print("\n--------------------------------")
     print("New test:", self, "\n")
     tester = app.test_client(self)
     response = tester.get('/a')
     self.assertEqual(response.status_code, 404)
Beispiel #27
0
 def test_connection_to_flask(self):
     print("\n--------------------------------")
     print("New test:", self, "\n")
     tester = app.test_client(self)
     response = tester.get('/checkConnection')
     self.assertEqual(response.status_code, 200)
 def test_get_tweets(self, twitter_api):
   twitter_api.return_value = [self.status_1, self.status_2]
   response = app.test_client().get('/tweets/ydawant/')
   self.assertEqual(response.status_code, 200)
   self.assertEqual(json.loads(response.data), {u'tweets': [{u'picture': u'https://www.google.com', u'influence_score': 1, u'created_at': u'December 2, 2014', u'text': u'good text', u'retweet_count': 5, u'id': 1},
                                                            {u'picture': None, u'influence_score': -1, u'created_at': u'December 2, 2014', u'text': u'bad text', u'retweet_count': 5, u'id': 2}]})
Beispiel #29
0
def _api():
    with app.test_client() as client:
        yield client
Beispiel #30
0
import unittest
import db
import json
from datetime import datetime
from data import new_recipe, fork_recipe, update_recipe, get_versions, get_recipes_for_user, get_forks, get_version, BadVersionError
from api import app
app.config['DEBUG'] = True

test_client = app.test_client()

class Test(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        clean()


class TestWithData(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        clean()
        insert_all()


def clean():
    db.session.close()
    db.Base.metadata.drop_all(db.engine)
    db.Base.metadata.create_all(db.engine)


class NewRecipe(Test):
    def test_new_recipe(self):
Beispiel #31
0
def test_api_works_basic():
    body = carregar_json(path)
    response = app.test_client().post("/v1/categorize",
                                      data=json.dumps(body),
                                      content_type="application/json")
    assert response.status_code == 200
Beispiel #32
0
 def __init__(self, *args, **kwargs):
     super(BaseTestCase, self).__init__(*args, **kwargs)
     self.app = app.test_client()
Beispiel #33
0
def test_api_works_products():
    body = carregar_json(TEST_PRODUCTS_PATH)
    response = app.test_client().post("/v1/categorize",
                                      data=json.dumps(body),
                                      content_type="application/json")
    assert response.status_code == 200
Beispiel #34
0
 def test_multiply_incorrect_value(self):
     tester = app.test_client(self)
     response = tester.get('/multiply?value1=a&value=2', content_type='application/json')
     self.assertEqual(json.loads(response.data.decode('utf-8')), { "Error":"Lose Key","status": 406})
Beispiel #35
0
def test_api_bad_request():
    response = app.test_client().post("/v1/categorize",
                                      data=json.dumps({}),
                                      content_type="application/json")
    assert response.status_code == 400
Beispiel #36
0
def client(app):
    return app.test_client()
Beispiel #37
0
 def test_index(self):
     tester = app.test_client(self)
     response = tester.get('/pedidos')
     statuscode = response.status_code
     self.assertEqual(statuscode, 200)
Beispiel #38
0
 def test_connection(self):
     tester = app.test_client()
     response = tester.get('/data/', content_type=('html/text'))
     self.assertEqual(response.status_code, 200)
Beispiel #39
0
def test_post_services():
    print('=== Testing Post Services ====')
    get_base64_image_file('image.png')

    'Validate Create Post'
    response = app.test_client().post(
        '/post/',
        data=json.dumps({
            "post": "This is the post content 2 #best",
            "topic": "this is the title 2",
            "privacy": "Public",
            "attachments": []
        }),
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data.get('code') == 200
        global post_id
        post_id = data.get('data').get('id')
        print('Validate Create Post : OK')
    except AssertionError:
        print('Validate Create Post : FAIL')
    except Exception:
        print(traceback.print_exc())

    'Validate View All Post'
    response = app.test_client().get(
        '/post/all/',
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data.get('code') == 200
        print('Validate View All Post : OK')
    except AssertionError:
        print('Validate View All Post : FAIL')

    'Validate View Post'
    response = app.test_client().get(
        '/post/' + post_id,
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data.get('code') == 200
        print('Validate View Post : OK')
    except AssertionError:
        print('Validate View Post : FAIL')

    'Validate Like Post'
    response = app.test_client().post(
        '/post/like',
        data=json.dumps({"post": post_id}),
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data.get('code') == 200
        print('Validate Like Post : OK')
    except AssertionError:
        print('Validate Like Post : FAIL')

    'Validate Dislike Post'
    response = app.test_client().post(
        '/post/dislike',
        data=json.dumps({"post": post_id}),
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data.get('code') == 200
        print('Validate Dislike Post : OK')
    except AssertionError:
        print('Validate Dislike Post : FAIL')

    'Validate Hashtag'
    response = app.test_client().get(
        '/hashtag/best',
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data.get('code') == 200
        print('Validate Hashtag : OK')
    except AssertionError:
        print('Validate Hashtag : FAIL')
    except Exception:
        print(traceback.print_exc())
Beispiel #40
0
 def test_customer_history_no_history(self):
     with app.test_client() as api:
         response = api.get('/api/v1/history/3')
         json_data = response.get_json()
         test = {"3": "no orders!"}
         self.assertDictEqual(test, json_data)
Beispiel #41
0
def test_auth_services():
    print('=== Testing Auth Services ====')
    'Validate username'
    response = app.test_client().post(
        '/validateusername',
        data=json.dumps({
            "username": "******",
        }),
        content_type='application/json',
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data['code'] == 400
        print('Validate Username : OK')
    except AssertionError:
        print('Validate Username : FAIL')

    'Validate email'
    response = app.test_client().post(
        '/validateemail',
        data=json.dumps({
            "email": "*****@*****.**",
        }),
        content_type='application/json',
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data['code'] == 400
        print('Validate Email : OK')
    except AssertionError:
        print('Validate Email : FAIL')

    'Validate Forgot Password'
    response = app.test_client().post(
        '/auth/forgot',
        data=json.dumps({
            "email": "*****@*****.**",
        }),
        content_type='application/json',
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data['code'] == 200
        print('Validate Forgot Password : OK')
    except AssertionError:
        print('Validate Forgot Password : FAIL')

    'Validate Reset Password'
    response = app.test_client().post(
        '/auth/reset',
        data=json.dumps({
            "email": "*****@*****.**",
            "otp": "845652",
            "password": "******"
        }),
        content_type='application/json',
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data['status'] == "Incorrect OTP."
        print('Validate Reset Password : OK')
    except AssertionError:
        print('Validate Reset Password : FAIL')

    test_sign_in('*****@*****.**', 'joyalbaby0675')

    'Validate Session'
    response = app.test_client().get(
        '/auth/validate/',
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data['code'] == 200
        print('Session Validation : OK')
    except AssertionError:
        print('Session Validation : FAIL')
    test_sign_out()
    'In Valid Session'
    response = app.test_client().get(
        '/auth/validate/',
        headers={
            "content_type": "application/json",
            "Authorization": "Bearer " + str(auth_token)
        },
    )
    data = json.loads(response.get_data(as_text=True))
    try:
        assert data.get('status') == "Token has been revoked"
        print('Session Out : OK')
    except AssertionError:
        print('Session Out : FAIL')
Beispiel #42
0
 def setUp(self):
     self.app_client = app.test_client()
Beispiel #43
0
 def setUp(self):
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
     self.app = app.test_client()
     db.create_all()
     self.load_data()
 def test_get_user(self, twitter_api):
   twitter_api.return_value = self.user
   response = app.test_client().get('/user/ydawant/')
   self.assertEqual(response.status_code, 200)
   self.assertEqual(json.loads(response.data), {u'user': {u'following': 20, u'followers': 10, u'description': u'fun times', u'name': u'yannick', u'id': 12345}})
Beispiel #45
0
 def setUp(self) -> None:
   self.client = app.test_client()
   app.app_context()
Beispiel #46
0
 def test_divide_zero_value(self):
     tester = app.test_client(self)
     response = tester.get('/divide?value1=1&value2=0', content_type='application/json')
     self.assertEqual(json.loads(response.data.decode('utf-8')), { "Error": "Value2 shold not be zero!","status": 200})
Beispiel #47
0
]
test_features = [
    {'feature': 'NFC', 'category': 2},
]


def setup_module(module):
    if not os.path.exists(os.path.join(os.path.dirname(__file__), os.path.pardir, 'db.sqlite')):
        create_all_tables()
        create_demo_products()

    app.config.from_object('config.TestingConfig')
    register_endpoints(app, db.Product, base_url=TestingConfig.BASE_URL, _search_field_name='title')


client = app.test_client()


def get_product_list(endpoint='product/'):
    response = client.get('{}{}'.format(API_URL, endpoint), follow_redirects=True)
    result = json.loads(response.get_data(as_text=True))
    return response, result


def test_get_product_list():
    response, result = get_product_list()
    assert response.status_code == 200
    assert len(result)
    for product in result:
        assert 'title' in product
Beispiel #48
0
 def setUp(self):
   app.config['TESTING'] = True
   app.config['WTF_CSRF_ENABLED'] = False
   self.app = app.test_client()
Beispiel #49
0
 def setUp(self):
     """Method which i run before every test"""
     self.client = app.test_client(self)
 def setUp(self):
     self.app = app.test_client()
     self._load_data()
     self._login()
Beispiel #51
0
 def test_index(self):
     tester = app.test_client(self)
     response = tester.get('/', content_type='html/text')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, b'Hello, World!')
 def setUp(self):
   app.config['TESTING'] = True
   self.app = app.test_client()
Beispiel #53
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['DEBUG'] = False
     self.app = app.test_client()
     self.assertEqual(app.debug, False)
Beispiel #54
0
 def test_divide_basic(self):
     tester = app.test_client(self)
     response = tester.get('/divide?value1=1&value2=1', content_type='application/json')
     self.assertEqual(json.loads(response.data.decode('utf-8')), {"divide": "1.00","status": 200})
Beispiel #55
0
 def setUp(self):
     self.test_app = app.test_client()
Beispiel #56
0
 def test_sum_basic(self):
     tester = app.test_client(self)
     response = tester.get('/sum?value1=1&value2=1', content_type='application/json')
     self.assertEqual(json.loads(response.data.decode('utf-8')), {"status": 200,"sum": "2.00"})
Beispiel #57
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
Beispiel #58
0
 def __init__(self, *args, **kwargs):
     super(TestAPIObjectResourceByID, self).__init__(*args, **kwargs)
     self.base_url = '/api/objects'
     self.app = app.test_client()
Beispiel #59
0
 def setup(self):
     self.test_app = app.test_client()
     self.repo = RouteRepository(db)
     delete_db()