Exemplo n.º 1
0
class UserTest(unittest.TestCase):

    def setUp(self):
        initdb()

    def tearDown(self):
        try:
            os.remove("sqlite3.db")
        except OSError:
            pass

    def test_valid__returnFalse(self):
        self.user = Service()
        self.assertFalse(self.user.valid())

    def test_valid_user_returnFalse(self):
        self.user = Service()
        self.user.name = "John"
        self.assertFalse(self.user.valid())

    def test_valid_userPass_returnTrue(self):
        self.user = Service()
        self.user.name = 'John'
        self.user.password = '******'
        self.assertTrue(self.user.valid())

    def test_valid_userPassKWARGS_returnTrue(self):
        self.user = Service(_name='John', _password='******')
        self.assertTrue(self.user.valid())
Exemplo n.º 2
0
def import_data(path='unipass_export.json'):
    initdb()  # If db not exists, create one
    with open(path, 'r') as fp:
        try:
            for s in json.load(fp):
                service = Service(**s)
                if service.valid():
                    service.create()
            return True
        except ValueError:
            return False
Exemplo n.º 3
0
def add_service(service, name, password, note):
    serv = Service()
    serv.service = service
    serv.name = name
    serv.password = password
    serv.note = note
    if serv.valid():
        serv.create()
        return True
    else:
        return False
Exemplo n.º 4
0
def create_user(username, password):
    user = Service()
    user.name = username
    user.password = password
    user.service = 'UniPass'
    user.note = 'Entry for UniPass'
    user.admin = True
    if user.valid():
        user.create()
        return True
    else:
        return False
Exemplo n.º 5
0
class DBTest(unittest.TestCase):

    def setUp(self):
        initdb()

    def tearDown(self):
        try:
            os.remove("sqlite3.db")
        except OSError:
            pass

    def test_create_none(self):
        self.user = Service()
        self.user.admin = True
        self.user.name = 'John'
        self.user.password = '******'
        self.user.create()
        self.assertTrue(self.user.valid())
        self.assertTrue(self.user in Service.getall())

    def test_update_none(self):
        self.user = Service()
        self.user.admin = True
        self.user.name = 'John'
        self.user.password = '******'
        self.user.create()
        self.user = Service.getbyuuid(self.user._uuid)
        self.user.name = 'Kalle'
        self.user.update()
        self.assertTrue(self.user in Service.getall())

    def test_delete_none(self):
        self.user = Service()
        self.user.admin = True
        self.user.name = 'John'
        self.user.password = '******'
        self.user.create()
        self.user.delete()
        self.assertFalse(self.user in Service.getall())