コード例 #1
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data()

        with self.client as c:
        with c.session_transaction() as sess:
            sess['RSVP'] = True

    def tearDown(self):
        """Do at end of every test."""

        # (uncomment when testing database)
        db.session.close()
        db.drop_all()

    def test_games(self):
        result = self.client.get("/games")
        self.assertIn("Clue", result.data)
コード例 #2
0
    def setUp(self):

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()
コード例 #3
0
ファイル: tests.py プロジェクト: allymcknight/CompanyClimate
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()

        connect_to_db(app, "sqlite:///")

        db.create_all()
        example_data()
コード例 #4
0
ファイル: tests.py プロジェクト: k-wiz/insomnia-app
    def setUp(self):
        self.client = app.test_client()
        app.config['TESTING'] = True

        #Connect to test db
        connect_to_db(app, 'postgresql:///testdb')

        #Create tables & add sample data
        db.create_all()
        example_data()
コード例 #5
0
ファイル: tests.py プロジェクト: laurensila/flask-testing
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        connect_to_db(app, "postgresql:///testdb")

        db.create_all()
        example_data()
コード例 #6
0
    def setUp(self):
        """Do at the start of every test"""

        self.client = app.test_client()
        app.config['TESTING'] = True
        connect_to_db(app, "postgresql:///test_questions")

        db.drop_all()
        db.create_all()

        example_data()
コード例 #7
0
ファイル: tests.py プロジェクト: aninahpets/RestaurantRides
    def setUp(self):
        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'key'
        self.client = app.test_client()
        connect_to_db(app, "postgresql:///testdb")
        db.create_all()
        example_data()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1
コード例 #8
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")
        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data()
コード例 #9
0
ファイル: tests.py プロジェクト: tkahnhau/hamildata
    def setUp(self):
        """Do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///travis_ci_test")

        # Create tables and add sample data
        db.create_all()
        example_data()
コード例 #10
0
ファイル: tests.py プロジェクト: ahmsolo/fish-finder
    def setUp(self):
        """Tasks to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()
コード例 #11
0
ファイル: tests.py プロジェクト: EmmaOnThursday/next-book
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()

        # Create secret key to access session
        app.secret_key = "ABC"

        # Connect to fake database
        connect_to_db(app, 'postgresql:///testdb')
        db.create_all()
        app.config['TESTING'] = True

        example_data()
コード例 #12
0
    def setUp(self):
        """Flask tests that use the database."""

        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'ABC'
        self.client = app.test_client()
        connect_to_db(app, "postgresql:///test_questions")

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1

        db.drop_all()
        db.create_all()

        example_data()
コード例 #13
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['RSVP'] = True
コード例 #14
0
    def setUp(self):
        """Stuff to do before every test."""

        # get flask test client
        self.client = app.test_client()

        #disable the error catching during request handling so that you get better error reports when performing test requests against the application.
        app.config['TESTING'] = True

        # QUESTION: Connect to test database
        # can I do this without creating a testdb?
        connect_to_db(app, "postgresql:///testdb")

        # QUESTION: Create tables and add sample data
        db.create_all()
        example_data()
コード例 #15
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'key'

        with self.client as c:
            with c.session_transaction() as sess:
                sess['RSVP'] = True
        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data()
コード例 #16
0
    def setUp(self):
        """Before every test"""

        app.config['TESTING'] = True
        self.client = app.test_client()

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1
コード例 #17
0
    def setUp(self):
        """To do before every test."""

        self.client = app.test_client()
        app.config['SECRET_KEY'] = 'key'
        app.config['TESTING'] = True
        connect_to_db(app, "postgresql:///apptestdb")
        db.create_all()
        example_data()

        with self.client as c:
            with c.session_transaction() as s:
                s['ID'] = 1
                s['NAME'] = 'Alex'
                s['EMAIL'] = '*****@*****.**'

        #Mock functions for API calls
        def _mock_check_hashed_password(password, hashed_password):
            """Mocks boolean return of hashed password check"""

            if password == 'test':
                return True
            else:
                return False

        helper.check_hashed_password = _mock_check_hashed_password

        def _mock_cloudinary_image_upload(image_data):
            """Mocks Cloudinary API upload call"""

            return 'fake url'

        api.cloudinary_upload_image = _mock_cloudinary_image_upload

        def _mock_cloudinary_image_delete(image_data):
            """Mocks Cloudinary API delete call"""

            return 'image deleted'

        api.cloudinary_delete_image = _mock_cloudinary_image_delete

        def _mock_borrow_book_text(data):
            """Mocks Twilio text call"""

            return None

        api.borrow_book_text = _mock_borrow_book_text
