Skip to content

Commit

Permalink
Merge branch origin/main into main via pull
Browse files Browse the repository at this point in the history
  • Loading branch information
klpulliam-37 committed May 7, 2023
2 parents 2c8fb08 + 4615087 commit db94cf6
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .flaskenv
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ POSTGRES_USER=adminadminSECURE!!!
POSTGRES_PASSWORD=ThisIsProductionBaby!!
POSTGRES_DB=greenwatch_production
SECRET_KEY=317aed4a0352d37253f433dc475fa5e7e306de7ad657add546d34f4e7c8b046c
SERVER_IP="127.0.0.1:5000"
SERVER_IP="40.112.52.52:80"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Within the [Docs](https://github.com/gramcracker40/GreenWatch/tree/main/docs) fo

## User Interface

In [UserInterface](https://github.com/gramcracker40/GreenWatch/tree/main/UserInterface) folder includes the code and images related to the User Interface.
The [UserInterface](https://github.com/gramcracker40/GreenWatch/tree/main/UserInterface) folder includes all of the static html files, the javascript files that manipulate DOM to create dynamic html files, and the css files that style the login page. There are also javascript utility scripts that include functions that are repeatedly used accross multiple files. The javascript files making the API fetch requests are also stored within the [UserInterface](https://github.com/gramcracker40/GreenWatch/tree/main/UserInterface) folder.

## Backend

Expand All @@ -29,6 +29,6 @@ In [UserInterface](https://github.com/gramcracker40/GreenWatch/tree/main/UserInt

- [Garrett Mathers](https://github.com/gramcracker40): Project Lead & Backend
- [Kolten Pulliam](https://github.com/klpulliam-37): API & Frontend
- [Derrick Pollock](https://github.com/derrk): Frontend & GUI
- [Derrick Pollock](https://github.com/derrk): Frontend
- [Edwin Mondragon](https://github.com/Takaximos): Hardware
- [June Portillo](https://github.com/BastionWolf): Misc.
4 changes: 3 additions & 1 deletion UserInterface/js/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ export function toStandardTime(_hours) {
let hours = _hours;
let amPm = '';
if (hours > 12) {
amPm = 'AM';
amPm = 'PM';
hours -= 12;
} else if (hours == 0) {
amPm = 'AM';
hours = "12";
}else if (hours < 12) {
amPm = 'AM';
}else{
amPm = 'PM';
}
Expand Down
1 change: 1 addition & 0 deletions docs/Statement of Scope and Requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Binary file removed docs/UML Diagram.pdf
Binary file not shown.
Binary file removed docs/UMLdiagram.png
Binary file not shown.
3 changes: 3 additions & 0 deletions greenwatch_vm_connection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Below command will auto connect with a pre authenticated user to the VM running Greenwatch
ssh -i greenwatch_key.pem [email protected]
31 changes: 27 additions & 4 deletions testing/RouteTester.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import requests
import json
import re
import csv

test_url = "http://127.0.0.1:5000"
user = "tester"
passw = "testtest"


class RouteTester:
'''
Implements methods used to test the Greenwatch REST API
Expand All @@ -17,6 +17,8 @@ class RouteTester:
init --> pass the 'base_url' aka "IP:port"
as well as passing the username and password.
can be fed in automatically at start of app
will create fake user and also log them in, noting all key
values needed for later use
request --> used as a helper method for test_routes, able to be
given the data and intelligently form the requests
Expand Down Expand Up @@ -56,10 +58,14 @@ def __init__(self, base_url="127.0.0.1:5000", username="test", password="testtes
except KeyError as err:
print(f"Initialization of RouteTester: Error --> {err}")

except requests.exceptions.RequestException as err:
print(f"Request exception thrown, check IP address given; Error -> {err}")



def __del__(self):
'''
logs out the user created in __init__ for the tests and then deletes the user as well
logs out the fake user created in __init__ for the tests and then deletes it as well
'''
logout_url = self.base_url + "/logout"
del_url = self.base_url + f"/users/{self.fake_user_id}"
Expand Down Expand Up @@ -100,7 +106,7 @@ def request(self, uri:str, method:str, data:dict=None) -> dict:
return {"uri": uri, "method": method, "status_code": req.status_code, "data": obj}


def test_routes(self, file:str, dump:bool=True, json_file_save:str=None) -> dict:
def test_routes(self, file:str, dump:bool=True, json_file_save:str=None, csv_file_save:str=None) -> dict:
'''
file : str --> path to the formatted JSON file, examples below
dump : bool --> determines if test_routes dumps results to terminal
Expand Down Expand Up @@ -208,13 +214,30 @@ def test_routes(self, file:str, dump:bool=True, json_file_save:str=None) -> dict
file = open(f"{json_file_save}.json", "w")
json.dump(results, file, indent=2)

if csv_file_save:
file = open(f"{json_file_save}.csv", "w")
writer = csv.writer(file)

fields = ["Resource", "URI", "Method", "Status Code", "Data"]
writer.writerow(fields)

for resource in results:
for method in results[resource]:
try:
writer.writerow([method['uri'], method['method'],
method['status_code'], method['data']])
except KeyError:
writer.writerow([method['uri'], method['method'],
method['status_code'], method['error']])
print(f"Error: ---> {err}")
return results


test_file_name = "routes.json"

test = RouteTester(base_url=test_url, username=user, password=passw)
test_results = test.test_routes(test_file_name, dump=True, json_file_save="test_results")
test_results = test.test_routes(test_file_name, dump=True,
json_file_save="test_results", csv_file_save="test_results")

del test

Expand Down
3 changes: 3 additions & 0 deletions testing/test_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Resource,URI,Method,Status Code,Data
/greenhouses,GET,200,[]
/greenhouses,POST,201,"{'Success': True, 'greenhouse_id': 1}"
Expand Down
18 changes: 5 additions & 13 deletions testing/test_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,10 @@
"method": "GET",
"status_code": 200,
"data": [
{
"email": "[email protected]",
"first_name": "n",
"id": 1,
"is_admin": true,
"last_name": "o",
"username": "test2"
},
{
"email": "[email protected]",
"first_name": "test",
"id": 2,
"id": 1,
"is_admin": true,
"last_name": "name",
"username": "tester"
Expand All @@ -51,7 +43,7 @@
],
"USER": [
{
"uri": "/users/2",
"uri": "/users/1",
"method": "PATCH",
"status_code": 201,
"data": {
Expand Down Expand Up @@ -123,7 +115,7 @@
"data": {
"Success": true,
"agent_id": 1,
"private_key": "QSAV2NDJ9LWZC81NRFGURE0B9OSGRPVMEFZENC6OLIVMFBS2CPZTWQ9EEVM2",
"private_key": "YD0G4R9354O7Q3F67C4JKZ1RWPRJ2W8H9O8Q5HJFCY6EFNQXXTGZGAYTUXAO",
"room_id": 1,
"server_ip": "172.22.0.1"
}
Expand Down Expand Up @@ -164,8 +156,8 @@
"body": "Hello, I am another message of testing",
"id": 1,
"room_id": 1,
"timestamp": "2023-04-29T19:20:10.056921",
"user_id": 2
"timestamp": "2023-05-06T18:58:52.028006",
"user_id": 1
}
]
}
Expand Down

0 comments on commit db94cf6

Please sign in to comment.