Skip to content

Commit

Permalink
style: format code with Autopep8
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 861ab62 according to the output
from Autopep8.

Details: None
  • Loading branch information
deepsource-autofix[bot] committed Dec 16, 2023
1 parent 861ab62 commit 41e1a0a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
14 changes: 8 additions & 6 deletions server.py
Expand Up @@ -10,7 +10,6 @@
states = {}



@app.route('/set/<pin:int>/<state:int>')
def set(pin, state):
if pin not in pins:
Expand All @@ -22,10 +21,11 @@ def set(pin, state):
states[pin] = state
return "pin "+str(pin)+" changed to "+str(states[pin])


@app.get('/setAll/<state:int>')
def setAll(state):
if state not in (1,0):
abort(code=404, text= "invalid state "+str(state))
if state not in (1, 0):
abort(code=404, text="invalid state "+str(state))
gpio.output(pins, state)
for pin in states:
states[pin] = state
Expand Down Expand Up @@ -64,7 +64,9 @@ def switch(pin):
def index():
return static_file("index.html", root="static")

#create control route on /control
# create control route on /control


@app.get('/control')
def control():
return static_file("control.html", root="static")
Expand All @@ -77,11 +79,11 @@ def control():
for pin in pins:
states[pin] = defaultState

#setting up the pins
# setting up the pins
gpio.setmode(gpio.BOARD)
gpio.setup(pins, gpio.OUT, initial=defaultState)

#main server
# main server
run(app, server='paste', host='0', port=3000)

finally:
Expand Down
43 changes: 18 additions & 25 deletions tests/test_unittest.py
@@ -1,13 +1,12 @@
import unittest
import http.client


class Test_TestAPI(unittest.TestCase):

@classmethod
def setUpClass(self):
self.conn = http.client.HTTPConnection("localhost:3000")



def test_connexion(self):
self.conn.request("GET", "/")
Expand All @@ -19,64 +18,58 @@ def test_control(self):
res = self.conn.getresponse()
self.assertEqual(res.status, 200)


def test_setWrongPin(self):
self.conn.request("GET","/set/14/0")
self.conn.request("GET", "/set/14/0")
res = self.conn.getresponse()
self.assertEqual(res.status,404)
self.assertEqual(res.status, 404)

def test_setWrongState(self):
self.conn.request("GET","/set/11/2")
self.conn.request("GET", "/set/11/2")
res = self.conn.getresponse()
self.assertEqual(res.status,400)
self.assertEqual(res.status, 400)

def test_set(self):
self.conn.request("GET","/set/11/1")
self.conn.request("GET", "/set/11/1")
res = self.conn.getresponse()
self.assertEqual(res.status,200)
self.assertEqual(res.status, 200)

self.conn.request("GET","/set/11/0")
self.conn.request("GET", "/set/11/0")
res = self.conn.getresponse()
self.assertEqual(res.status,200)


self.assertEqual(res.status, 200)

def test_pins(self):
self.conn.request("GET", "/pins")
res = self.conn.getresponse()
self.assertEqual(res.status,200)


self.assertEqual(res.status, 200)

def test_getAll(self):
self.conn.request("GET", "/get")
res = self.conn.getresponse()
self.assertEqual(res.status,200)
self.assertEqual(res.status, 200)

def test_getWrongPin(self):
self.conn.request("GET", "/get/14")
res = self.conn.getresponse()
self.assertEqual(res.status,404)
self.assertEqual(res.status, 404)

def test_getPin(self):
self.conn.request("GET", "/get/11")
res = self.conn.getresponse()
self.assertEqual(res.status,200)


self.assertEqual(res.status, 200)

def test_switchWrongPin(self):
self.conn.request("GET", "/switch/14")
res = self.conn.getresponse()
self.assertEqual(res.status,404)
self.assertEqual(res.status, 404)

def test_switch(self):
self.conn.request("GET", "/switch/11")
res = self.conn.getresponse()
self.assertEqual(res.status,200)
self.assertEqual(res.status, 200)
self.conn.request("GET", "/switch/11")
res = self.conn.getresponse()
self.assertEqual(res.status,200)
self.assertEqual(res.status, 200)


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 41e1a0a

Please sign in to comment.