From 6656f76a7ac4c45d600c5e3a14365cb170672062 Mon Sep 17 00:00:00 2001
From: Alex Gleason <alex@alexgleason.me>
Date: Oct 01 2018 19:18:23 +0000
Subject: [PATCH 1/4] Onboarding: fix dev-data.py, prioritize docker-compose for local dev, fix Vagrant issues


---

diff --git a/README.rst b/README.rst
index f4faa4e..c532c42 100644
--- a/README.rst
+++ b/README.rst
@@ -37,9 +37,38 @@ on `this recording <https://pagure.io/how-do-you-pronounce-pagure/raw/master/f/p
 Get it running
 ==============
 
-There are several options when it comes to a development environment. Vagrant
-will provide you with a virtual machine which you can develop on, or you can
-install it directly on your host machine.
+There are several options when it comes to a development environment.
+They are: Docker Compose, Vagrant, and manual. Choose an option below.
+
+Docker Compose
+^^^^^^^^^^^^^^
+Docker Compose will provide you with a container which you can develop on.
+Install it `with these instructions <https://docs.docker.com/compose/install/>`_.
+
+For more information about docker-compose cli, see: https://docs.docker.com/compose/reference/.
+
+Once installed, create the folder that will receive the projects, forks, docs,
+requests and tickets' git repo::
+
+    mkdir -p lcl/{repos,remotes,attachments,releases}
+
+A docker compose environment is available to run pagure. First use the following
+command to build the containers. ::
+
+    $ docker-compose -f dev/docker-compose.yml build
+
+Once all the containers are built, run the following command to start the containers. ::
+
+    $ docker-compose -f dev/docker-compose.yml up
+
+Once all the containers have started, you can access pagure on http://localhost:5000.
+To stop the containers, press Ctrl+C.
+
+To populate the container with test data and create a new account, run ::
+
+    $ docker-compose -f dev/docker-compose.yml exec web python dev-data.py --all
+
+You can then login with any of the created users.
 
 Vagrant
 ^^^^^^^
@@ -48,12 +77,21 @@ For a more thorough introduction to Vagrant, see
 https://fedoraproject.org/wiki/Vagrant.
 
 An example Vagrantfile is provided as ``Vagrantfile.example``. To use it,
-just copy it and install Vagrant::
+just copy it and install Vagrant. Instructions for Fedora::
 
     $ cp dev/Vagrantfile.example Vagrantfile
     $ sudo dnf install ansible libvirt vagrant-libvirt vagrant-sshfs vagrant-hostmanager
     $ vagrant up
 
+On Ubuntu, install Vagrant directly `from the website <https://www.vagrantup.com/downloads.html>`_
+then run these commands instead::
+
+    $ cp dev/Vagrantfile.example Vagrantfile
+    $ sudo add-apt-repository ppa:ansible/ansible
+    $ sudo apt update
+    $ sudo apt install ansible libvirt0 openssh-server qemu libvirt-bin ebtables dnsmasq libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
+    $ vagrant plugin install vagrant-libvirt vagrant-sshfs vagrant-hostmanager
+
 If you get this error ``Block in synced_folders: Internal error. Invalid: sshfs``,
 when you run ``vagrant up`` , you need to install vagrant sshfs plugin, which can be done by::
 
@@ -86,33 +124,9 @@ preconfigured::
     $ pstop             # Stops all those tasks again
     $ pstatus           # Shows pagure status
 
-The Vagrant pagure doesn't have its own log file, use ``journalctl -f`` to 
+The Vagrant pagure doesn't have its own log file, use ``journalctl -f`` to
 show the pagure output. The verbosity can be configured in the pagure config file
-with the ``LOGGING`` parameter. 
-
-Docker Compose
-^^^^^^^^^^^^^^
-Create the folder that will receive the projects, forks, docs, requests and
-tickets' git repo::
-
-    mkdir -p lcl/{repos,remotes,attachments,releases}
-
-A docker compose environment is available to run pagure. First use the following
-command to build the containers. ::
-
-    $ docker-compose -f dev/docker-compose.yml build
-
-Once all the containers are built, run the following command to start the containers. ::
-
-    $ docker-compose -f dev/docker-compose.yml up -d
-
-Once all the containers have started, you can access pagure on http://localhost:5000
-
-To stop the containers, run the following ::
-
-    $ docker-compose -f dev/docker-compose.yml stop
-
-More information about docker-compose cli see https://docs.docker.com/compose/reference/.
+with the ``LOGGING`` parameter.
 
 Running the unit-tests
 **********************
