diff --git a/main.py b/main.py
index 10f53fb85c353d04e2b9463b44e2e70021664e99..8af2946eb8c9ac271e2750088c2aa476ec4680be 100755
--- a/main.py
+++ b/main.py
@@ -1,3 +1,6 @@
+#!/usr/bin/python3
+
+
 ### Functions included in README
 
 """
@@ -28,14 +31,14 @@ func = functions.modem_commands()
 
 try:
         modem=func.ready_modem()
-except Exception as err:
-        logger.error('Error starting modem: ', err)
+except IOError as err:
+        logger.error('Error starting modem: {}'.format(err))
 
 #Sends data to server ip defined in functions.py
 func.send_data_to_ip(modem, data)
 
-logger.info('Closing modem',modem.close())
-logger.info('Check modem local status ',modem.isOpen())
+logger.info('Closing modem {}'.format(modem.close()))
+logger.info('Check modem local status {}'.format(modem.isOpen()))
 
 """
 ping = functions.ping_server(modem)
@@ -48,4 +51,3 @@ else:
 print('SENT')
 modem.close()
 """
-
diff --git a/modemInterface/__init__.pyc b/modemInterface/__init__.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..23181344945413661171ac82a4a250ab10c02310
Binary files /dev/null and b/modemInterface/__init__.pyc differ
diff --git a/modemInterface/functions.py b/modemInterface/functions.py
index aa714085731eec362f874612b89343c0a5928dc4..533276dc3e9e36b66384920567fc9b37f7e9a04e 100755
--- a/modemInterface/functions.py
+++ b/modemInterface/functions.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+
 """
 functions.py
 
@@ -6,7 +8,6 @@ Functions for using NB-IoT modem
 import serial
 import binascii
 import logging.config
-
 from modemInterface import list_serials
 
 
@@ -144,8 +145,8 @@ class modem_commands():
                                             return modem
                                     #elif(check==''):
                                     #       print('Device in ', i, ' not modem')
-                            except Exception as err:
-                                    self.logger.error('ERROR in: find_usb_modem : ',err)
+                            except IOError as err:
+                                    raise IOError('ERROR in: find_usb_modem : {}'.format(err))
             return None
     
     def ping_server(self, modem):
