def setUp(self):
        """ Runs before each test """
        self.app = app.test_client()
        Customer.init_db("tests")
        Customer.remove_all()
        Customer(first_name='fido',
                 last_name='dog',
                 address='ny',
                 email='*****@*****.**',
                 username='******',
                 password='******',
                 phone_number='932',
                 active=True,
                 id = 1
        ).save()

        time.sleep(WAIT_SECONDS)

        Customer(first_name='afido',
                 last_name='cat',
                 address='ny',
                 email='*****@*****.**',
                 username='******',
                 password='******',
                 phone_number='9321',
                 active=True,
                 id = 2
        ).save()

        time.sleep(WAIT_SECONDS)

        Customer(first_name='redo',
                 last_name='cat',
                 address='ny',
                 email='*****@*****.**',
                 username='******',
                 password='******',
                 phone_number='233',
                 active=False,
                 id = 3
        ).save()

        time.sleep(WAIT_SECONDS)

        Customer(first_name='tedo',
                 last_name='dog',
                 address='nj',
                 email='*****@*****.**',
                 username='******',
                 password='******',
                 phone_number='423',
                 active=False,
                 id = 4
        ).save()

        self.app = app.test_client()
Beispiel #2
0
    def setUp(self):
        app.config.from_object('testing.TestConfig')
        self.app = app.test_client()

        db.create_all()

        fixtures.load_fixtures(
            loaders.load('testing/fixtures/user.json'))
        fixtures.load_fixtures(
            loaders.load('testing/fixtures/broadcaster2_follower.json'))
        fixtures.load_fixtures(
            loaders.load('testing/fixtures/tweet.json'))


        # manually setting date_created; I don't believe 
        # Flask-Fixtures supports setting dates
        renee_tweet = Tweet.query.filter_by(id=1).first()
        renee_tweet.date_created = datetime.date(2015, 1, 1)

        trenton_tweet = Tweet.query.filter_by(id=2).first()
        trenton_tweet.date_created = datetime.date(2015, 1, 2)

        db.session.add(renee_tweet)
        db.session.add(trenton_tweet)
        db.session.commit()
    def test_users_query(self):
        # Test users query status code.

        self.test_app = app.test_client()
        dummy_dict = {
            'name': '',
            'uid': 1000000,
            'gid': 1000000,
            'comment': '',
            'home': '',
            'shell': ''
        }

        # Get all combinations of querystring args.
        combos = []
        for i in range(len(user_cols) + 1):
            for item in combinations(user_cols, i):
                temp = {}
                for param in list(item):
                    temp[param] = dummy_dict[param]
                combos.append(temp)

        # Iterate through all combinations of querystring args.
        for item in combos:
            response = self.test_app.get('/users/query', query_string=item)
            self.assertEqual(response.status_code, 200)

        # Run query with non-supported arg.
        response = self.test_app.get('/users/query',
                                     query_string={'asdf': 'fdsa'})
        self.assertEqual(response.status_code, 200)
    def test_users_all(self):
        # Test all users status code.

        self.test_app = app.test_client()
        response = self.test_app.get('/users')
        self.assertEqual(response.status_code, 200)
        '''with app.test_client() as client:  # Testing query URL.
Beispiel #5
0
 def setUp(self):
     app.config['host'] = opts.address.split(':')[0]
     app.config['port'] = opts.address.split(':')[1]
     app.config['database'] = opts.database
     app.config['username'] = opts.username
     app.config['password'] = opts.password
     self.app = app.test_client()
def test_getter():
    """test greeter endpoint"""
    response = app.test_client().get('/reservations?flight_id=QWE123')

    # data = response.get_data(as_text=True)

    assert response.status_code == 200
Beispiel #7
0
 def setUp(self):
     self.app = app.test_client()
     initialize_logging(logging.CRITICAL)
     init_db()
     data_reset()
     data_load({"name": "fido", "category": "dog", "available": True})
     data_load({"name": "kitty", "category": "cat", "available": True})
 def setUp(self):
     """ Initialize the Cloudant database """
     self.app = app.test_client()
     Promotion.init_db("tests")
     Promotion.remove_all()
     Promotion("A001", "BOGO", True, 10).save()
     Promotion("A002", "B2GO", True, 10).save()
     Promotion("A003", "B3GO", False, 10).save()
 def setUp(self):
     """ Initialize the Cloudant database """
     self.app = app.test_client()
     Pet.init_db("tests")
     Pet.remove_all()
     Pet("fido", "dog", True).save()
     Pet("kitty", "cat", True).save()
     Pet("harry", "hippo", False).save()
Beispiel #10
0
 def setUp(self):
     """ Runs before each test """
     init_db()
     db.drop_all()    # clean up the last tests
     db.create_all()  # create new tables
     self.app = app.test_client()
     self.headers = {
         'X-Api-Key': app.config['API_KEY']
     }
    def test_users_query_data(self):
        # Test users query data.

        self.test_app = app.test_client()
        dummy_dict = {
            'name': 'root',
            'uid': 0,
            'gid': 0,
            'comment': 'System Operator',
            'home': '/',
            'shell': '/bin/ksh'
        }

        # Get all combinations of querystring args.
        combos = []
        for i in range(len(user_cols) + 1):
            for item in combinations(user_cols, i):
                temp = {}
                for param in list(item):
                    temp[param] = dummy_dict[param]
                combos.append(temp)

        # Iterate through all combinations of querystring args.
        for item in combos:
            response = self.test_app.get('/users/query', query_string=item)

            # Test for valid JSON.
            json_vals = self.valid_json(response.data)

            # JSON return is invalid.
            if json_vals is None:
                self.assertTrue(False)

            # Test the valid JSON.
            else:

                # No need to validate if we have a user.
                # Some queries may not return any users.

                # Check for all user columns in returned data.
                self.valid_user_data(json_vals, False)

        # Run query with non-supported arg.
        response = self.test_app.get('/users/query',
                                     query_string={'asdf': 'fdsa'})
        json_vals = self.valid_json(response.data)
        if json_vals is None:
            self.assertTrue(False)
        else:

            # No need to validate if we have a user.
            # Some queries may not return any users.

            # Check for all user columns in returned data.
            self.valid_user_data(json_vals, False)
def test_greeter():
    """test greeter endpoint"""
    response = app.test_client().get(
        '/hello/nina'
        #data=json.dumps({'a': 1, 'b': 2}),
        #content_type='application/json',
    )

    data = response.get_data(as_text=True)

    assert response.status_code == 200
    assert data == "Hello nina!"
    def test_users_single(self):
        # Test single user status code.

        self.test_app = app.test_client()
        response = self.test_app.get('/users/' +
                                     str(dummy_user))  # dummy user.
        self.assertEqual(response.status_code, 200)

        response = self.test_app.get('/users/1000000')  # non-existent user.
        self.assertEqual(response.status_code, 404)

        response = self.test_app.get('/users/asdf')  # non-integer uid.
        self.assertEqual(response.status_code, 404)
    def test_groups_single(self):
        # Test single group status code.

        self.test_app = app.test_client()
        response = self.test_app.get('/groups/' +
                                     str(dummy_group))  # dummy group.
        self.assertEqual(response.status_code, 200)

        response = self.test_app.get('/groups/1000000')  # non-existent group.
        self.assertEqual(response.status_code, 404)

        response = self.test_app.get('/groups/asdf')  # non-integer gid.
        self.assertEqual(response.status_code, 404)
Beispiel #15
0
    def setUp(self):
        # creates a test client
        self.app = app.test_client()
        # propagate the exceptions to the test client

        # sends HTTP GET request to the application
        # on the specified path
        result = self.app.get(
            '/commodity?start_date=2019-04-17&end_date=2019-05-01&commodity_type=gold'
        )
        # assert the response data
        self.obj = json.loads(result.data.decode())

        self.app.testing = True
    def test_users_groups(self):
        # Test user group status code.

        self.test_app = app.test_client()
        response = self.test_app.get('/users/' + str(dummy_user) +
                                     '/groups')  # dummy user.
        self.assertEqual(response.status_code, 200)

        response = self.test_app.get(
            '/users/1000000/groups')  # non-existent user.
        self.assertEqual(response.status_code, 404)

        response = self.test_app.get('/users/asdf/groups')  # non-integer uid.
        self.assertEqual(response.status_code, 404)
Beispiel #17
0
 def setUp(self):
     """ Initialize the Cloudant database """
     self.app = app.test_client()
     Pet.init_db("tests")
     # Cloudant Lite will rate limit so you must sleep between requests :()
     sleep(0.5)
     Pet.remove_all()
     sleep(0.5)
     Pet("fido", "dog", True).save()
     sleep(0.5)
     Pet("kitty", "cat", True).save()
     sleep(0.5)
     Pet("harry", "hippo", False).save()
     sleep(0.5)
def test_user_save():
    """Test user saving"""
    response = app.test_client().post(
        '/users/12345',
        data=json.dumps({
            'name': "test_user",
            'b': "test_user_other_data"
        }),
        content_type='application/json',
    )

    data = json.loads(response.get_data(as_text=True))

    assert response.status_code == 200
    assert data['completion']['user_id'] == '12345'
def test_user_save():
    """Test user saving"""
    response = app.test_client().put(
        '/reservations',
        data=json.dumps({
            'seat_num': "12C",
            'flight_id': "QWE123",
            "customer_id": "anon"
        }),
        content_type='application/json',
    )

    # data = json.loads(response.get_data(as_text=True))

    valid_response = (response.status_code == 200
                      or response.status_code == 403)
    assert valid_response
def client():
    ## Setup for each test ##
    app.config['TESTING'] = True
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@testdb:5432/mytestdb'

    client = app.test_client()

    with app.app_context():
        db.create_all()

    yield client

    ## Teardown for each test ##
    with app.app_context():
        db.session.close()
        db.drop_all()
def test_service_token(auth0_key_mock, service_token):
    app.config["TOKEN"] = "abc123"
    app.config["AUTH0_JWKS"] = "https://auth0/jwks.json"
    app_context = app.app_context()
    app_context.push()
    client = app.test_client()

    resp = client.post(
        "/buckets",
        headers={
            "Content-Type": "application/json",
            "Authorization": f"Bearer {service_token()}",
        },
        data=json.dumps({"study_id": "SD_00000000"}),
    )

    assert resp.status_code == 201
Beispiel #22
0
 def setUp(self):
     """Runs before each test"""
     self.app = app.test_client()
     Recommendation.init_db("tests")
     sleep(0.5)
     Recommendation.remove_all()
     sleep(0.5)
     Recommendation(id=1,
                    productId='Infinity Gauntlet',
                    suggestionId='Soul Stone',
                    categoryId='Comics').save()
     sleep(0.5)
     Recommendation(id=2,
                    productId='iPhone',
                    suggestionId='iphone Case',
                    categoryId='Electronics').save()
     sleep(0.5)
    def test_users_all_data(self):
        # Check all users data.

        self.test_app = app.test_client()
        response = self.test_app.get('/users')

        json_vals = self.valid_json(response.data)

        # JSON return is invalid.
        if json_vals is None:
            self.assertTrue(False)

        # Test the valid JSON.
        else:

            # Make sure we have users.
            self.assertTrue(len(json_vals) > 0)

            # Check for all user columns in returned data.
            self.valid_user_data(json_vals, False)
 def setUp(self):
     app.config["TESTING"] = True
     app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/test.db"
     self.app = app.test_client()
     db.create_all()
     self.data = {'code': 'g',
     'description': 'Giulia',
     'designer': 'alice',
     'gender': 'F',
     'image_urls': ['http://www.oxygenboutique.com/GetImage/d',
                    'http://www.oxygenboutique.com/GetImage/d'],
     'last_updated': '2013-07-12 17:25:24',
     'name': 'Giulia Emb',
     'price': 690.0,
     'raw_color': '',
     'sale_discount': 0,
     'source_url': 'http://www.oxygenboutique.com/giulia-em',
     'stock_status': {u'L': 1, u'M': 1, u'S': 3, u'XS': 3},
     'type': 'A'}
     self.data["__type__"] = "Product"
Beispiel #25
0
 def setUp(self):
     self.app = app.test_client()
     self.headers = {'X-Api-Key': app.config['API_KEY']}
     service.init_db("test")
     service.data_reset()
     service.data_load({
         "name": "fido",
         "category": "dog",
         "available": True
     })
     service.data_load({
         "name": "kitty",
         "category": "cat",
         "available": True
     })
     service.data_load({
         "name": "happy",
         "category": "hippo",
         "available": False
     })
    def test_users_single_data(self):
        # Test single user data.

        self.test_app = app.test_client()
        response = self.test_app.get('/users/' +
                                     str(dummy_user))  # dummy group.

        json_vals = self.valid_json(response.data)

        # JSON return is invalid.
        if json_vals is None:
            self.assertTrue(False)

        # Test the valid JSON.
        else:

            # Make sure we have a user.
            self.assertTrue(len(json_vals) > 1)

            # Check for all user columns in returned data.
            self.valid_user_data(json_vals, True)
    def test_users_groups_data(self):
        # Test user group data.

        self.test_app = app.test_client()
        response = self.test_app.get('/users/' + str(dummy_user) +
                                     '/groups')  # dummy user.

        json_vals = self.valid_json(response.data)

        # JSON return is invalid.
        if json_vals is None:
            self.assertTrue(False)

        # Test the valid JSON.
        else:

            # No need to validate if we have a group.
            # Some users may not be in any groups.

            # Check for all group columns in returned data.
            self.valid_group_data(json_vals, False)
Beispiel #28
0
    def setUp(self):
        app.config.from_object('testing.TestConfig')
        self.app = app.test_client()

        db.create_all()

        fixtures.load_fixtures(loaders.load('testing/fixtures/user.json'))
        fixtures.load_fixtures(
            loaders.load('testing/fixtures/broadcaster2_follower.json'))
        fixtures.load_fixtures(loaders.load('testing/fixtures/tweet.json'))

        # manually setting date_created; I don't believe
        # Flask-Fixtures supports setting dates
        renee_tweet = Tweet.query.filter_by(id=1).first()
        renee_tweet.date_created = datetime.date(2015, 1, 1)

        trenton_tweet = Tweet.query.filter_by(id=2).first()
        trenton_tweet.date_created = datetime.date(2015, 1, 2)

        db.session.add(renee_tweet)
        db.session.add(trenton_tweet)
        db.session.commit()
 def setUp(self):
     self.app = app.test_client()
     self.headers = {'X-Api-Key': app.config['API_KEY']}
     routes.init_db("test")
     routes.data_reset()
     routes.data_load({
         "name": "fido",
         "category": "dog",
         "available": True,
         "gender": Gender.Male.name
     })
     routes.data_load({
         "name": "kitty",
         "category": "cat",
         "available": True,
         "gender": Gender.Female.name
     })
     routes.data_load({
         "name": "happy",
         "category": "hippo",
         "available": False,
         "gender": Gender.Unknown.name
     })
Beispiel #30
0
 def setUp(self):
     """ Runs before each test """
     init_db()
     db.drop_all()  # clean up the last tests
     db.create_all()  # create new tables
     self.app = app.test_client()
 def setUp(self):
     """ This runs before each test """
     Counter.connect(DATABASE_URI)
     Counter.remove_all()
     self.app = app.test_client()
 def setUp(self):
     app.testing = True
     self.app = app.test_client()
     self.token = "Bearer eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NDMzMjc0MTUsImlhdCI6MTU0MzI0MTAxNSwiaXNzIjoiSm9ybXVuZ2FuZHIgSldUIEF1dGhvcml0eSIsImp0aSI6ImExOGEzOTQ0LWUyM2QtNDk4My1hZTYwLThlMGEyOWE0ZGM3ZSIsIm5iZiI6MCwib3JnYW5pemF0aW9ucyI6IiIsInJvbGVzIjoidXNlciIsInNjb3BlcyI6IlwiYXBpOnJlYWRcIiIsInN1YiI6IjViZmJmY2FiODJlNjIyMDAwMTJjMmM0NSIsInVzZXJJZCI6IjViZmJmY2FiODJlNjIyMDAwMTJjMmM0NSIsInVzZXJuYW1lIjoiYW5hQGFuYS5jb20ifQ.BdQB0FxEXR33Sitn__59Iii98BAbrsQay0Z-XdOH_E6OW7oyEJQc50jr63aftRP8cLqVMPXyR-_qRYbiz8Pm3kFUXGfLAY3bSRrmTPKqhCNUiLbEbm9TKcPpYJVPt0twrLtFDPv28stDPEmfI4WcowsqbVoqaAckJZsFJTpm87bRiAOuquiGMyACgcoFaTiJiSUpTUBDvnqcUCPrYvkX61Ht6gVXN7YsC952v6dWBHmQo3mKiFyBCC7JxGtcH-cojsklRzIu0G90Td6h-SdixQtZs07lrggG9T41s9rPvoeKiUc3BBN_pWweok3zpVdn89UW8CZAN_r3sAB2-camCQ"
 def setUp(self):
     app.testing = True
     self.app = app.test_client()
     self.base_url = '/api/v1.0'
Beispiel #34
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()