diff --git a/dev-data.py b/dev-data.py
index 5189357..21f80bc 100644
--- a/dev-data.py
+++ b/dev-data.py
@@ -1,4 +1,6 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 """ Populate the pagure db with some dev data. """
 
 from __future__ import print_function, unicode_literals
@@ -12,6 +14,8 @@ from sqlalchemy import create_engine, MetaData
 import pagure
 import tests
 from pagure.lib import create_session
+from pagure.lib.login import generate_hashed_value
+from pagure.lib.model import create_default_status
 
 '''
 Usage:
@@ -47,17 +51,23 @@ def empty_dev_db(metadata, engine):
     print('WARNING: Deleting all data from ', _config['DB_URL'])
     # Dangerous: this will wipe the data from the table but keep the schema
     print('')
-    response = raw_input('Do you want to continue yes or no?    ')
+    response = raw_input('Do you want to continue? (yes/no)    ')
     if 'yes'.startswith(response.lower()):
         for tbl in reversed(metadata.sorted_tables):
             if tbl.fullname != 'acls':
                 engine.execute(tbl.delete())
+    else:
+        exit("Aborting.")
 
 
 def insert_data(session, username, user_email):
     _config['EMAIL_SEND'] = False
     _config['TESTING'] = True
 
+    # Populate with default statuses
+    create_default_status(session)
+    print('Default statuses populated')
+
     ######################################
     # tags
     item = pagure.lib.model.Tag(
@@ -70,53 +80,65 @@ def insert_data(session, username, user_email):
     # Users
     # Create a couple of users
     item = pagure.lib.model.User(
+        id=1,
         user='pingou',
         fullname='PY C',
-        password='foo',
+        password=generate_hashed_value(u'testing123'),
+        token=None,
         default_email='bar@pingou.com',
     )
     session.add(item)
     session.commit()
+    print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
 
     item = pagure.lib.model.User(
+        id=2,
         user='foo',
         fullname='foo bar',
-        password='foo',
+        password=generate_hashed_value(u'testing123'),
+        token=None,
         default_email='foo@bar.com',
     )
     session.add(item)
     session.commit()
+    print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
 
     item = pagure.lib.model.User(
+        id=3,
         user=username,
         fullname=username,
-        password='foo',
+        password=generate_hashed_value(u'testing123'),
+        token=None,
         default_email=user_email,
     )
     session.add(item)
     session.commit()
+    print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
 
     ######################################
     # pagure_group
     item = pagure.lib.model.PagureGroup(
         group_name='admin',
+        group_type='admin',
         user_id=1,
         display_name='admin',
         description='Admin Group',
     )
     session.add(item)
     session.commit()
+    print('Created "admin" group. Pingou is a member.')
 
     # Add a couple of groups so that we can list them
     item = pagure.lib.model.PagureGroup(
         group_name='group',
         group_type='user',
-        user_id=1,  # pingou
+        user_id=1,
         display_name='group group',
         description='this is a group group',
     )
     session.add(item)
     session.commit()
+    print('Created "group" group. Pingou is a member.')
 
     item = pagure.lib.model.PagureGroup(
         group_name='rel-eng',
@@ -127,12 +149,13 @@ def insert_data(session, username, user_email):
     )
     session.add(item)
     session.commit()
+    print('Created "rel-eng" group. Pingou is a member.')
     ######################################
     # projects
 
     import shutil
     # delete folder from local instance to start from a clean slate
-    if os.path.exists(pagure.APP.config['GIT_FOLDER']):
+    if os.path.exists(_config['GIT_FOLDER']):
         shutil.rmtree(_config['GIT_FOLDER'])
 
     tests.create_projects(session)
@@ -267,7 +290,8 @@ def insert_data(session, username, user_email):
     repo = pagure.lib.get_authorized_project(session, 'test')
     item = pagure.lib.model.ProjectGroup(
         project_id=repo.id,
-        group_id=group.id
+        group_id=group.id,
+        access="commit"
     )
     session.add(item)
     session.commit()
@@ -277,7 +301,8 @@ def insert_data(session, username, user_email):
     repo = pagure.lib.get_authorized_project(session, 'test2')
     item = pagure.lib.model.ProjectGroup(
         project_id=repo.id,
-        group_id=group.id
+        group_id=group.id,
+        access="admin"
     )
     session.add(item)
     session.commit()
@@ -293,8 +318,7 @@ def insert_data(session, username, user_email):
         repo_to=repo,
         branch_to='master',
         title='Fixing code for unittest',
-        user=username,
-        requestfolder=None,
+        user=username
     )
     session.commit()
 
@@ -308,7 +332,8 @@ def insert_data(session, username, user_email):
     repo = pagure.lib.get_authorized_project(session, 'test')
     item = pagure.lib.model.ProjectUser(
         project_id=repo.id,
-        user_id=user.id
+        user_id=user.id,
+        access="commit"
     )
     session.add(item)
     session.commit()
@@ -317,7 +342,8 @@ def insert_data(session, username, user_email):
     repo = pagure.lib.get_authorized_project(session, 'test2')
     item = pagure.lib.model.ProjectUser(
         project_id=repo.id,
-        user_id=user.id
+        user_id=user.id,
+        access="commit"
     )
     session.add(item)
     session.commit()
@@ -337,8 +363,7 @@ def insert_data(session, username, user_email):
     repo = pagure.lib.get_authorized_project(session, 'test')
     all_issues = pagure.lib.search_issues(session, repo)
     pagure.lib.add_issue_dependency(session, all_issues[0],
-                                    all_issues[1], 'pingou',
-                                    _config['GIT_FOLDER'])
+                                    all_issues[1], 'pingou')
 
     ######################################
     # pull_request_comments
@@ -366,7 +391,8 @@ def insert_data(session, username, user_email):
         username=user.user,
         percent=80,
         comment="Jenkins build passes",
-        url=str(pr.id)
+        url=str(pr.id),
+        status="Open"
     )
     session.add(item)
     session.commit()
@@ -377,7 +403,7 @@ def insert_data(session, username, user_email):
     issues = pagure.lib.search_issues(session, repo)
     item = pagure.lib.model.TagIssue(
         issue_uid=issues[0].uid,
-        tag='Blocker',
+        tag='tag1',
     )
     session.add(item)
     session.commit()
@@ -415,11 +441,7 @@ def insert_data(session, username, user_email):
         print('requests folder already deleted')
 
     repo = pagure.lib.get_authorized_project(session, 'test')
-    result = pagure.lib.fork_project(session, 'foo', repo,
-                                     _config['GIT_FOLDER'],
-                                     _config['DOCS_FOLDER'],
-                                     _config['TICKETS_FOLDER'],
-                                     _config['REQUESTS_FOLDER'])
+    result = pagure.lib.fork_project(session, 'foo', repo)
     if result == 'Repo "test" cloned to "foo/test"':
         session.commit()
 
diff --git a/dev/ansible/roles/pagure-dev/files/bashrc b/dev/ansible/roles/pagure-dev/files/bashrc
index eb3b474..8505dec 100644
--- a/dev/ansible/roles/pagure-dev/files/bashrc
+++ b/dev/ansible/roles/pagure-dev/files/bashrc
@@ -5,6 +5,12 @@ if [ -f /etc/bashrc ]; then
     . /etc/bashrc
 fi
 
+# Always use the virtualenv
+workon python2-pagure
+
+# To avoid confusion, start in the `devel` directory
+cd devel
+
 # Uncomment the following line if you don't like systemctl's auto-paging feature:
 # export SYSTEMD_PAGER=
 
diff --git a/dev/ansible/roles/pagure-dev/files/motd b/dev/ansible/roles/pagure-dev/files/motd
index 9a2a76c..ec96796 100644
--- a/dev/ansible/roles/pagure-dev/files/motd
+++ b/dev/ansible/roles/pagure-dev/files/motd
@@ -3,12 +3,12 @@ Welcome to the Pagure development environment!
 
 Here are some tips:
 
-* Pagure is installed in a Python virtualenv. Use `workon python2-pagure` to
-  enter the virtualenv.
+* Pagure is installed in a Python virtualenv. Use `deactivate` to leave it,
+  or `workon python2-pagure` to get back in.
 
 * The code for Pagure is located at ~/devel/
 
-* You can populate the database with the `dev-data.py` script in the repository
+* You can populate the database with `python dev-data.py --all`
 
 * Run `pstart` to start the development server and `pstop` to stop it.
 
diff --git a/dev/ansible/roles/pagure-dev/files/pagure.cfg b/dev/ansible/roles/pagure-dev/files/pagure.cfg
index 94780d3..6640aac 100644
--- a/dev/ansible/roles/pagure-dev/files/pagure.cfg
+++ b/dev/ansible/roles/pagure-dev/files/pagure.cfg
@@ -138,7 +138,7 @@ REDIS_DB = 0
 # Specify which authentication method to use, defaults to `fas` can be or
 # `local`
 # Default: ``fas``.
-PAGURE_AUTH = 'fas'
+PAGURE_AUTH = 'local'
 
 # When this is set to True, the session cookie will only be returned to the
 # server via ssl (https). If you connect to the server via plain http, the
diff --git a/tests/__init__.py b/tests/__init__.py
index 61601fe..f5c370b 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -591,6 +591,7 @@ def create_locks(session, project):
 def create_projects(session, is_fork=False, user_id=1, hook_token_suffix=''):
     """ Create some projects in the database. """
     item = pagure.lib.model.Project(
+        id=1,
         user_id=user_id,  # pingou
         name='test',
         is_fork=is_fork,
@@ -604,6 +605,7 @@ def create_projects(session, is_fork=False, user_id=1, hook_token_suffix=''):
     create_locks(session, item)
 
     item = pagure.lib.model.Project(
+        id=2,
         user_id=user_id,  # pingou
         name='test2',
         is_fork=is_fork,
@@ -615,6 +617,7 @@ def create_projects(session, is_fork=False, user_id=1, hook_token_suffix=''):
     session.add(item)
 
     item = pagure.lib.model.Project(
+        id=3,
         user_id=user_id,  # pingou
         name='test3',
         is_fork=is_fork,
@@ -754,9 +757,10 @@ def add_content_git_repo(folder, branch='master'):
     with open(os.path.join(newfolder, subfolder, 'file'), 'w') as stream:
         stream.write('foo\n bar\nbaz')
     repo.index.add(os.path.join(subfolder, 'file'))
-    with open(os.path.join(newfolder, subfolder, 'fileŠ'), 'w') as stream:
-        stream.write('foo\n bar\nbaz')
-    repo.index.add(os.path.join(subfolder, 'fileŠ'))
+    # TODO: Test unicode names
+    # with open(os.path.join(newfolder, subfolder, 'fileŠ'), 'w') as stream:
+    #     stream.write('foo\n bar\nbaz')
+    # repo.index.add(os.path.join(subfolder, 'fileŠ'))
     repo.index.write()
 
     # Commits the files added

From c498c2c6700f35b5570ea68dee0f7b5942fb093b Mon Sep 17 00:00:00 2001
From: Alex Gleason <alex@alexgleason.me>
Date: Oct 01 2018 19:18:23 +0000
Subject: [PATCH 2/4] Install tests_requirements.txt into Docker container, fix minor readme typo


---

diff --git a/README.rst b/README.rst
index c532c42..ebe1d4c 100644
--- a/README.rst
+++ b/README.rst
@@ -48,9 +48,9 @@ Install it `with these instructions <https://docs.docker.com/compose/install/>`_
 For more information about docker-compose cli, see: https://docs.docker.com/compose/reference/.
 
 Once installed, create the folder that will receive the projects, forks, docs,
-requests and tickets' git repo::
+requests and tickets' git repo. Run this command exactly as it appears::
 
-    mkdir -p lcl/{repos,remotes,attachments,releases}
+    $ mkdir -p lcl/{repos,remotes,attachments,releases}
 
 A docker compose environment is available to run pagure. First use the following
 command to build the containers. ::
diff --git a/dev/docker/web-run b/dev/docker/web-run
index c3b5296..b138e58 100644
--- a/dev/docker/web-run
+++ b/dev/docker/web-run
@@ -1,4 +1,5 @@
 #!/bin/bash -xe
+pip install -r tests_requirements.txt
 python setup.py build
 if [ ! -f /attachments/inited ];
 then

From 633b657fb91d7d52d9be85cf8fc640e258df24bf Mon Sep 17 00:00:00 2001
From: Alex Gleason <alex@alexgleason.me>
Date: Oct 01 2018 19:18:23 +0000
Subject: [PATCH 3/4] Fix autoincrement issues, fix tests


---

diff --git a/dev-data.py b/dev-data.py
index 21f80bc..7398416 100644
--- a/dev-data.py
+++ b/dev-data.py
@@ -8,6 +8,9 @@ from __future__ import print_function, unicode_literals
 import argparse
 import os
 import sys
+import tempfile
+import pygit2
+import shutil
 
 from sqlalchemy import create_engine, MetaData
 
@@ -16,6 +19,8 @@ import tests
 from pagure.lib import create_session
 from pagure.lib.login import generate_hashed_value
 from pagure.lib.model import create_default_status
+from pagure.lib.repo import PagureRepo
+
 
 '''
 Usage:
