This project was created with the following ideas:
-
Comply with the HTML/CSS requirements set forth by the Build a Survey Form project, which is the second project out of five, from FreeCodeCamp's (FCC) Responsive Web Design Certification, which can be found here. The strict HTML/CSS version of this project can be found in my CodePen here.
-
Build the Back End to the Survey Form.
-
Build a User Interface test, which would validate that the main html requirements set forth by FCC are maintained throughout.
The purpose of this project is to experience horizontal development, integrating all layers of the project:
- The user interface (HTML/CSS),
- Middleware (Flask), and
- Database (SQLite).
-
This project was done with Python 3.7.
-
Clone this repository locally. This is done by typing
git clone https://github.com/adriaanbd/simple_survey_form simple-survey
in your terminal. -
I'd recommend setting up a virtual environment, which is an isolated python environment in your chosen directory. Do this with
python venv myvenv
in your terminal. This will create a virtual environment calledmyvenv
. If you have other version of Python installed, you'd need to make sure that you are accessing the desiredpython
when typing that term. You can check this out by typingpython --version
. If it says 3.7, you're good to go. If not, typepy --version
, which should display 3.7 if you installed it succesfully. If so, then you'd need to setup your virtual environment with the following commanpy venv myvenv
. -
If you're using a Bash terminal, activate your virtual environment with
source venv/myvenv/activate
. If it doesn't work for you, please Google it online. There are plenty of resources available. -
Install all requirements. In your local directory where you cloned the repo, type
pip install -r requirements.txt
in your terminal.
-
From the terminal, run the command
flask db init
-
You should see a
migrations
folder in your root directory. -
Migrate your db by running
flask db migrate
-
You should see some new files in your
/migrations
folder -
Make the db setup permanent by running
flask db upgrade
-
From your terminal, run
flask shell
-
This will load all configuration values with access to the db model.
-
Enter and check the following:
>>> Voter.query.all()
[]
>>> v = Voter(name="John Doe", email="john@doe.com")
>>> v
<Voter John Doe>
>>> db.session.add(v)
>>> db.session.commit()
>>> a = Answer(age=31, gender='Male', path='Full Stack', voter=v)
>>> a
<Answer (31, 'Male', 'Full Stack')>
>>> a.voter
<Voter John Doe>
>>> db.session.add(a)
>>> db.session.commit()
>>> l = Language(language='Python', voter=v)
>>> l.language, l.voter
('Python', <Voter John Doe>)
>>> db.session.add(l)
>>> db.session.commit()
>>> c = Comment(comment='I love to code', voter=v)
>>> c.comment, c.voter
('I love to code', <Voter John Doe>)
>>> db.session.add(c)
>>> db.session.commit()
-
In your terminal, type
flask run
-
Either click on the link provided in your terminal
http://127.0.0.1:5000/
or insert it directly on your web browser.
-
Fill all the values in the form
-
Name and email are required values
-
Click on submit, at which point you should receive a "Your form was submitted" message in red.
-
flask shell
-
Run the following and check that the output is the same as the values you entered in the form.
>>>Voter.query.all()
>>>Answer.query.all()
>>>Language.query.all()
>>>Comment.query.all()
- Make sure your local server is running.
- In the terminal, type
python -m unittest
- Alternatively, you can run the file directly, typing:
python tests/test_survey_ui.py
I've used the page object design pattern, separating the location of the web
elements (located either by id, css selector, tag name) on the locators.py
file, the page method actions using those web elements on page.py
, and the
tests themselves on test_survey_ui.py
. Feel
free to look at them. The idea behind this separation, is that if something
changes to the html or css, the locators would only need to be updated in one
place.
Development is still in progress:
- Unittest will be replaced by pytest.
- More tests will be added.