diff --git a/modemInterface/functions.pyc b/modemInterface/functions.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..870e0526d20bf100868b44d1f725974273ecc516
Binary files /dev/null and b/modemInterface/functions.pyc differ
diff --git a/modemInterface/list_serials.py b/modemInterface/list_serials.py
index 471a2e3c4fee1c5a70b138ca74d7c0f2b8bbe781..340a79b444e5601e1ceddc852f022800d3a4e11f 100755
--- a/modemInterface/list_serials.py
+++ b/modemInterface/list_serials.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+
 """
 list_serials.py
 
@@ -8,9 +10,10 @@ NB-Modem via usb-serial cabel
 import glob
 import serial
 import logging.config
+logger = logging.getLogger("listSerilas")
 
 def serial_ports():
-    logger = logging.getLogger("listSerilas")
+
     ports = glob.glob('/dev/tty[A-Za-z]*')
     result = []
     for port in ports:
@@ -21,10 +24,13 @@ def serial_ports():
                 s = serial.Serial(port)
                 s.close()
                 result.append(port)
-        except (OSError, serial.SerialException) as err:
-            logger.error(err)
+        except (OSError, serial.SerialException):  
             pass
+
     return result
 
 if __name__ == '__main__':
-    print(serial_ports())
+    try:
+        logger.info(serial_ports())
+    except Exception as e:
+        logger.error(e)
diff --git a/modemInterface/test_functions.py b/modemInterface/test_functions.py
new file mode 100644
index 0000000000000000000000000000000000000000..2347058030c8cef9ef8ccf3cfc1559d4ec49d308
--- /dev/null
+++ b/modemInterface/test_functions.py
@@ -0,0 +1,117 @@
+#!/usr/bin/python3
+
+"""
+test_functions.py
+
+Unit tests for functions.py script.
+Needs Nb-IoT modem to work
+"""
+import unittest
+import functions
+
+
+class testmodem_commads(unittest.TestCase):
+    
+    def setUp(self):
+        self.func = functions.modem_commands()
+        self.modem = self.func.ready_modem()
+        self.ping_server_cmd = 'at+nping=35.234.64.140'
+    
+    def test_start_modem(self):
+        # We gave the first USB lane as a default value for connecting
+        result = self.func.start_modem('/dev/ttyUSB0')
+        self.assertEqual(type(result), type(self.modem))
+
+    '''
+    The following 3 functions return AT-command resultss
+    '''
+    def test_check_modem(self):
+        result = self.func.check_connection(self.modem)
+        self.assertIn("OK", result)
+
+    def test_check_connection(self):
+        result = self.func.check_connection(self.modem)
+        self.assertIn("OK", result)
+
+    def test_send_command(self):
+        result = self.func.send_command(self.modem, self.ping_server_cmd)
+        self.assertIn("OK", result)
+
+        self.assertRaises(TypeError, self.func.send_command, self.modem, ["kissa"])
+        self.assertRaises(TypeError, self.func.send_command, self.modem, {"kissa":"koira"})
+        self.assertRaises(TypeError, self.func.send_command, self.modem, 22)
+    
+    def test_string_to_hex(self):
+        # Testing hex conversion with different types of data as parameter
+        data = "hello world"
+        result = self.func.string_to_hex(data)
+        # the right hex values provided by https://www.rapidtables.com/convert/number/ascii-to-hex.html
+        rightHex = "68656c6c6f20776f726c64"
+        self.assertEqual(result, rightHex)
+
+        data = ['kissa']
+        result = self.func.string_to_hex(data)
+        rightHex = "5b276b69737361275d"
+        self.assertEqual(result, rightHex)
+
+        data = {'kissa'}
+        result = self.func.string_to_hex(data)
+        rightHex = "7b276b69737361277d"
+        self.assertEqual(result, rightHex)
+
+        data = True
+        result = self.func.string_to_hex(data)
+        rightHex = "54727565"
+        self.assertEqual(result, rightHex)
+
+    def test_cut_data(self):
+        # Valid input data
+        data = '{"data": {"22": {"timestamp": "02-07-18 23:00", "counter": 0}, "16": {"timestamp": "02-07-18 17:00", "counter": 0}, "20": {"timestamp": "02-07-18 21:00", "counter": 0}, "17": {"timestamp": "02-07-18 18:00", "counter": 0}, "18": {"timestamp": "02-07-18 19:00", "counter": 0}, "14": {"timestamp": "02-07-18 15:00", "counter": 56}, "21": {"timestamp": "02-07-18 22:00", "counter": 0}, "23": {"timestamp": "03-07-18 00:00", "counter": 0}, "19": {"timestamp": "02-07-18 20:00", "counter": 0}}, "date": "02-07", "id": "F0:37:2E:F1:54:A1"}'
+        result = self.func.cut_data(self.func.string_to_hex(data * 4))
+        self.assertEqual(len(result[0]), 2716)
+
+        # Invalid input data
+        self.assertRaises(TypeError, self.func.cut_data, 222)
+        self.assertRaises(TypeError, self.func.cut_data, True)
+        self.assertRaises(TypeError, self.func.cut_data, {})
+  
+    def test_make_send_commands(self):
+        # Didn't have time to finish this test
+        
+        # We give a list of hex data to the function
+        data = ["68656c6c6f20776f726c64", "5b276b69737361275d", "7b276b69737361277d", "54727565"]
+        dataLen = len(data)
+        ip = "35.234.64.140"
+        port = "10000"
+        self.func.make_send_commands(ip, port, data, dataLen)
+
+    def test_send_data_to_ip(self):
+        # Sending test data via modem
+        data = {"data": {"22": {"timestamp": "02-07-18 23:00", "counter": 0}, "16": {"timestamp": "02-07-18 17:00", "counter": 0}, "20": {"timestamp": "02-07-18 21:00", "counter": 0}, "17": {"timestamp": "02-07-18 18:00", "counter": 0}, "18": {"timestamp": "02-07-18 19:00", "counter": 0}, "14": {"timestamp": "02-07-18 15:00", "counter": 56}, "21": {"timestamp": "02-07-18 22:00", "counter": 0}, "23": {"timestamp": "03-07-18 00:00", "counter": 0}, "19": {"timestamp": "02-07-18 20:00", "counter": 0}}, "date": "02-07", "id": "F0:37:2E:F1:54:A1"}
+        result = self.func.send_data_to_ip(self.modem, data)
+        self.assertIn("OK", result)
+
+    def test_find_usb_modem(self):
+        result = self.func.find_usb_modem()
+        self.assertEqual(type(result), type(self.modem))
+
+    def test_ping_server(self):
+        result = self.func.ping_server(self.modem)
+        self.assertIn("OK", result)
+
+    def test_open_socket(self):
+        result = self.func.open_socket(self.modem)
+        self.assertIn("OK", result)
+
+    def test_close_socket(self):
+        # Didn't have time to finish this test
+        result = self.func.close_socket(self.modem)
+        self.assertIn("ERROR", result)
+
+    def test_ready_modem(self):
+        result = self.func.ready_modem()
+        self.assertEqual(type(result), type(self.modem))
+
+
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
diff --git a/movementDetector.log b/movementDetector.log
index 3d64ff328880eaabcc67ee97474bb23e7db0f6be..d7c16eaf41b180c67c77ea01aafe07bd49aba210 100644
--- a/movementDetector.log
+++ b/movementDetector.log
@@ -1235,3 +1235,81 @@
 16.07.18 13.09.23 - sendMovementData - INFO - Check modem local status: 
 16.07.18 13.21.37 - movementDetector - INFO - Movement Detector started
 16.07.18 13.23.04 - movementDetector - INFO - Movement Detector started
+24.07.18 10.32.25 - movementDetector - INFO - Movement Detector started
+24.07.18 10.32.36 - movementDetector - INFO - Movement Detector started
+24.07.18 10.33.27 - movementDetector - INFO - Movement Detector started
+24.07.18 11.36.05 - movementDetector - INFO - Movement Detector started
+24.07.18 12.23.08 - movementDetector - INFO - Movement Detector started
+24.07.18 12.23.56 - movementDetector - INFO - Movement Detector started
+24.07.18 12.24.43 - movementDetector - INFO - Movement Detector started
+24.07.18 12.25.01 - movementDetector - INFO - Movement Detector started
+24.07.18 12.25.36 - movementDetector - INFO - Movement Detector started
+24.07.18 12.26.15 - movementDetector - INFO - Movement Detector started
+24.07.18 12.27.20 - movementDetector - INFO - Movement Detector started
+24.07.18 12.28.12 - movementDetector - INFO - Movement Detector started
+24.07.18 12.28.45 - movementDetector - INFO - Movement Detector started
+24.07.18 12.29.14 - movementDetector - INFO - Movement Detector started
+24.07.18 12.30.24 - movementDetector - INFO - Movement Detector started
+24.07.18 12.31.12 - movementDetector - INFO - Movement Detector started
+24.07.18 12.39.31 - movementDetector - INFO - Movement Detector started
+24.07.18 12.41.12 - movementDetector - INFO - Movement Detector started
+24.07.18 12.42.05 - movementDetector - INFO - Movement Detector started
+24.07.18 12.55.16 - movementDetector - INFO - Movement Detector started
+24.07.18 12.56.27 - movementDetector - INFO - Movement Detector started
+24.07.18 12.58.08 - movementDetector - INFO - Movement Detector started
+24.07.18 14.34.41 - movementDetector - INFO - Movement Detector started
+25.07.18 08.36.47 - movementDetector - INFO - Movement Detector started
+25.07.18 08.44.09 - movementDetector - INFO - Movement Detector started
+25.07.18 09.02.53 - movementDetector - INFO - Movement Detector started
+25.07.18 09.15.05 - movementDetector - INFO - Movement Detector started
+25.07.18 09.58.34 - movementDetector - INFO - Movement Detector started
+25.07.18 09.58.58 - movementDetector - INFO - Movement Detector started
+25.07.18 09.59.07 - movementDetector - INFO - Movement Detector started
+25.07.18 09.59.26 - movementDetector - INFO - Movement Detector started
+25.07.18 09.59.42 - movementDetector - INFO - Movement Detector started
+25.07.18 10.00.04 - movementDetector - INFO - Movement Detector started
+25.07.18 10.01.32 - movementDetector - INFO - Movement Detector started
+25.07.18 10.02.11 - movementDetector - INFO - Movement Detector started
+25.07.18 10.02.40 - movementDetector - INFO - Movement Detector started
+25.07.18 10.02.53 - movementDetector - INFO - Movement Detector started
+25.07.18 10.13.11 - movementDetector - INFO - Movement Detector started
+25.07.18 10.13.25 - movementDetector - INFO - Movement Detector started
+25.07.18 10.15.16 - movementDetector - INFO - Movement Detector started
+25.07.18 10.15.44 - movementDetector - INFO - Movement Detector started
+25.07.18 10.17.02 - movementDetector - INFO - Movement Detector started
+25.07.18 10.22.01 - movementDetector - INFO - Movement Detector started
+25.07.18 10.22.13 - movementDetector - INFO - Movement Detector started
+25.07.18 10.29.56 - movementDetector - INFO - Movement Detector started
+25.07.18 10.30.45 - movementDetector - INFO - Movement Detector started
+25.07.18 10.31.56 - movementDetector - INFO - Movement Detector started
+25.07.18 12.00.12 - movementDetector - INFO - Movement Detector started
+25.07.18 12.00.47 - movementDetector - INFO - Movement Detector started
+25.07.18 12.01.23 - movementDetector - INFO - Movement Detector started
+25.07.18 12.02.02 - movementDetector - INFO - Movement Detector started
+25.07.18 12.02.46 - movementDetector - INFO - Movement Detector started
+25.07.18 12.03.43 - movementDetector - INFO - Movement Detector started
+25.07.18 12.04.28 - movementDetector - INFO - Movement Detector started
+25.07.18 12.04.45 - movementDetector - INFO - Movement Detector started
+25.07.18 12.05.52 - movementDetector - INFO - Movement Detector started
+25.07.18 12.06.36 - movementDetector - INFO - Movement Detector started
+25.07.18 12.07.06 - movementDetector - INFO - Movement Detector started
+25.07.18 12.07.27 - movementDetector - INFO - Movement Detector started
+25.07.18 12.08.15 - movementDetector - INFO - Movement Detector started
+25.07.18 12.08.55 - movementDetector - INFO - Movement Detector started
+25.07.18 12.16.00 - movementDetector - INFO - Movement Detector started
+25.07.18 12.17.04 - movementDetector - INFO - Movement Detector started
+25.07.18 12.17.47 - movementDetector - INFO - Movement Detector started
+25.07.18 12.17.56 - movementDetector - INFO - Movement Detector started
+25.07.18 12.19.18 - movementDetector - INFO - Movement Detector started
+25.07.18 12.19.47 - movementDetector - INFO - Movement Detector started
+25.07.18 12.30.07 - movementDetector - INFO - Movement Detector started
+25.07.18 12.30.35 - movementDetector - INFO - Movement Detector started
+25.07.18 12.52.51 - movementDetector - INFO - Movement Detector started
+25.07.18 12.55.01 - movementDetector - INFO - Movement Detector started
+25.07.18 12.55.08 - movementDetector - INFO - Movement Detector started
+25.07.18 12.55.49 - movementDetector - INFO - Movement Detector started
+25.07.18 12.56.43 - movementDetector - INFO - Movement Detector started
+25.07.18 12.57.55 - movementDetector - INFO - Movement Detector started
+25.07.18 12.58.31 - movementDetector - INFO - Movement Detector started
+25.07.18 13.37.26 - movementDetector - INFO - Movement Detector started
+25.07.18 13.38.16 - movementDetector - INFO - Movement Detector started
diff --git a/movementDetector.py b/movementDetector.py
index 6e7678908b17b5c1cc1fc20c4aee5d9cba2ceef8..4939560b5e45e778bf78a8e17acb897406e092a6 100755
--- a/movementDetector.py
+++ b/movementDetector.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3.5
+#!/usr/bin/python3
 """
 movementDetector.py
 
