def test_should_do_a_get_request(self): url = "http://localhost:5000/file_that_is_not_there" # run serve.py to run this server web = Web() response = web.get(url) status = response.getcode() self.assertEqual(200, status)
def grab_tids(self, file, revision): # Grabs date date_list = self.conn.get( "select date from (select cid,file,date from changeset union " "select rev,file,date from revision union " "select cid,file,date from dates) where cid=? and file=?;", ( revision, file, )) if date_list: date = date_list[0][0] else: url = 'https://hg.mozilla.org/' + self.config['hg'][ 'branch'] + '/json-file/' + revision + file Log.note(url) response = Web.get_string(url) if response.status_code == 404: return () mozobj = json.loads(response.text) date = mozobj['date'][0] cid = mozobj['node'][:12] file = "/" + mozobj['path'] date = mozobj['date'][0] self.conn.execute( "INSERT INTO DATES (CID,FILE,DATE) VALUES (?,?,?)", ( cid, file, date, )) # End Grab Date # TODO make it grab the max old_revision = self.conn.get( "select REV,DATE,CHILD from revision where date<=? and file=?", ( date, file, )) if not old_revision or old_revision[0][0] == revision: return self._grab_revision(file, revision) old_rev_id = old_revision[0][0] current_changeset = old_revision[0][2] # Grab child current_date = old_revision[0][1] old_rev = self._grab_revision(file, old_rev_id) cs_list = [] while True: if current_changeset == []: return old_rev change_set = self.conn.get(GRAB_CHANGESET_QUERY, ( file, current_changeset, )) if not current_changeset: return old_rev if not change_set: url = 'https://hg.mozilla.org/' + self.config['hg'][ 'branch'] + '/json-diff/' + current_changeset + file Log.note(url) mozobj = Web.get(url) self._make_tids_from_diff(mozobj) cs_list = self.conn.get(GRAB_TID_QUERY, (file, current_changeset)) current_changeset = mozobj['children'] if current_changeset: current_changeset = current_changeset[0][:12] current_date = mozobj['date'][0] else: cs_list = self.conn.get(GRAB_TID_QUERY, (file, current_changeset)) current_changeset = change_set[0][4] current_date = change_set[0][3] if current_date > date: break old_rev = self._add_changeset_to_rev(self, old_rev, cs_list) return old_rev
def test_should_do_a_get_request(self): url = "http://localhost:5000/" # run serve.py to run this server web = Web() response = web.get(url) content = response.read() self.assertEqual(content, "Hello")
def _grab_revision(self, file, revision): res = self.conn.get( "select t.tid,t.revision,t.file,t.line,t.operator from temporal t, revision r where " "t.tid=r.tid and r.file=? and r.rev=? order by r.line;", ( file, revision[:12], )) if res: return res url = 'https://hg.mozilla.org/' + self.config['hg'][ 'branch'] + '/json-annotate/' + revision + file Log.note(url) mozobj = Web.get(url) date = mozobj['date'][0] child = mozobj['children'] if child: child = child[0][:12] else: child = None count = 1 for el in mozobj['annotate']: try: self.conn.execute( "INSERT into Temporal (REVISION,FILE,LINE,OPERATOR) values (?,?,?,?);", ( el['node'][:12], file, el['targetline'], '1', )) except sqlite3.IntegrityError: pass tid_result = self.conn.get_one( "select TID from Temporal where REVISION=? AND FILE=? AND LINE=?", ( el['node'][:12], file, el['targetline'], ))[0] try: self.conn.execute( "INSERT into REVISION (REV,FILE,DATE,CHILD,TID,LINE) values (substr(?,0,13),?,?,?,?,?);", ( revision, file, date, child, tid_result, count, )) except sqlite3.IntegrityError: pass count += 1 self.conn.commit() return self.conn.get( "select t.tid,t.revision,t.file,t.line,t.operator from temporal t, revision r where " "t.tid=r.tid and r.file=? and r.rev=? order by r.line;", ( file, revision[:12], ))