def test_database(self): with data_site.app.app_context(): database = sqlite3.connect(data_site.app.config['DATABASE']) cur = database.execute( 'SELECT username FROM Contributors').fetchall() self.assertListEqual(rd.top_contributors(), [name[0] for name in cur]) cur = database.execute( 'SELECT problem_number FROM Problems').fetchall() self.assertListEqual( [int(problem) for problem in rd.get_problems()], [problem[0] for problem in cur])
def main_page(): database = get_database() error = None stats = [ repo_data.top_contributors()[0], repo_data.most_popular_problems()[0], repo_data.count_all_solutions(), repo_data.most_average_user(), len(repo_data.get_contributors()), repo_data.most_common_language() ] if request.method == 'POST': if request.form['problem']: # collects digits inside problem digits = re.search('\d', request.form['problem']) # checks if digits are in the entry if digits: # gets substring of just digits digits = request.form['problem'][request.form['problem']. index(digits.group(0)):] cur = database.execute( 'SELECT problem_number FROM Problems WHERE problem_number = ?', (int(digits), )) if cur.fetchall(): return redirect( url_for('search_problem', problem=int(digits))) else: error = request.form['problem'] + ' is an invalid problem' else: error = request.form['problem'] + ' is an invalid problem' else: # checks if user in database cur = database.execute( 'SELECT * FROM Contributors WHERE username = ?', (request.form['username'], )) if cur.fetchall(): return redirect( url_for('search_username', username=request.form['username'])) else: error = request.form[ 'username'] + ' is an invalid user \n *Capitalization matters!' # renders a template for the main page return render_template( 'Git_Hub_Data_Site.html', stats=stats, error=error, )
def test_top_contributor(self): self.assertListEqual( rd.top_contributors()[0:3], ["Christopher D Chen", "Chris Nugent", "Christopher Nugent"])
def create_contributors(): """method to add all current contributors to the database""" # loops through contributors, creating contributor objects for contributor in repo_data.top_contributors(): # creates a new contributor and adds it on add_contributor(contributor)