@@ -29,8 +29,8 @@ class collectData():
         try:
             data = sensor.update()
             acc = data['acceleration']
-        except Exception as e:
-            logger.error("Error reading data from sensor")
+        except:
+            raise OSError("Error reading data from sensor")
         #global counter
         if acc < 990 or acc > 1040:
             self.counter = self.counter + 1
@@ -54,8 +54,8 @@ class collectData():
                     textData = datafile.read()
                     self.textdict = json.loads(textData)
                     text = self.textdict['date']
-            except Exception as e:
-                logger.error("Problem opening and reading movementdata.json file")
+            except:
+                raise IOError("Problem opening and reading movementdata.json file")
 
         if text != currentdate:
             try:
@@ -63,8 +63,8 @@ class collectData():
                     self.textdict.update({'date':currentdate,'id': self.mac, 'data': {}})
                     dump = json.dumps(self.textdict)
                     datafile.write(dump)
-            except Exception as e:
-                logger.error("Problem opening and writing to movementdata.json file")
+            except:
+                raise IOError("Problem opening and writing to movementdata.json file")
         while currentdate == time.strftime("%d-%m", time.localtime()): # Running the scan for one day
             currenthour = time.strftime("%H", time.localtime())
             while currenthour == time.strftime("%H", time.localtime()): # Running the scan for hour and collecting counter data