@@ -79,8 +84,7 @@ def insert_data(session, username, user_email):
     ######################################
     # Users
     # Create a couple of users
-    item = pagure.lib.model.User(
-        id=1,
+    pingou = item = pagure.lib.model.User(
         user='pingou',
         fullname='PY C',
         password=generate_hashed_value(u'testing123'),
@@ -91,8 +95,7 @@ def insert_data(session, username, user_email):
     session.commit()
     print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
 
-    item = pagure.lib.model.User(
-        id=2,
+    foo = item = pagure.lib.model.User(
         user='foo',
         fullname='foo bar',
         password=generate_hashed_value(u'testing123'),
@@ -103,8 +106,7 @@ def insert_data(session, username, user_email):
     session.commit()
     print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
 
-    item = pagure.lib.model.User(
-        id=3,
+    you = item = pagure.lib.model.User(
         user=username,
         fullname=username,
         password=generate_hashed_value(u'testing123'),
@@ -120,7 +122,7 @@ def insert_data(session, username, user_email):
     item = pagure.lib.model.PagureGroup(
         group_name='admin',
         group_type='admin',
-        user_id=1,
+        user_id=pingou.id,
         display_name='admin',
         description='Admin Group',
     )
@@ -132,7 +134,7 @@ def insert_data(session, username, user_email):
     item = pagure.lib.model.PagureGroup(
         group_name='group',
         group_type='user',
-        user_id=1,
+        user_id=pingou.id,
         display_name='group group',
         description='this is a group group',
     )
@@ -143,7 +145,7 @@ def insert_data(session, username, user_email):
     item = pagure.lib.model.PagureGroup(
         group_name='rel-eng',
         group_type='user',
-        user_id=1,  # pingou
+        user_id=pingou.id,
         display_name='Release Engineering',
         description='The group of release engineers',
     )
@@ -158,15 +160,53 @@ def insert_data(session, username, user_email):
     if os.path.exists(_config['GIT_FOLDER']):
         shutil.rmtree(_config['GIT_FOLDER'])
 
-    tests.create_projects(session)
+    # Create projects
+    item = project1 = pagure.lib.model.Project(
+        user_id=pingou.id,
+        name='test',
+        is_fork=False,
+        parent_id=None,
+        description='test project #1',
+        hook_token='aaabbbccc',
+    )
+    item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+    session.add(item)
+    session.flush()
+    tests.create_locks(session, item)
+
+    item = project2 = pagure.lib.model.Project(
+        user_id=pingou.id,
+        name='test2',
+        is_fork=False,
+        parent_id=None,
+        description='test project #2',
+        hook_token='aaabbbddd',
+    )
+    item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+    session.add(item)
+
+    item = project3 = pagure.lib.model.Project(
+        user_id=pingou.id,
+        name='test3',
+        is_fork=False,
+        parent_id=None,
+        description='namespaced test project',
+        hook_token='aaabbbeee',
+        namespace='somenamespace',
+    )
+    item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+    session.add(item)
+
+    session.commit()
+
     tests.create_projects_git(_config['GIT_FOLDER'], bare=True)
-    tests.add_content_git_repo(
+    add_content_git_repo(
         os.path.join(_config['GIT_FOLDER'], 'test.git'))
     tests.add_readme_git_repo(
         os.path.join(_config['GIT_FOLDER'], 'test.git'))
 
     # Add some content to the git repo
-    tests.add_content_git_repo(
+    add_content_git_repo(
         os.path.join(_config['GIT_FOLDER'], 'forks', 'pingou',
                      'test.git'))
     tests.add_readme_git_repo(
@@ -179,22 +219,22 @@ def insert_data(session, username, user_email):
     ######################################
     # user_emails
     item = pagure.lib.model.UserEmail(
-        user_id=1,
+        user_id=pingou.id,
         email='bar@pingou.com')
     session.add(item)
 
     item = pagure.lib.model.UserEmail(
-        user_id=1,
+        user_id=pingou.id,
         email='foo@pingou.com')
     session.add(item)
 
     item = pagure.lib.model.UserEmail(
-        user_id=2,
+        user_id=foo.id,
         email='foo@bar.com')
     session.add(item)
 
     item = pagure.lib.model.UserEmail(
-        user_id=3,
+        user_id=you.id,
         email=user_email)
     session.add(item)
 
@@ -202,9 +242,8 @@ def insert_data(session, username, user_email):
 
     ######################################
     # user_emails_pending
-    user = pagure.lib.search_user(session, username='pingou')
     email_pend = pagure.lib.model.UserEmailPending(
-        user_id=user.id,
+        user_id=pingou.id,
         email='foo@fp.o',
         token='abcdef',
     )
@@ -215,36 +254,35 @@ def insert_data(session, username, user_email):
     # issues
     # Add an issue and tag it so that we can list them
     item = pagure.lib.model.Issue(
-        id=1,
+        id=1001,
         uid='foobar',
-        project_id=1,
+        project_id=project1.id,
         title='Problem with jenkins build',
         content='For some reason the tests fail at line:24',
-        user_id=1,  # pingou
+        user_id=pingou.id,
     )
     session.add(item)
     session.commit()
 
     item = pagure.lib.model.Issue(
-        id=2,
+        id=1002,
         uid='foobar2',
-        project_id=1,
+        project_id=project1.id,
         title='Unit tests failing',
         content='Need to fix code for the unit tests to '
                 'pass so jenkins build can complete.',
-        user_id=1,  # pingou
+        user_id=pingou.id,
     )
     session.add(item)
     session.commit()
 
-    user = pagure.lib.search_user(session, username=username)
     item = pagure.lib.model.Issue(
-        id=3,
+        id=1003,
         uid='foobar3',
-        project_id=1,
+        project_id=project1.id,
         title='Segfault during execution',
         content='Index out of bounds for variable i?',
-        user_id=user.id,  # current user
+        user_id=you.id,
     )
     session.add(item)
     session.commit()
@@ -253,31 +291,28 @@ def insert_data(session, username, user_email):
     # pagure_user_group
     group = pagure.lib.search_groups(session, pattern=None,
                                      group_name="rel-eng", group_type=None)
-    user = pagure.lib.search_user(session, username='pingou')
     item = pagure.lib.model.PagureUserGroup(
-        user_id=user.id,
+        user_id=pingou.id,
         group_id=group.id
     )
     session.add(item)
     session.commit()
 
-    user = pagure.lib.search_user(session, username=username)
     group = pagure.lib.search_groups(session, pattern=None,
                                      group_name="admin", group_type=None)
 
     item = pagure.lib.model.PagureUserGroup(
-        user_id=user.id,
+        user_id=you.id,
         group_id=group.id
     )
     session.add(item)
     session.commit()
 
-    user = pagure.lib.search_user(session, username='foo')
     group = pagure.lib.search_groups(session, pattern=None,
                                      group_name="group", group_type=None)
 
     item = pagure.lib.model.PagureUserGroup(
-        user_id=user.id,
+        user_id=foo.id,
         group_id=group.id
     )
     session.add(item)
@@ -324,25 +359,23 @@ def insert_data(session, username, user_email):
 
     ######################################
     # tokens
-    tests.create_tokens(session)
+    tests.create_tokens(session, user_id=pingou.id, project_id=project1.id)
 
     ######################################
     # user_projects
-    user = pagure.lib.search_user(session, username='foo')
     repo = pagure.lib.get_authorized_project(session, 'test')
     item = pagure.lib.model.ProjectUser(
         project_id=repo.id,
-        user_id=user.id,
+        user_id=foo.id,
         access="commit"
     )
     session.add(item)
     session.commit()
 
-    user = pagure.lib.search_user(session, username=username)
     repo = pagure.lib.get_authorized_project(session, 'test2')
     item = pagure.lib.model.ProjectUser(
         project_id=repo.id,
-        user_id=user.id,
+        user_id=you.id,
         access="commit"
     )
     session.add(item)
@@ -351,7 +384,7 @@ def insert_data(session, username, user_email):
     ######################################
     # issue_comments
     item = pagure.lib.model.IssueComment(
-        user_id=1,
+        user_id=pingou.id,
         issue_uid='foobar',
         comment='We may need to adjust the unittests instead of the code.',
     )
@@ -381,14 +414,13 @@ def insert_data(session, username, user_email):
 
     ######################################
     # pull_request_flags
-    user = pagure.lib.search_user(session, username='pingou')
     # only 1 pull request available atm
     pr = pagure.lib.get_pull_request_of_user(session, "pingou")[0]
     item = pagure.lib.model.PullRequestFlag(
         uid="random_pr_flag_uid",
         pull_request_uid=pr.uid,
-        user_id=user.id,
-        username=user.user,
+        user_id=pingou.id,
+        username=pingou.user,
         percent=80,
         comment="Jenkins build passes",
         url=str(pr.id),
@@ -446,6 +478,95 @@ def insert_data(session, username, user_email):
         session.commit()
 
 
+def add_content_git_repo(folder, branch='master'):
+    """ Create some content for the specified git repo. """
+    if not os.path.exists(folder):
+        os.makedirs(folder)
+    brepo = pygit2.init_repository(folder, bare=True)
+
+    newfolder = tempfile.mkdtemp(prefix='pagure-tests')
+    repo = pygit2.clone_repository(folder, newfolder)
+
+    # Create a file in that git repo
+    with open(os.path.join(newfolder, 'sources'), 'w') as stream:
+        stream.write('foo\n bar')
+    repo.index.add('sources')
+    repo.index.write()
+
+    parents = []
+    commit = None
+    try:
+        commit = repo.revparse_single(
+            'HEAD' if branch == 'master' else branch)
+    except KeyError:
+        pass
+    if commit:
+        parents = [commit.oid.hex]
+
+    # Commits the files added
+    tree = repo.index.write_tree()
+    author = pygit2.Signature(
+        'Alice Author', 'alice@authors.tld')
+    committer = pygit2.Signature(
+        'Cecil Committer', 'cecil@committers.tld')
+    repo.create_commit(
+        'refs/heads/%s' % branch,  # the name of the reference to update
+        author,
+        committer,
+        'Add sources file for testing',
+        # binary string representing the tree object ID
+        tree,
+        # list of binary strings representing parents of the new commit
+        parents,
+    )
+
+    parents = []
+    commit = None
+    try:
+        commit = repo.revparse_single(
+            'HEAD' if branch == 'master' else branch)
+    except KeyError:
+        pass
+    if commit:
+        parents = [commit.oid.hex]
+
+    subfolder = os.path.join('folder1', 'folder2')
+    if not os.path.exists(os.path.join(newfolder, subfolder)):
+        os.makedirs(os.path.join(newfolder, subfolder))
+    # Create a file in that git repo
+    with open(os.path.join(newfolder, subfolder, 'file'), 'w') as stream:
+        stream.write('foo\n bar\nbaz')
+    repo.index.add(os.path.join(subfolder, 'file'))
+    repo.index.write()
+
+    # Commits the files added
+    tree = repo.index.write_tree()
+    author = pygit2.Signature(
+        'Alice Author', 'alice@authors.tld')
+    committer = pygit2.Signature(
+        'Cecil Committer', 'cecil@committers.tld')
+    repo.create_commit(
+        'refs/heads/%s' % branch,  # the name of the reference to update
+        author,
+        committer,
+        'Add some directory and a file for more testing',
+        # binary string representing the tree object ID
+        tree,
+        # list of binary strings representing parents of the new commit
+        parents
+    )
+
+    # Push to origin
+    ori_remote = repo.remotes[0]
+    master_ref = repo.lookup_reference(
+        'HEAD' if branch == 'master' else 'refs/heads/%s' % branch).resolve()
+    refname = '%s:%s' % (master_ref.name, master_ref.name)
+
+    PagureRepo.push(ori_remote, refname)
+
+    shutil.rmtree(newfolder)
+
+
 if __name__ == "__main__":
     desc = "Run the dev database initialization/insertion/deletion " \
            "script for db located  " + str(_config['DB_URL'])
diff --git a/tests/__init__.py b/tests/__init__.py
index f5c370b..61601fe 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -591,7 +591,6 @@ def create_locks(session, project):
 def create_projects(session, is_fork=False, user_id=1, hook_token_suffix=''):
     """ Create some projects in the database. """
     item = pagure.lib.model.Project(
-        id=1,
         user_id=user_id,  # pingou
         name='test',
         is_fork=is_fork,
@@ -605,7 +604,6 @@ def create_projects(session, is_fork=False, user_id=1, hook_token_suffix=''):
     create_locks(session, item)
 
     item = pagure.lib.model.Project(
-        id=2,
         user_id=user_id,  # pingou
         name='test2',
         is_fork=is_fork,
@@ -617,7 +615,6 @@ def create_projects(session, is_fork=False, user_id=1, hook_token_suffix=''):
     session.add(item)
 
     item = pagure.lib.model.Project(
-        id=3,
         user_id=user_id,  # pingou
         name='test3',
         is_fork=is_fork,
@@ -757,10 +754,9 @@ def add_content_git_repo(folder, branch='master'):
     with open(os.path.join(newfolder, subfolder, 'file'), 'w') as stream:
         stream.write('foo\n bar\nbaz')
     repo.index.add(os.path.join(subfolder, 'file'))
-    # TODO: Test unicode names
-    # with open(os.path.join(newfolder, subfolder, 'fileŠ'), 'w') as stream:
-    #     stream.write('foo\n bar\nbaz')
-    # repo.index.add(os.path.join(subfolder, 'fileŠ'))
+    with open(os.path.join(newfolder, subfolder, 'fileŠ'), 'w') as stream:
+        stream.write('foo\n bar\nbaz')
+    repo.index.add(os.path.join(subfolder, 'fileŠ'))
     repo.index.write()
 
     # Commits the files added

From 3a45af9546470322a91d2d6ced4446693b71ecd4 Mon Sep 17 00:00:00 2001
From: Alex Gleason <alex@alexgleason.me>
Date: Oct 01 2018 19:27:18 +0000
Subject: [PATCH 4/4] Let templates autoreload in Docker container


---

diff --git a/dev/openshift.cfg b/dev/openshift.cfg
index b6fc9de..247ef48 100644
--- a/dev/openshift.cfg
+++ b/dev/openshift.cfg
@@ -12,3 +12,4 @@ ATTACHMENTS_FOLDER = '/attachments'
 EVENTSOURCE_SOURCE = 'http://localhost:8080'
 HOOK_DEBUG = True
 PAGURE_CI_SERVICES = ['jenkins']
+TEMPLATES_AUTO_RELOAD = True

