- Explore and use various tools such as: GitHub, VirtualBox, Tuffix, Linux Terminal, and Atom.
- Write a Python program using:
- sqlite3
- Run and test a Python program.
-
Open the Terminal program in Tuffix.
-
Change the present working directory to the
Documents
directory by typing the following command at the command prompt:cd Documents
-
Make a copy of this Github repository on your computer using the
git
andclone
commands that you will input to the terminal. The commands take a URL as a parameter to specify where it can get a copy of the repository. You can find the URL by clicking on the green Clone or download button at the top right part of this page. Copy the URL and replace the example text shown below. Note thatusername
should be replaced with your own Github username. When you hit Enter it will ask you to provide your Github username and token. Once done, you will have a copy of the repository on your computer.git clone https://github.com/CSUF-CPSC223P-STMAY-2021F/lab11-username.git
-
Navigate into the new directory using the command line. Note that
username
should be replaced with your own Github username. As a shortcut, you can type the first few letters of the folder name and press Tab so that it auto completes the folder name for you.cd lab11-username
- Write a Python program that performs as a Tuffy Titan Contacts phone list. You are given the main.py file and are required to create the Contacts class.
- The following is the Entity-Relationship Diagram for the data structure:
- The following is some sample data to help visualize the data model:
- Create a
Contacts
class to meet the following requirements:- Create a file named
contacts.py
.- Define a method named
__init__
to meet the following requirements:- Declare a class variable to store the database file and intitialize it to an empty string.
- Define a method named
set_database_name
to meet the following requirements:- Take a database file name as a positional parameter and assign the value to the class variable.
- If the file already exists, do nothing (we want to preserve any data in the file for continued use.)
- If the file does not exisit, connect to the
sqlite3
file and create thecontacts
table and thephones
table using the proper SQLCREATE TABLE
statement. Use the same field names as those used in the Entity-Relationship diagram above. Use integers for all the id's and text for all the other data.
- Define a method named
get_database_name
to meet the following requirements:- Return the value of the class variable that stores the database name.
- Define a method named
add_contact
to meet the following requirements:- Take a first name and last name as positionals parameter.
- Insert the first name and last name into the contacts table using the SQL
INSERT INTO
statement.
- Define a method named
modify_contact
to meet the following requirements:- Take a contact id, first name, and last name as positionals parameter.
- Update the first name and last name of the cooresponding contact id in the contacts table using the SQL
UPDATE
statement.
- Define a method named
add_phone
to meet the following requirements:- Take a contact id, phone type, and phone number as positionals parameter.
- Insert the contact id, phone type, phone number into the phones table using the SQL
INSERT INTO
statement.
- Define a method named
modify_phone
to meet the following requirements:- Take a phone id, phone type, and phone number as positionals parameter.
- Update the phone type and phone number of the cooresponding phone id in the phones table using the SQL
UPDATE
statement.
- Define a method named
get_contact_phone_list
to meet the following requirements:- Return an array created from a query on the database using the SQL statement
SELECT contacts.*, phones.* FROM contacts LEFT JOIN phones ON contacts.contact_id=phones.contact_id
.
- Return an array created from a query on the database using the SQL statement
- Define a method named
- Create a file named
- Run the unit testing program to ensure that your program runs as expected.
The unit testing will output the results of a series of tests using specific input and expected output. Any error will provide information on where the expected output is different from the actual output. You will need to edit your source code to fix the error and run
.python3 test.py
./test.sh
repeatedly until it passes all the test.
Periodically throughout the exercise, and when you have completed the exercise, submit the complete repository to Github.
git add .
git commit -m "your comment"
git push
In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github token.
git config --global user.email "[email protected]"
git config --global user.name "Tuffy Titan"
git commit -m "your comment"
git push
When you completed the final Github push, go back into github.com through the browser interface and ensure all your files have been correctly updated. You should have the following files:
contacts.py
test.txt
- All points add up to a total of 100 points possible as detailed below. Partial credit will be given where applicable.
Points | Description |
---|---|
50 | initial git clone of this repository to your Tuffix machine |
5 | contacts.py file submitted contains the Contacts class and meets the program requirements |
10 | unit test passes Test01_ADD_CONTACT |
10 | unit test passes Test02_MODIFY_CONTACT |
10 | unit test passes Test03_ADD_PHONE |
10 | unit test passes Test04_MODIFY_PHONE |
5 | unit test passes Test05_GET_CONTACT_PHONE_LIST |