def test_constructor(self): '''Test the __init__ method.''' path = os.path.join(self.env.tracker.paths['admin'], 'cache', 'tracker.db') # Init a database when one does not exist: db1 = Database(self.env.tracker) assert os.path.exists(path) assert db1.conn # Init a database when one already exists: db2 = Database(self.env.tracker) assert os.path.exists(path) assert db2.conn
def test_insert_many(self): '''Tests the `insert_many` method''' db = Database(self.env.tracker) issues = [] for i in range(20): issue = Issue(self.env.tracker) issue.save() issues.append(issue) db.insert_many(issues) rows = db.select().execute() db_issues = [Issue(self.env.tracker, r['id']) for r in rows] # quick check to make sure they're all there. assert len(db_issues) == len(issues)
def test_insert(self): '''Tests the `insert` method''' db = Database(self.env.tracker) # make and insert the issue issue1 = Issue(self.env.tracker) issue1.content = 'test' issue1.title = 'Test' issue1.save() db.insert(issue1) rows = db.select().execute() issue2 = [Issue(self.env.tracker, r['id']) for r in rows][0] # make sure the issues are equal which triggers the __eq__ method. assert issue1 == issue2
def __init__(self, path): if not os.path.exists(path): path = match_path(path) if path is None: raise OSError('Supplied path does not exist') # remove trailing slash if path.endswith('/'): path = path[:-1] self.path = path self.paths = { 'root': self.path, 'base': os.path.basename(self.path), 'config': os.path.join(self.path, 'config'), 'issues': os.path.join(self.path, 'issues'), 'admin': os.path.join(self.path, '.hopper'), 'docs': os.path.join(self.path, 'docs') } self.properties = {'name': None} self.repo = Repo(path) self.config = TrackerConfig(self) self.db = Database(self)
def test_select(self): '''Tests the `select` method''' db = Database(self.env.tracker) # should just return an sqlalchemy.sql.Select object. assert type(db.select()) is Select
def __init__(self, tracker): self.tracker = tracker self.has_db = True if self.has_db: self.db = Database(self.tracker, check=False) self.table = self.db.issues