Skip to content

Commit

Permalink
Merge pull request #106 from seng499-company2/integration-test
Browse files Browse the repository at this point in the history
Integration test
  • Loading branch information
Russell-Waterhouse authored Jul 19, 2022
2 parents ba6fe6d + 0c6b096 commit 09bc30c
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 139 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ data/
.idea/
.env.*
/schedule.json
/.db_init_done
67 changes: 32 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,29 @@ Company 2's back-end system
# Running the application

This is a Django application, where Scheduler is considered the main project. It is broken up into 4 apps:
* Users
* Courses
* Preferences
* Schedule

- Users
- Courses
- Preferences
- Schedule

This application uses Django 4.0, which requires Python >=3.8. This application uses PostgreSQL; to run migrations, see [Database Migrations](#database-migrations).
This application uses Django 4.0, which requires Python >=3.8. This application uses PostgreSQL; to run migrations, see [Database Migrations](#database-migrations).

## Docker

To run the application, first make sure you have [docker](https://docs.docker.com/desktop/) and [docker compose](https://docs.docker.com/compose/install/) installed.

To build and run the application, from the root directory run:

```
docker-compose up --build //Add -d flag to run the containers in the background (detached mode)
```

Now in a separate terminal, apply any missing migrations using the command. The scheduler_service will say `You have # unapplied migration(s)` when starting the docker container if you are missing them.

```
docker-compose exec web python manage.py migrate
```

Then go to [http://localhost:8000/](http://localhost:8000/) to see the Django app up and running.
Then go to [http://localhost:8000/](http://localhost:8000/) to see the Django app up and running.
To stop the docker containers either use `ctrl c` if not running in detached mode or use the command

```
docker-compose down # Add -v flag to remove the volumes along with the containers
```
Expand All @@ -40,7 +36,7 @@ When developing the app, if you add or modify models, you will have to apply the

## Testing

To test the application, ensure that the app is running with [docker](Docker). Then open up a new terminal.
To test the application, ensure that the app is running with [docker](Docker). Then open up a new terminal.

Then within the root folder, run the command

Expand All @@ -56,40 +52,47 @@ To run a specific app's test cases, use the command
docker-compose exec web python manage.py test <app_name>
```

OR alternatively, on Unix-like systems:
OR alternatively, on Unix-like systems:

```
$ ./test.sh
```
```

will bring up all docker containers, run the tests, and teardown the docker containers.
will bring up all docker containers, run the tests, and teardown the docker containers.

# Development

Since the app has been containerized, any changes that you make will be picked up by docker as long as the app is running.
Since the app has been containerized, any changes that you make will be picked up by docker as long as the app is running.

## Resetting the Database

If you have a lot of database migrations, you may just want to start with a fresh instance of the db.
First, nuke the postgres docker container volume with the current database data:

If you have a lot of database migrations, you may just want to start with a fresh instance of the db.
First, nuke the postgres docker container volume with the current database data:
```
sudo rm -rf data
```

Then, rebuild the docker containers:

Then, rebuild the docker containers:
```
docker-compose up -d --build
```

After the containers come up, create the new database schema:

After the containers come up, create the new database schema:
```
docker-compose exec web python manage.py makemigrations
docker-compose exec web python manage.py migrate
```

To populate the database with values, run the bash script

```
./init_db.sh
```

The script populates the database and writes to the `data/` directory. The script makes sure the initialization is only one once.
If run a second time, the script would skip the initialization step.

To force an init, reset the database again (as described above)


To populate the database with values, run the bash script

```
Expand Down Expand Up @@ -127,14 +130,12 @@ This will take all the migrations that haven't been applied and runs them agains

For development purposes, The PostgreSQL can be connected to via its Docker container shell, to view database contents or metadata. To get a bash shell, run:

On Mac Environments:

On Mac Environments:
```
docker exec -it back-end_db_1 /bin/bash
```

On Linux Environments:

On Linux Environments:
```
docker exec -it back-end-db-1 /bin/bash
```
Expand All @@ -148,22 +149,18 @@ psql -h localhost -U postgres
From here, a connection should be established to the database, and standard PostgreSQL commands should function correctly.

## Admin Endpoint

Django created a useful admin interface where you can manage the data in the application. It can be reached by the admin endpoint `(/admin/)` which allows you view your data and modify it as needed.

To access this interface create an admin user in the database. This can be done with the command:

```
docker-compose exec web python manage.py createsuperuser --email admin@example.com --username admin
```
It will ask you to insert a password. Please remember the password as you will use it to login.

It will ask you to insert a password. Please remember the password as you will use it to login.

To view data from the admin interface, it needs to be registered within the app's admin file. Please check out the [Django Documentation](https://docs.djangoproject.com/en/4.0/intro/tutorial02/#introducing-the-django-admin) for an example and more information. Once it is setup, go to [http://localhost:8000/admin](http://localhost:8000/admin) to access it.
To view data from the admin interface, it needs to be registered within the app's admin file. Please check out the [Django Documentation](https://docs.djangoproject.com/en/4.0/intro/tutorial02/#introducing-the-django-admin) for an example and more information. Once it is setup, go to [http://localhost:8000/admin](http://localhost:8000/admin) to access it.

### Please Note

If you intend to use this admin user for testing purposes, please create the an associated App User for it or else you may run into issues. This can be done in the admin interface by adding a new App User and selecting `admin` as the user.
If you intend to use this admin user for testing purposes, please create the an associated App User for it or else you may run into issues. This can be done in the admin interface by adding a new App User and selecting `admin` as the user.

## Running production

Expand Down
110 changes: 55 additions & 55 deletions db_initialization/schedule_courses.csv
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
string,string,string,boolean (optional),boolean (optional),boolean (optional),integer,integer ( 1 or 2),string (optional),string (optional),integer (optional),"enum(""TWF"", ""MTh"", ""M"", ""T"", ""W"", ""Th"", ""F"") (optional)",custom (optional),string (optional),string (optional),integer (optional will be used for multiple section generation),"enum(""TWF"", ""MTh"", ""M"", ""T"", ""W"", ""Th"", ""F"") (optional)",custom (optional)
semester,code,title,pengRequired.fall,pengRequired.spring,pengRequired.summer,yearRequired,numberOfSections,professor.id,professor.name,capacity,days (will be used to create dayOfTheWeek),timeRange (start and end separated by ~),professor.id,professor.name,capacity,days (will be used to create dayOfTheWeek),timeRange (start and end separated by ~)
fall,CSC111,Fundamentals of Programming with Engineering Applications,TRUE,TRUE,,1,2,,,140,,,,,80,,
spring,CSC111,Fundamentals of Programming with Engineering Applications,TRUE,TRUE,,1,2,,,60,,,,,100,,
fall,CSC115,Fundamentals of Programming II,TRUE,TRUE,TRUE,1,2,,,60,,,,,60,,
spring,CSC115,Fundamentals of Programming II,TRUE,TRUE,TRUE,1,2,,,60,,,,,80,,
summer,CSC115,Fundamentals of Programming II,TRUE,TRUE,TRUE,1,2,,,120,,,,,60,,
fall,CSC230,Introduction to Computer Architecture,TRUE,FALSE,FALSE,2,2,,,120,,,,,60,,
spring,CSC230,Introduction to Computer Architecture,TRUE,FALSE,FALSE,2,2,,,140,,,,,60,,
summer,CSC230,Introduction to Computer Architecture,TRUE,FALSE,FALSE,2,2,,,100,,,,,60,,
fall,ECE255,Introduction to Computer Architecture,FALSE,FALSE,FALSE,2,2,,,120,,,,,140,,
fall,ECE260,Continuous-Time Signals and Systems,FALSE,,FALSE,2,2,,,80,,,,,100,,
summer,ECE260,Continuous-Time Signals and Systems,FALSE,,FALSE,2,2,,,100,,,,,80,,
fall,SENG265,Software Development Methods,TRUE,FALSE,FALSE,2,2,,,140,,,,,80,,
spring,SENG265,Software Development Methods,TRUE,FALSE,FALSE,2,2,,,120,,,,,80,,
summer,SENG265,Software Development Methods,TRUE,FALSE,FALSE,2,2,,,120,,,,,120,,
fall,CSC225,Algorithms and Data Structures I,FALSE,FALSE,FALSE,2,2,,,140,,,,,60,,
spring,CSC225,Algorithms and Data Structures I,FALSE,FALSE,FALSE,2,2,,,120,,,,,100,,
summer,CSC225,Algorithms and Data Structures I,FALSE,FALSE,FALSE,2,2,,,60,,,,,80,,
spring,ECE310,Digital Signal Processing I,,FALSE,FALSE,2,2,,,80,,,,,100,,
summer,ECE310,Digital Signal Processing I,,FALSE,FALSE,2,2,,,60,,,,,100,,
spring,SENG275,Software Testing,,TRUE,TRUE,2,2,,,100,,,,,120,,
summer,SENG275,Software Testing,,TRUE,TRUE,2,2,,,60,,,,,120,,
fall,SENG310,Human Computer Interaction,TRUE,TRUE,TRUE,2,2,,,140,,,,,80,,
spring,SENG310,Human Computer Interaction,TRUE,TRUE,TRUE,2,2,,,120,,,,,120,,
summer,SENG310,Human Computer Interaction,TRUE,TRUE,TRUE,2,2,,,100,,,,,80,,
spring,ECE458,Communication Networks,FALSE,FALSE,,3,2,,,60,,,,,60,,
fall,CSC361,Computer Communications and Networks,FALSE,TRUE,,3,2,,,100,,,,,80,,
spring,CSC361,Computer Communications and Networks,FALSE,TRUE,,3,2,,,120,,,,,140,,
fall,CSC226,Algorithms and Data Structures II,FALSE,FALSE,FALSE,3,2,,,60,,,,,120,,
spring,CSC226,Algorithms and Data Structures II,FALSE,FALSE,FALSE,3,2,,,140,,,,,100,,
summer,CSC226,Algorithms and Data Structures II,FALSE,FALSE,FALSE,3,2,,,100,,,,,120,,
fall,ECE360,Control Theory and Systems I,FALSE,FALSE,,3,2,,,60,,,,,60,,
spring,ECE360,Control Theory and Systems I,FALSE,FALSE,,3,2,,,60,,,,,80,,
fall,SENG321,Requirements Engineering,TRUE,TRUE,,3,2,,,60,,,,,120,,
spring,SENG321,Requirements Engineering,TRUE,TRUE,,3,2,,,100,,,,,100,,
spring,SENG371,Software Evolution,FALSE,TRUE,,3,2,,,80,,,,,100,,
fall,ECE355,Microprocessor-Based Systems,FALSE,,,3,2,,,100,,,,,60,,
fall,CSC355,Digital Logic and Computer Organization,FALSE,,,3,2,,,120,,,,,120,,
fall,CSC320,Foundations of Computer Science,FALSE,FALSE,FALSE,3,2,,,140,,,,,140,,
spring,CSC320,Foundations of Computer Science,FALSE,FALSE,FALSE,3,2,,,100,,,,,120,,
summer,CSC320,Foundations of Computer Science,FALSE,FALSE,FALSE,3,2,,,120,,,,,80,,
fall,CSC360,Operating Systems,TRUE,TRUE,FALSE,3,2,,,100,,,,,60,,
spring,CSC360,Operating Systems,TRUE,TRUE,FALSE,3,2,,,100,,,,,140,,
summer,CSC360,Operating Systems,TRUE,TRUE,FALSE,3,2,,,120,,,,,100,,
fall,CSC370,Database Systems,FALSE,FALSE,FALSE,3,2,,,120,,,,,60,,
spring,CSC370,Database Systems,FALSE,FALSE,FALSE,3,2,,,120,,,,,120,,
summer,CSC370,Database Systems,FALSE,FALSE,FALSE,3,2,,,140,,,,,140,,
fall,SENG350,Software Architecture and Design,FALSE,,,3,2,,,80,,,,,140,,
fall,SENG360,Security Engineering,FALSE,,,3,2,,,140,,,,,120,,
summer,SENG426,Software Quality Engineering,,,FALSE,4,2,,,60,,,,,140,,
summer,SENG440,Embedded Systems,,,FALSE,4,2,,,100,,,,,80,,
summer,SENG499,Design Project II,,,FALSE,4,2,,,60,,,,,140,,
spring,ECE455,Real-Time Computer Systems Design Project,,FALSE,,4,2,,,60,,,,,100,,
spring,CSC460,Design and Analysis of Real-time Systems,,TRUE,,4,2,,,100,,,,,60,,
spring,SENG401,Social and Professional Issues,,FALSE,,4,2,,,120,,,,,100,,
fall,CSC111,Fundamentals of Programming with Engineering Applications,TRUE,TRUE,,1,2,,,0,,,,,0,,
spring,CSC111,Fundamentals of Programming with Engineering Applications,TRUE,TRUE,,1,2,,,0,,,,,0,,
fall,CSC115,Fundamentals of Programming II,TRUE,TRUE,TRUE,1,2,,,0,,,,,0,,
spring,CSC115,Fundamentals of Programming II,TRUE,TRUE,TRUE,1,2,,,0,,,,,0,,
summer,CSC115,Fundamentals of Programming II,TRUE,TRUE,TRUE,1,2,,,0,,,,,0,,
fall,CSC230,Introduction to Computer Architecture,TRUE,FALSE,FALSE,2,2,,,0,,,,,0,,
spring,CSC230,Introduction to Computer Architecture,TRUE,FALSE,FALSE,2,2,,,0,,,,,0,,
summer,CSC230,Introduction to Computer Architecture,TRUE,FALSE,FALSE,2,2,,,0,,,,,0,,
fall,ECE255,Introduction to Computer Architecture,FALSE,FALSE,FALSE,2,2,,,0,,,,,0,,
fall,ECE260,Continuous-Time Signals and Systems,FALSE,,FALSE,2,2,,,0,,,,,0,,
summer,ECE260,Continuous-Time Signals and Systems,FALSE,,FALSE,2,2,,,0,,,,,0,,
fall,SENG265,Software Development Methods,TRUE,FALSE,FALSE,2,2,,,0,,,,,0,,
spring,SENG265,Software Development Methods,TRUE,FALSE,FALSE,2,2,,,0,,,,,0,,
summer,SENG265,Software Development Methods,TRUE,FALSE,FALSE,2,2,,,0,,,,,0,,
fall,CSC225,Algorithms and Data Structures I,FALSE,FALSE,FALSE,2,2,,,0,,,,,0,,
spring,CSC225,Algorithms and Data Structures I,FALSE,FALSE,FALSE,2,2,,,0,,,,,0,,
summer,CSC225,Algorithms and Data Structures I,FALSE,FALSE,FALSE,2,2,,,0,,,,,0,,
spring,ECE310,Digital Signal Processing I,,FALSE,FALSE,2,2,,,0,,,,,0,,
summer,ECE310,Digital Signal Processing I,,FALSE,FALSE,2,2,,,0,,,,,0,,
spring,SENG275,Software Testing,,TRUE,TRUE,2,2,,,0,,,,,0,,
summer,SENG275,Software Testing,,TRUE,TRUE,2,2,,,0,,,,,0,,
fall,SENG310,Human Computer Interaction,TRUE,TRUE,TRUE,2,2,,,0,,,,,0,,
spring,SENG310,Human Computer Interaction,TRUE,TRUE,TRUE,2,2,,,0,,,,,0,,
summer,SENG310,Human Computer Interaction,TRUE,TRUE,TRUE,2,2,,,0,,,,,0,,
spring,ECE458,Communication Networks,FALSE,FALSE,,3,2,,,0,,,,,0,,
fall,CSC361,Computer Communications and Networks,FALSE,TRUE,,3,2,,,0,,,,,0,,
spring,CSC361,Computer Communications and Networks,FALSE,TRUE,,3,2,,,0,,,,,0,,
fall,CSC226,Algorithms and Data Structures II,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
spring,CSC226,Algorithms and Data Structures II,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
summer,CSC226,Algorithms and Data Structures II,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
fall,ECE360,Control Theory and Systems I,FALSE,FALSE,,3,2,,,0,,,,,0,,
spring,ECE360,Control Theory and Systems I,FALSE,FALSE,,3,2,,,0,,,,,0,,
fall,SENG321,Requirements Engineering,TRUE,TRUE,,3,2,,,0,,,,,0,,
spring,SENG321,Requirements Engineering,TRUE,TRUE,,3,2,,,0,,,,,0,,
spring,SENG371,Software Evolution,FALSE,TRUE,,3,2,,,0,,,,,0,,
fall,ECE355,Microprocessor-Based Systems,FALSE,,,3,2,,,0,,,,,0,,
fall,CSC355,Digital Logic and Computer Organization,FALSE,,,3,2,,,0,,,,,0,,
fall,CSC320,Foundations of Computer Science,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
spring,CSC320,Foundations of Computer Science,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
summer,CSC320,Foundations of Computer Science,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
fall,CSC360,Operating Systems,TRUE,TRUE,FALSE,3,2,,,0,,,,,0,,
spring,CSC360,Operating Systems,TRUE,TRUE,FALSE,3,2,,,0,,,,,0,,
summer,CSC360,Operating Systems,TRUE,TRUE,FALSE,3,2,,,0,,,,,0,,
fall,CSC370,Database Systems,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
spring,CSC370,Database Systems,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
summer,CSC370,Database Systems,FALSE,FALSE,FALSE,3,2,,,0,,,,,0,,
fall,SENG350,Software Architecture and Design,FALSE,,,3,2,,,0,,,,,0,,
fall,SENG360,Security Engineering,FALSE,,,3,2,,,0,,,,,0,,
summer,SENG426,Software Quality Engineering,,,FALSE,4,2,,,0,,,,,0,,
summer,SENG440,Embedded Systems,,,FALSE,4,2,,,0,,,,,0,,
summer,SENG499,Design Project II,,,FALSE,4,2,,,0,,,,,0,,
spring,ECE455,Real-Time Computer Systems Design Project,,FALSE,,4,2,,,0,,,,,0,,
spring,CSC460,Design and Analysis of Real-time Systems,,TRUE,,4,2,,,0,,,,,0,,
spring,SENG401,Social and Professional Issues,,FALSE,,4,2,,,0,,,,,0,,
fall,ENGR110,Design and Communication I,,,,1,2,100,Static Prof 1,60,TWF,8:30~9:20,100,Static Prof 1,80,TWF,8:30~9:20
fall,ENGR130,Introduction to Professional Practice,,,,1,2,101,Static Prof 2,100,MTh,8:30~9:50,101,Static Prof 2,80,MTh,8:30~9:50
spring,ENGR130,Introduction to Professional Practice,,,,1,2,101,Static Prof 2,100,TWF,8:30~9:20,101,Static Prof 2,140,TWF,8:30~9:20
Expand Down Expand Up @@ -83,4 +83,4 @@ fall,STAT260,Introduction to Probability and Statistics I,,,,2,2,112,Static Prof
spring,STAT260,Introduction to Probability and Statistics I,,,,2,2,112,Static Prof 13,140,MTh,8:30~9:50,112,Static Prof 13,120,MTh,8:30~9:50
summer,STAT260,Introduction to Probability and Statistics I,,,,2,2,112,Static Prof 13,100,TWF,9:30~10:20,112,Static Prof 13,60,TWF,9:30~10:20
fall,ECON180,Introduction to Principles of Microeconomics and Financial Project Evaluation,,,,2,2,113,Static Prof 14,100,MTh,10:00~11:20,113,Static Prof 14,80,MTh,10:00~11:20
summer,ECON180,Introduction to Principles of Microeconomics and Financial Project Evaluation,,,,2,2,113,Static Prof 14,140,MTh,10:00~11:20,113,Static Prof 14,60,MTh,10:00~11:20
summer,ECON180,Introduction to Principles of Microeconomics and Financial Project Evaluation,,,,2,2,113,Static Prof 14,140,MTh,10:00~11:20,113,Static Prof 14,60,MTh,10:00~11:20
4 changes: 1 addition & 3 deletions init_db.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/bin/bash
cd data

FILE=.db_init_done
if [ -f "$FILE" ]; then
echo "db already initialized... skipping"
else
cd ../
docker compose run web python initialize.py
cd data
touch .db_init_done
fi
47 changes: 47 additions & 0 deletions integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/bash

echo '------------------------------------'
echo '| Starting Integration Test |'
echo '------------------------------------'

docker-compose up -d

sleep 3

./init_db.sh

sleep 3

echo ' '
echo '------------------------------------'
echo '| Testing Company 2 |'
echo '------------------------------------'
echo ' '
echo ' '

curl http://localhost:8000/schedule/2022/FALL/2

echo ' '
echo ' '
echo ' '
echo '------------------------------------'
echo '| Testing Company 1 |'
echo '------------------------------------'
echo ' '
echo ' '
echo ' '

curl http://localhost:8000/schedule/2022/FALL/1


echo ' '
echo ' '
echo ' '
echo '------------------------------------'
echo '| Testing Complete |'
echo '------------------------------------'
echo ' '
echo ' '
echo ' '

docker-compose down
16 changes: 16 additions & 0 deletions rebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

docker-compose down

sudo rm -rf data

docker-compose up -d --build

docker-compose exec web python manage.py makemigrations
docker-compose exec web python manage.py migrate

rm .db_init_done

./init_db.sh

docker-compose down
4 changes: 2 additions & 2 deletions requirements-testpypi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Requirements from pypi should be in requirements.txt

--extra-index-url https://test.pypi.org/simple/
capacityforecaster==0.2.6 #Company 2 alg 2 (from pypi.org/simple/ index)
capacityforecaster==0.2.9 #Company 2 alg 2 (from pypi.org/simple/ index)

--extra-index-url https://test.pypi.org/simple/
c1algo2==0.0.7 #Company 1 alg 2 (from pypi.org/simple/ index)
c1algo2==0.0.10 #Company 1 alg 2 (from pypi.org/simple/ index)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pyjwt==2.4.0

# algorithms
coursescheduler==0.0.6 #Company 2 alg 1
c1algo1==2.0.3 # Company 1 alg 1
c1algo1==2.0.7 # Company 1 alg 1

# dependencies from c1algo2
numpy
Expand Down
6 changes: 5 additions & 1 deletion schedule/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def course_to_course_offering(course: Course) -> A_CourseOffering:


def add_course_offering_to_schedule(course: Course, a_course_offering: A_CourseOffering):
schedule, _ = A_Schedule.objects.get_or_create(id=0)
schedule = A_Schedule.objects.first()
if schedule is None:
print("ERROR: NO DATABASE DATA FOUND. HAVE YOU RUN init_db.sh?")
return None

if course.fall_offering:
schedule.fall.add(a_course_offering)
if course.spring_offering:
Expand Down
Loading

0 comments on commit 09bc30c

Please sign in to comment.