コード例 #18
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = "key"

        with self.client as c:
            with c.session_transaction() as sess:
                sess['RSVP'] = 1

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()
コード例 #19
0
ファイル: tests.py プロジェクト: amsowie/HBproject
    def setUp(self):
        """Setting up tests for pages where user is logged in"""

        self.client = app.test_client()
        app.config['TESTING'] = True  # shows debugging output
        connect_to_db(app, "postgresql:///testdb"
                      )  # work on this postg understanding and db test
        app.config['SECRET_KEY'] = 'key'

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_name'] = 'Brian'
                sess['user_id'] = 1

        #create tables and ad sample data
        db.create_all()
        example_data()
コード例 #20
0
ファイル: tests.py プロジェクト: acufarah/garden-trading
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'key'
        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")
        bcrypt = Bcrypt(app)
        # Create tables and add sample data (uncomment when testing database)
        db.drop_all()
        db.create_all()
        example_data(bcrypt)

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1
コード例 #21
0
    def setUp(self):
        """Do before every test."""

        self.client = app.test_client()
        app.config["TESTING"] = True
        app.config["SECRET_KEY"] = "key"

        with self.client as c:
            with c.session_transaction() as sess:
                sess["user_id"] = 1
                sess["user_name"] = 1

        connect_to_db(app, "postgresql:///testdb")

        db.create_all()
        example_data()
        update_pkey_seqs()
コード例 #22
0
    def setUp(self):
        """ To do before every test."""

        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'key'

        self.client = app.test_client()
        connect_to_db(app, "postgresql:///ratings_test")

        # Create tables and add sample data
        db.drop_all()
        db.create_all()
        example_data()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1
