コード例 #1
0
ファイル: test_models.py プロジェクト: jherrlin/unipass
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())
コード例 #2
0
ファイル: controller.py プロジェクト: rasjostrom/unipass
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
コード例 #3
0
ファイル: controller.py プロジェクト: rasjostrom/unipass
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
コード例 #4
0
ファイル: controller.py プロジェクト: rasjostrom/unipass
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
コード例 #5
0
ファイル: test_db.py プロジェクト: jherrlin/unipass
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())