课程: SQL for Testers

Setting up a site for testing - SQL教程

课程: SQL for Testers

Setting up a site for testing

- [Instructor] Now that we have the basics of SQL under our belt, let's start to look at how to use SQL queries as a tester. I really firmly believe that you'll learn best if you can actually execute queries on your own and have a hands-on experience throughout this course. Now, in order to do that, you're going to need to set up some databases locally, but I didn't want this just to be about querying databases. As testers, we look at things in a holistic way. A database by itself can be interesting, but whenever we're looking at a database in our application, it's part of an ecosystem. The database provides data that is ultimately used by a client or user interface in some way. So in order to sort of replicate this, I put together a simple website that has a few database tables for various parts of the data, and it has a simple user interface on top of it that uses the data. Now, obviously this will be far less complex than a real e-commerce site would be, but it should help to make sure that the things that we learn in this course are applicable in the day-to-day work of a tester. I also want to acknowledge GitHub user, Himani13040, whose repo I initially forked off of before modifying this for our needs here. In order to use this site locally, you're going to need a few things. First of all, you'll need to have Python three installed on your computer. If you don't yet have it, you can get it from python.org/downloads and then download the latest version three release for your platform and install it like you would any other application. The site that we're using is built on a Python library called Flask. So once you have Python three installed, you can install Flask by using pip install flask, and then hitting Enter. PIP is just a tool that comes with Python that you can use to install additional packages like this Flask library. This command takes care of downloading and installing everything that you need for running Flask applications. One other library that you'll need to install as well is the Requests library, which you can install in the same way, pip install requests. So once those installs have completed, you'll need to get the application that you want to run, and you can get this from the ZIP files in the course, download and extract those into a folder on your computer. And then once you've done that, go to the command prompt and navigate to that folder. So you can use CD for Change Directory and then put in the path of that folder and hit Enter. So once you're in that folder, you'll need to set the values for a couple of environment variables. So these are the values that Flask will use when it's starting up. First of all, you're going to set the Flask app variable, and on my computer I can do that by calling export FLASK_APP. On Windows, you would probably do, set FLASK_APP, and then we're going to set the value of this variable to main. And similarly, I will also set the FLASK_ENV variable. And this one I will set to development, to let it know that we're working in a development environment. So once I've done that, I'm ready to start the application. And to do that, we can just type flask run, and then hit Enter. And you can see that it starts it up and the application is running on this URL. And if we load that URL in the web browser, you could see it here. Now this application uses some database tables, so let's connect to the database that is behind this site. To do that, I will open the database and choose database.db from the folder. And you can see that it has added these tables here for us in SQLiteStudio. Now, I have also provided a reset script that you can use to reset the database in case anything goes wrong. To run that script, simply go to Open SQL Files, and choose the DatabaseInitializationScript.sql file, open it, and then click on Run to run it, and it will initialize the database for you. So now you've got everything set up and ready to go for doing all kinds of cool testing with this application. Let's dive into that in the next video.

内容