コード例 #23
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # The second 'with' STORES a session in the test browser
        # (so that it can be fake-logged-in)
        with self.client as c:
            with c.session_transaction() as sess:
                sess['RSVP'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data()
コード例 #24
0
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()

        # Show Flask errors that happen during tests
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        def f_date():
            assert datetime.datetime.now() == datetime.datetime(2017, 10, 31)
コード例 #25
0
ファイル: tests.py プロジェクト: loopDelicious/testing-py-2
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # adding a session variable to signify user has RSVP'd, since all tests
        # in PartyTestsDatabases class assumes user has RSVP'd
        with self.client as c:
            with c.session_transaction() as sess:
                sess['RSVP'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data()
コード例 #26
0
ファイル: tests.py プロジェクト: yusra-ahmed/language-app
    def setUp(self):
        """Set up a fake browser"""
        # Get the Flask test client
        self.client = app.test_client()
        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1
                sess['username'] = '******'

        app.config['TESTING'] = True
        app.config['DEBUG'] = False
        connect_to_db(app, "postgresql:///testdb")

        app.secret_key = "Babilim1234"

        # Connects to fake database
        db.create_all()
        example_data()
コード例 #27
0
    def setUp(self):
        """Stuff to do before every test."""

        app.config['TESTING'] = True
        #TO DO: Figure out if secret key here needs to match secret key in server file
        app.config['SECRET_KEY'] = 'ABC'
        self.client = app.test_client()

        with self.client as c:
            with c.session_transaction() as session:
                session['student_id'] = 1

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()
コード例 #28
0
    def setUp(self):
        """Before every test"""

        app.config['TESTING'] = True
        self.client = app.test_client()

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1

        # Make mock
        def _mock_recipe_search(search_name, recipe_id):
            """ Mocks info returned from Spoonacular API. """

            example_search = fake_api_json.recipe_search('pasta', 1)

            return example_search

        def _mock_summary_info(recipe_id):
            """ Mocks info returned from Spoonacular API. """

            example_summary = fake_api_json.summary_info('548180')

            return example_summary

        def _mock_recipe_info(recipe_id):
            """ Mocks info returned from Spoonacular API. """

            example_info = fake_api_json.recipe_info('548180')

            return example_info

        # Attaches mocks calls to app's real calls
        api_calls.recipe_search = _mock_recipe_search
        api_calls.summary_info = _mock_summary_info
        api_calls.recipe_info = _mock_recipe_info
コード例 #29
0
    def setUp(self):
        """Stuff to do before every test."""

        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'key'
        self.client = app.test_client()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1

        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        # import pdb
        # pdb.set_trace()

        example_data()
コード例 #30
0
ファイル: tests.py プロジェクト: marsmans13/HB-Project
    def setUp(self):
        self.client = app.test_client()
        app.config['TESTING'] = True

        connect_to_db(app, "postgresql:///testdb")

        db.create_all()
        example_data()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['username'] = '******'

        self.client.post('/login',
                         data={
                             'username': '******',
                             'password': '******'
                         },
                         follow_redirects=True)
コード例 #31
0
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()

        # Show Flask errors that happen during tests
        app.config['TESTING'] = True

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1
       
        # Connect to test database
        connect_to_db(app, "testdb") #create testdb based on model.py

        # # Create tables and add sample data
        db.create_all()
        example_data()
コード例 #32
0
ファイル: tests.py プロジェクト: yfalcon8/Testing_py_2
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        # Reach into model.py to call example_data() to create test db
        db.create_all()
        example_data()

        # with statement for the test client to be logged in 
        # - if theyre logged in the /games route should display games.html
        with self.client as c:
            with c.session_transaction() as sess:
                sess['RSVP'] = True
コード例 #33
0
    def setUp(self):
        """Stuff to do before every test."""

        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'ABC'
        self.client = app.test_client()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['current_user'] = "******"

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data

        db.drop_all()
        db.create_all()
        example_data()
コード例 #34
0
ファイル: tests.py プロジェクト: elenachurilova/gastronotes
    def test_login(self):
        """Test login page"""

        example_data()

        result = self.client.post("/login",
                                  data={
                                      "email": "*****@*****.**",
                                      "password": "******"
                                  },
                                  follow_redirects=True)
        self.assertIn(b"Successfully logged in as", result.data)

        result2 = self.client.post("/login",
                                   data={
                                       "email": "*****@*****.**",
                                       "password": "******"
                                   },
                                   follow_redirects=True)
        self.assertIn(b"Incorrect password", result2.data)
コード例 #35
0
    def setUp(self):
        """Set up test database and mock api result."""

        self.client = app.test_client()
        app.config['TESTING'] = True
        connect_to_db(app, "postgresql:///testdb")

        db.create_all()
        example_data()

        # Make mock
        def _mock_find_route_coordinates(origin, destination):

            return [(37.8067567, -122.2961741), (37.8070326, -122.2974171),
                    (37.8167166, -122.2896513), (37.8276755, -122.2890558),
                    (37.8279634, -122.2893052), (37.8280475, -122.288937),
                    (37.8287455, -122.2891528), (37.8290338, -122.2886093),
                    (37.8291819, -122.2886597)]

        find_route_coordinates = _mock_find_route_coordinates
コード例 #36
0
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()
        app.config['TESTING'] = True

        # Make mock of Google Flights API call
        def _mock_flight_results(parameter):
            return functions.flight_results_from_file(
                'seed_data/testflights.txt')

        functions.flight_results = _mock_flight_results

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()
コード例 #37
0
ファイル: test.py プロジェクト: DrewForeman/project_tagline
    def setUp(self):
        """Set up test database and mock api result."""

        self.client = app.test_client()
        app.config['TESTING'] = True
        connect_to_db(app, "postgresql:///testdb")

        db.create_all()
        example_data()

        # Make mock 
        def _mock_find_route_coordinates(origin, destination):

            return [(37.8067567, -122.2961741), (37.8070326, -122.2974171), 
                    (37.8167166, -122.2896513), (37.8276755, -122.2890558), 
                    (37.8279634, -122.2893052), (37.8280475, -122.288937), 
                    (37.8287455, -122.2891528), (37.8290338, -122.2886093), 
                    (37.8291819, -122.2886597)]

        find_route_coordinates = _mock_find_route_coordinates
コード例 #38
0
    def setUp(self):
        """Stuff to do before every test."""

        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'key'
        self.client = app.test_client()

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        # Add user to session
        user = User.query.filter_by(email='*****@*****.**').first()

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user'] = user.user_id
コード例 #39
0
    def setUp(self):
        """ Things to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testfood")

        # Create tables and add sample data
        db.create_all()
        example_data()

        # Create a session
        app.config['SECRET_KEY'] = os.environ["testing_secret_key"]

        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1
コード例 #40
0
ファイル: tests.py プロジェクト: dencynluv/testing-flask
    def setUp(self):
        """Stuff to do before every test."""

        # creating a test client that we can test. A pretend browser (headless browser)
        self.client = app.test_client()
        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = "SECRETSECRETSECRET"

        # creates a fake session in our browser so test_games can run
        with self.client as c:
            with c.session_transaction() as sess:
                # creating an RSVP session from line 26 in party.py
                sess['RSVP'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        db.create_all()  #opens session
        example_data()
コード例 #41
0
    def setUp(self):
        """ stuff to do before every test """

        self.client = app.test_client()
        # getting flask test client
        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = 'supersecret'

        # connects to database
        connect_to_db(app, "postgresql:///testdb")

        db.create_all()
        example_data()
        # import pdb; pdb.set_trace()

        with self.client as c:
            with c.session_transaction() as sess:

                sess['name'] = 'Harry'
                sess['id'] = 1
コード例 #42
0
ファイル: tests.py プロジェクト: s-gerrity/hb-demos
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()

        # Show Flask errors that happen during tests
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        # Make mock
        def _mock_state_to_code(state_name):
            return "CA"

        server.state_to_code = _mock_state_to_code
コード例 #43
0
ファイル: tests.py プロジェクト: tien-han/Testing-Py-2
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # reset our sample database
        # Game.query.delete()
        # db.session.commit()

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")


        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data("Chess", "A 2-person game of strategy.")

        with self.client as c:
            with c.session_transaction() as sess:
                sess['RSVP'] = True
コード例 #44
0
    def setUp(self):
        """To do before every test"""

        #Get the Flask test client
        self.client = app.test_client()

        #Show Flask errors that happen during tests
        app.config['TESTING'] = True
        app.config['SECRET KEY'] = 'thisisasecret'

        #Connect to testdb
        connect_to_db(app, "postgresql:///testdb")

        db.create_all()
        example_data()

        #only allow access to page if user is logged in
        with self.client as c:
            with c.session_transaction() as sess:
                sess['username'] = '******'
                sess['user_id'] = 1
コード例 #45
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        # Add an attribute for scores and n_scores to every product
        products = Product.query.all()

        for p in products:
            scores = p.calculate_score_distribution()
            p.scores = json.dumps(scores)
            p.n_scores = sum(scores)

            db.session.commit()
コード例 #46
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        p = Product.query.get("A1")
        scores = p.calculate_score_distribution()
        p.scores = json.dumps(scores)
        p.n_scores = sum(scores)
        p.pg_score = p.calculate_pg_score()
        p.pos_words = []
        p.neg_words = []

        db.session.commit()
コード例 #47
0
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()

        # Show Flask errors that happen during tests
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()

        def f_date():
            assert datetime.datetime.now() == datetime.datetime(2017, 10, 31)

        def _mock_post_add_image(project, user, up_image):
            pass

        api.post_add_image = _mock_post_add_image

        def _mock_sync_update(user):
            return "test update"

        sync_projects = _mock_sync_update

        def _mock_post_project_api_update(project, up_notes,
                                          up_status, up_progress, user):
            pass

        api.post_project_api_update = _mock_post_project_api_update

        # add a session
        with self.client as c:
            with c.session_transaction() as sess:
                sess['user'] = 1
コード例 #48
0
ファイル: tests.py プロジェクト: ChloeCodesThings/LaterGator
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()
        app.config['TESTING'] = True

        app.config['SECRET_KEY'] = "ABCDEFG"

        # Connect to test database
        db_uri = os.environ.get("DATABASE_URL") or "postgresql:///testdb"
        connect_to_db(app, db_uri)

        # Create tables and add sample data
        db.create_all()
        example_data()

        with self.client.session_transaction() as session:

            user = User.query.first()
            user_id = user.user_id
            session['user_id'] = user_id
コード例 #49
0
ファイル: tests.py プロジェクト: lyoness1/frienergy
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = server.app.test_client()
        server.app.config['TESTING'] = True
        server.app.secret_key = "ABC"

        # Connect to test database
        connect_to_db(server.app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()

        # inputs sample data for testing from model.py
        example_data()

        # establish a client session for use in tests
        with self.client as c:
            with c.session_transaction() as sess:
                sess['logged_in_user_id'] = 1
                sess['logged_in_email'] = '*****@*****.**'
                sess['logged_in_user_name'] = 'First'
コード例 #50
0
    def test_get_edmunds_trims(self):
        result = self.client.post('/search/trim.json', data={'year': 1999, 'make': 'test', 'model': 'test'})
        print "{test_get_edmunds_trims ran}"


class Tests(unittest.TestCase):
    def setUp(self):
        self._old_db = model.db
        model.db = mock_db

    def tearDown(self):
        model.db = self._old_db


def connect_to_db(app):
    """ Connect the test database to test Flask app. """

    # Configure to use our PstgreSQL database
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testdb'
    mock_db.app = app
    mock_db.init_app(app)


if __name__ == "__main__":
    unittest.main()

    connect_to_db(app)
    mock_db.create_all()
    example_data()