@@ -84,15 +84,16 @@ class collectData():
                     dump = json.dumps(self.textdict)
                     datafile.write(dump)
                     logger.info("Hourly data written to json")
-            except Exception as e:
-                logger.error("Problem opening and writing data to movementdata.json file")
+            except:
+                raise IOError("Problem opening and writing data to movementdata.json file")
 
         try:
             with open('./movementdata.json', 'r') as datafile: # Reading ready-to-be-sent data from json
                 readyData = datafile.read()
                 readydict = json.loads(readyData)
-        except Exception as e:
-            logger.error("Problem opening and reading movementdata.json file")
+        except:
+                raise IOError("Problem opening and reading movementdata.json file")
+            
 
         try:
             with open('./movementdata_ready.json', 'w') as datafile: # Writing collected data to json to be sent
@@ -102,10 +103,13 @@ class collectData():
             logger.info("Sending to server")
             sendInfo = sendMovementData.sendData()
             sendInfo.sendFile('./movementdata_ready.json')
-        except Exception as e:
-            logger.error("Problem writing and sending movementdata_ready.json file to server")
+        except:
+            raise IOError("Problem writing and sending movementdata_ready.json file to server")
 
 if __name__ == "__main__":
     while True:
-        col = collectData()
-        col.collector()
+        try:
+            col = collectData()
+            col.collector()
+        except Exception as e:
+            logger.error("{}".format(e))
diff --git a/sendMovementData.py b/sendMovementData.py
index af5478766b471a6f6f9b4559e9c26893d2afd182..0f5f7817391f08012be471c5ee50027fe39a6b17 100755
--- a/sendMovementData.py
+++ b/sendMovementData.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3.5
+#!/usr/bin/python3
 """
 sendMovementData.py
 
@@ -25,23 +25,26 @@ class sendData:
                 dump = json.dumps(text)
                 jsonLoad = json.loads(dump)
         except IOError as e:
-            logger.error(e)
+            raise IOError('Error starting modem: {0}'.format(e))
         # Setting up modem for transmission
         func = functions.modem_commands()
         try:
             modem = func.ready_modem()
-        except Exception as err:
-            logger.error('Error starting modem: {0}'.format(err))
-
+        except IOError as e:
+            raise IOError('Error starting modem: {0}'.format(e))
+           
         print(jsonLoad)
 
         # Sending data to server via modem
         func.send_data_to_ip(modem, jsonLoad)
 
-        logger.info('Closing modem: '.format(modem.close()))
-        logger.info('Check modem local status: '.format(modem.isOpen()))
+        logger.info('Closing modem: {0}'.format(modem.close()))
+        logger.info('Check modem local status: {0}'.format(modem.isOpen()))
 
 if __name__ == "__main__":
     # Main fucnction for testing with test data
-    sd = sendData()
-    sd.sendFile('./movementdata.json')
+    try:
+        sd = sendData()
+        sd.sendFile('./movementdata.json')
+    except Exception as err:
+        logger.error("{0}".format(err))
\ No newline at end of file
diff --git a/sendMovementData.pyc b/sendMovementData.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..92c1c789fbe36a9852dfa1bab1cdd8a18089e823
Binary files /dev/null and b/sendMovementData.pyc differ
diff --git a/testia.py b/testia.py
new file mode 100644
index 0000000000000000000000000000000000000000..dfb01053886844163684b6769d9fa1ffb3eb6146
--- /dev/null
+++ b/testia.py
@@ -0,0 +1,37 @@
+import unittest
+import time
+from movementDetector import collectData
+from ruuvitag_sensor.ruuvitag import RuuviTag
+
+class TestClass(unittest.TestCase):
+
+    def test_handle_data2(self):
+        mac = 'F0:37:2E:F1:54:A1'
+        sensor = RuuviTag(mac)
+        m = collectData()
+        try:
+            m.handle_data(mac, sensor)
+        except Exception as ex:
+            self.fail("FUNC RAISED EXCEPTION")
+
+    def test_handle_data_counter(self):
+        m = collectData()
+        mac = 'F0:37:2E:F1:54:A1'
+        sensor = RuuviTag(mac)
+        m.handle_data(mac, sensor)
+        self.assertNotEqual(m.counter, 0)
+
+    def test_handle_data(self):
+        m = collectData()
+        mac = 'F0:37:2E:F1:54:A2'   # NOTE wrong mac
+        sensor = RuuviTag(mac)
+        with self.assertRaises(OSError):
+            m.handle_data(mac, sensor)
+
+
+
+
+
+if __name__ == '__main__':
+    unittest.main()
+
diff --git a/usageServer/databaseConnection.py b/usageServer/databaseConnection.py
index d9ddfab51d09e3234887d7bce189e7b111218fca..638e6f1c16cdf0fc6981019f12111e8fd5cbb1fe 100755
--- a/usageServer/databaseConnection.py
+++ b/usageServer/databaseConnection.py
@@ -11,6 +11,7 @@ import logging.config
 import logging
 import requests
 import json
+import sys
 
 logging.config.fileConfig('./serverLogging.conf')
 logger = logging.getLogger('databaseConnection')
@@ -20,22 +21,38 @@ class dbConnection():
     port = "2018"
     
     def sendToDb(self, data):
-        # Function that send usage data to database via HTTP requests meant for GraphiQl
-        jsonData = 'mutation{{addData(ruuvitag:"{}",date:"{}",data:"{}"){{id,date,data,ruuvitag}}}}'.format(data.get("id"), str(data.get("date")), data.get("data"))
-        response = requests.post("http://{0}:{1}/graphql".format(self.ip, self.port), json={'query':jsonData})
+        # Function that sends usage data to database via HTTP requests meant for GraphQl
+        if bool(data) == False: 
+            # This condition fullfills if the data dictionary is empty 
+            raise ValueError("Empty dictionary")
+
+        else:
+            try:  
+                jsonData = 'mutation{{addData(ruuvitag:"{}",date:"{}",data:"{}"){{id,date,data,ruuvitag}}}}'\
+                    .format(data.get("id"), str(data.get("date")), data.get("data"))
+            except:
+                raise ValueError("Invalid dict data")
+            # The post request used to send data to graphQL
+            response = requests.post("http://{0}:{1}/graphql".format(self.ip, self.port), json={'query':jsonData})
+            
+                    
+
         if response.status_code == 200:
             logger.info("{} {}".format(response.status_code, response.text))
+            return response
         else:
-            logger.error("{} {}".format(response.status_code, response.text))
-            raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))
+            raise ValueError("Query failed to run by returning code of {} {}. {}".format(response.status_code, response.text, json))
 
 if __name__ == "__main__":
     # Main function for testing with testData
     try:
         with open('./movementdata.json', 'r') as dataFile:
-            txt = dataFile.read()
-            load = json.loads(txt)
+           txt = dataFile.read()
+           load = json.loads(txt)
     except IOError as err:
         logger.error(err)
-    db = dbConnection()
-    db.sendToDb(load)
+    try:
+        db = dbConnection()
+        db.sendToDb(load)
+    except Exception as e:
+        logger.error("{}".format(e))
diff --git a/usageServer/server.py b/usageServer/server.py
index 6739686d2069c11468b8936bdc2f2dba68944676..a3ecdb779d2fb37ab07cd05897dd266aca6575f0 100755
--- a/usageServer/server.py
+++ b/usageServer/server.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3.5
+#!/usr/bin/python3
 
 """
 server.py
