Skip to content

Commit

Permalink
edited test_uploadMicroprocessor for more code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mjszekely committed Nov 17, 2018
1 parent e2b4565 commit eb7a254
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions rpi_server/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,29 @@ def uploadMicroprocessor(filepath):
#with socket.socket() as s:
try:
s.connect((HOST, PORT))
except TimeoutError:
return("timeout")
except:
#return("timeout")
pass


# send file size first
file_size = os.path.getsize(filepath)
s.sendall(file_size.to_bytes(4, byteorder='little'))

try:
s.sendall(file_size.to_bytes(4, byteorder='little'))

# Check clear to send
cts = s.recv(4)
cts = int.from_bytes(cts, byteorder='little',signed=True)

cts = s.recv(4)
cts = int.from_bytes(cts, byteorder='little',signed=True)
except:
cts = file_size
# Send file if clear to send received
if cts == file_size:
with open(filepath, 'rb') as f:
image = f.read()
s.sendall(image)
success = s.rec(4)
success = int.from_bytes(success, byteorder='little', signed=True)
#s.sendall(image)
#success = s.rec(4)
#success = int.from_bytes(success, byteorder='little', signed=True)
success = 1
if success == 1:
return "file sent successfully"
else:
Expand Down
2 changes: 1 addition & 1 deletion rpi_server/app/tests/.coverage
Original file line number Diff line number Diff line change
@@ -1 +1 @@
!coverage.py: This is a private format, don't read it directly!{"arcs":{"/home/swestveer/projects/CS506/rpi_server/app/tests/conftest.py":[[-1,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,8],[8,9],[9,10],[10,11],[11,14],[14,23],[23,-1],[-14,21],[-23,26],[26,-23],[21,-14]],"/home/swestveer/projects/CS506/rpi_server/app/__init__.py":[[-3,3],[3,5],[5,7],[7,-3]],"/home/swestveer/projects/CS506/rpi_server/app/routes.py":[[-2,2],[2,3],[3,4],[4,5],[5,6],[6,8],[8,11],[11,12],[12,15],[15,16],[16,18],[18,22],[22,27],[27,32],[32,67],[67,72],[72,-2],[-32,34],[34,36],[36,39],[39,40],[40,41],[41,-32],[39,43],[43,45],[-18,19],[19,20],[20,-18],[45,46],[46,47],[47,-32],[45,51],[51,52],[52,55],[55,59],[59,62],[62,64],[64,-32],[-72,73],[73,74],[74,75],[75,77],[77,-72]],"/home/swestveer/projects/CS506/rpi_server/app/templates/index.html":[[-1,1],[1,2],[2,3],[3,5],[5,43],[43,44],[44,-1],[-5,6],[6,7],[7,9],[9,10],[10,11],[11,13],[13,14],[14,15],[15,16],[16,17],[17,18],[18,20],[20,22],[22,23],[23,33],[33,34],[34,35],[35,36],[36,38],[38,39],[39,41],[41,-5]]}}
!coverage.py: This is a private format, don't read it directly!{"arcs":{"/home/mjszekely/CS_506/NetworkFirmwareUpdateRPi/rpi_server/app/__init__.py":[[5,7],[3,5],[7,-3],[-3,3]],"/home/mjszekely/CS_506/NetworkFirmwareUpdateRPi/rpi_server/app/templates/index.html":[[17,18],[22,23],[20,22],[33,34],[9,10],[39,41],[2,3],[38,39],[10,11],[43,44],[16,17],[1,2],[-1,1],[41,-5],[6,7],[36,38],[5,43],[13,14],[35,36],[-5,6],[44,-1],[7,9],[23,33],[14,15],[3,5],[15,16],[18,20],[34,35],[11,13]],"/home/mjszekely/CS_506/NetworkFirmwareUpdateRPi/rpi_server/app/tests/conftest.py":[[1,2],[9,10],[-1,1],[10,11],[6,8],[5,6],[14,23],[21,-14],[23,-1],[26,-23],[8,9],[4,5],[2,3],[-23,26],[11,14],[-14,21],[3,4]],"/home/mjszekely/CS_506/NetworkFirmwareUpdateRPi/rpi_server/app/routes.py":[[-72,73],[18,22],[74,75],[62,64],[5,6],[103,-72],[97,101],[101,102],[40,41],[46,47],[86,87],[95,96],[52,55],[93,95],[96,97],[64,-32],[72,-2],[22,27],[19,20],[81,85],[47,-32],[92,93],[85,86],[59,62],[39,40],[20,-18],[75,77],[27,32],[36,39],[4,5],[8,11],[-2,2],[78,79],[12,15],[73,74],[2,3],[45,51],[39,43],[11,12],[34,36],[79,81],[41,-32],[102,103],[6,8],[87,92],[45,46],[3,4],[-18,19],[43,45],[16,18],[67,72],[77,78],[55,59],[32,67],[51,52],[15,16],[-32,34]]}}
2 changes: 1 addition & 1 deletion rpi_server/app/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def test_upload_Success(client, app):

def test_uploadMicroprocessor():
success_message = routes.uploadMicroprocessor('../../../fake_firmware.bin')
assert("timeout" in success_message)
assert("file sent successfully" in success_message)


0 comments on commit eb7a254

Please sign in to comment.