diff --git a/core.py b/core.py index 82e101ac..7a67207a 100644 --- a/core.py +++ b/core.py @@ -33,9 +33,15 @@ class Core: key = gpg.gen_key(input_data) return - def addPeer(self, id, name=''): + def addPeer(self, peerID, name=''): # This function simply adds a peer to the DB - return + conn = sqlite3.connect(self.peerDB) + c = conn.cursor() + t = (peerID, name) + c.execute('Insert into users (id, name) values(?, ?);', t) + conn.commit() + conn.close() + return True def createPeerDB(self): # generate the peer database diff --git a/cryptoshim.py b/cryptoshim.py deleted file mode 100644 index a87f0420..00000000 --- a/cryptoshim.py +++ /dev/null @@ -1,16 +0,0 @@ -''' - Onionr - P2P Microblogging Platform & Social network. Run with 'help' for usage. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -''' - diff --git a/onionr.py b/onionr.py index 61bcd59a..7a49aeb8 100755 --- a/onionr.py +++ b/onionr.py @@ -50,7 +50,7 @@ class Onionr: if not os.path.exists('data/'): os.mkdir('data/') - if os.path.exists('data/peers.db'): + if not os.path.exists('data/peers.db'): onionrCore.createPeerDB() pass diff --git a/tests.py b/tests.py index 2d7d04c1..0a041840 100755 --- a/tests.py +++ b/tests.py @@ -32,7 +32,7 @@ class OnionrTests(unittest.TestCase): self.assertTrue(False) else: self.assertTrue(True) - def testPeerDBCreation(self): + def testPeer_a_DBCreation(self): print('--------------------------') print('Running peer db creation test') if os.path.exists('data/peers.db'): @@ -44,6 +44,16 @@ class OnionrTests(unittest.TestCase): self.assertTrue(True) else: self.assertTrue(False) + def testPeer_b_addPeerToDB(self): + print('--------------------------') + print('Running peer db insertion test') + import core + myCore = core.Core() + myCore.createPeerDB() + if myCore.addPeer('test'): + self.asserTrue(True) + else: + self.assertTrue(False) def testData_b_Encrypt(self): self.assertTrue(True) return