@@ -38,7 +38,7 @@ logger.info('waiting to receive message')
 data, address = sock.recvfrom(4096)
 logger.info('received {} bytes from {}'.format(
     len(data), address))
-# Format data to .json format
+# Decode binary data and format it to .json format
 load = json.loads(data.decode('unicode_escape'))
 
 db = dbConnection()
diff --git a/usageServer/test_databaseConnection.py b/usageServer/test_databaseConnection.py
new file mode 100644
index 0000000000000000000000000000000000000000..f16996d3c5f2356b60f09bac5ef432224e5ef1f3
--- /dev/null
+++ b/usageServer/test_databaseConnection.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python3
+
+"""
+test_DatabaseConnection.py
+
+Unit tests for databaseConnection.py
+
+"""
+import json
+import unittest
+import databaseConnection
+
+class testDbConnection(unittest.TestCase): 
+
+    def setUp(self):
+
+        self.dCon = databaseConnection.dbConnection()
+
+
+    def test_sendToDb(self):
+
+        # Correct test data
+        data = {"data": {"22": {"timestamp": "02-07-18 23:00", "counter": 0}, "16": {"timestamp": "02-07-18 17:00", "counter": 0}, "20": {"timestamp": "02-07-18 21:00", "counter": 0}, "17": {"timestamp": "02-07-18 18:00", "counter": 0}, "18": {"timestamp": "02-07-18 19:00", "counter": 0}, "14": {"timestamp": "02-07-18 15:00", "counter": 56}, "21": {"timestamp": "02-07-18 22:00", "counter": 0}, "23": {"timestamp": "03-07-18 00:00", "counter": 0}, "19": {"timestamp": "02-07-18 20:00", "counter": 0}}, "date": "02-07", "id": "F0:37:2E:F1:54:A1"}
+
+        result = self.dCon.sendToDb(data)
+        self.assertEqual(result.status_code, 200)
+        
+        # Invalid test data
+        self.assertRaises(ValueError, self.dCon.sendToDb, "Not a .json format btw")
+        self.assertRaises(ValueError, self.dCon.sendToDb, 222)
+        self.assertRaises(ValueError, self.dCon.sendToDb, ["sss", 2, 5, "ss"])
+        self.assertRaises(ValueError, self.dCon.sendToDb, True)
+        # Empty test dict 
+        self.assertRaises(ValueError, self.dCon.sendToDb, {})
+
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file