|
Pierre-Yves Chibon |
6e31e0 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
"""
|
|
Pierre-Yves Chibon |
6e31e0 |
(c) 2019 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
Authors:
|
|
Pierre-Yves Chibon |
6e31e0 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
"""
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
from __future__ import unicode_literals, absolute_import
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
import os
|
|
Pierre-Yves Chibon |
6e31e0 |
import subprocess
|
|
Pierre-Yves Chibon |
6e31e0 |
import sys
|
|
Pierre-Yves Chibon |
6e31e0 |
import unittest
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
import six
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
REPO_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
import tests # noqa
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
c30238 |
class TestDevData(tests.Modeltests):
|
|
Pierre-Yves Chibon |
6e31e0 |
"""This test class contains tests pertaining to the dev-data utility
|
|
Pierre-Yves Chibon |
6e31e0 |
script."""
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
maxDiff = None
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
def test_dev_data_all(self):
|
|
Pierre-Yves Chibon |
6e31e0 |
"""Check how dev-data --all performs
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
"""
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
config_path = os.path.join(self.path, "config")
|
|
Pierre-Yves Chibon |
6e31e0 |
with open(config_path, "w") as f:
|
|
Pierre-Yves Chibon |
c30238 |
f.write("DB_URL = 'sqlite:///%s/db_dev_data.sqlite'\n" % self.path)
|
|
Pierre-Yves Chibon |
c30238 |
f.write("GIT_FOLDER = '%s/repos'\n" % self.path)
|
|
Pierre-Yves Chibon |
c30238 |
f.write(
|
|
Pierre-Yves Chibon |
73d120 |
"BROKER_URL = 'redis+socket://%(global_path)s/broker'\n"
|
|
Pierre-Yves Chibon |
73d120 |
% self.config_values
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
c30238 |
f.write("CELERY_CONFIG = {'task_always_eager': True}\n")
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
env = {
|
|
Pierre-Yves Chibon |
6e31e0 |
"USER_NAME": "testuser",
|
|
Pierre-Yves Chibon |
6e31e0 |
"USER_EMAIL": "testuser@example.com",
|
|
Pierre-Yves Chibon |
6e31e0 |
"FORCE_DELETE": "yes",
|
|
Pierre-Yves Chibon |
6e31e0 |
"PAGURE_CONFIG": config_path,
|
|
Pierre-Yves Chibon |
6e31e0 |
}
|
|
Pierre-Yves Chibon |
6e31e0 |
proc1 = subprocess.Popen(
|
|
Pierre-Yves Chibon |
6e31e0 |
[sys.executable, "dev-data.py", "--all"],
|
|
Pierre-Yves Chibon |
6e31e0 |
cwd=REPO_PATH,
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout=subprocess.PIPE,
|
|
Pierre-Yves Chibon |
6e31e0 |
env=env,
|
|
Pierre-Yves Chibon |
6e31e0 |
)
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout, stderr = proc1.communicate()
|
|
Pierre-Yves Chibon |
6e31e0 |
if isinstance(stdout, six.binary_type):
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout = stdout.decode("utf-8")
|
|
Pierre-Yves Chibon |
6e31e0 |
output = (
|
|
Pierre-Yves Chibon |
6e31e0 |
"""Database created
|
|
Pierre-Yves Chibon |
6e31e0 |
User created: pingou <bar@pingou.com>, testing123</bar@pingou.com>
|
|
Pierre-Yves Chibon |
6e31e0 |
User created: foo <foo@bar.com>, testing123</foo@bar.com>
|
|
Pierre-Yves Chibon |
6e31e0 |
User created: testuser <testuser@example.com>, testing123</testuser@example.com>
|
|
Pierre-Yves Chibon |
6e31e0 |
Created "admin" group. Pingou is a member.
|
|
Pierre-Yves Chibon |
6e31e0 |
Created "group" group. Pingou is a member.
|
|
Pierre-Yves Chibon |
6e31e0 |
Created "rel-eng" group. Pingou is a member.
|
|
Pierre-Yves Chibon |
6e31e0 |
git folder already deleted
|
|
Pierre-Yves Chibon |
6e31e0 |
docs folder already deleted
|
|
Pierre-Yves Chibon |
6e31e0 |
tickets folder already deleted
|
|
Pierre-Yves Chibon |
6e31e0 |
requests folder already deleted
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
WARNING: Deleting all data from sqlite:///%s/db_dev_data.sqlite
|
|
Pierre-Yves Chibon |
6e31e0 |
"""
|
|
Pierre-Yves Chibon |
6e31e0 |
% self.path
|
|
Pierre-Yves Chibon |
6e31e0 |
)
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
self.assertEqual(len(stdout.split("\n")), 14)
|
|
Pierre-Yves Chibon |
6e31e0 |
self.assertEqual(stdout, output)
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
def test_dev_data_delete(self):
|
|
Pierre-Yves Chibon |
6e31e0 |
"""Check how dev-data --init --delete performs
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
"""
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
config_path = os.path.join(self.path, "config")
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
env = {
|
|
Pierre-Yves Chibon |
6e31e0 |
"USER_NAME": "testuser",
|
|
Pierre-Yves Chibon |
6e31e0 |
"USER_EMAIL": "testuser@example.com",
|
|
Pierre-Yves Chibon |
6e31e0 |
"FORCE_DELETE": "yes",
|
|
Pierre-Yves Chibon |
6e31e0 |
"PAGURE_CONFIG": config_path,
|
|
Pierre-Yves Chibon |
6e31e0 |
}
|
|
Pierre-Yves Chibon |
6e31e0 |
proc1 = subprocess.Popen(
|
|
Pierre-Yves Chibon |
6e31e0 |
[sys.executable, "dev-data.py", "--init", "--delete"],
|
|
Pierre-Yves Chibon |
6e31e0 |
cwd=REPO_PATH,
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout=subprocess.PIPE,
|
|
Pierre-Yves Chibon |
6e31e0 |
env=env,
|
|
Pierre-Yves Chibon |
6e31e0 |
)
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout, stderr = proc1.communicate()
|
|
Pierre-Yves Chibon |
6e31e0 |
if isinstance(stdout, six.binary_type):
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout = stdout.decode("utf-8")
|
|
Pierre-Yves Chibon |
6e31e0 |
output = (
|
|
Pierre-Yves Chibon |
6e31e0 |
"""Database created
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
WARNING: Deleting all data from %s
|
|
Pierre-Yves Chibon |
6e31e0 |
"""
|
|
Pierre-Yves Chibon |
6e31e0 |
% self.dbpath
|
|
Pierre-Yves Chibon |
6e31e0 |
)
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
self.assertEqual(len(stdout.split("\n")), 4)
|
|
Pierre-Yves Chibon |
6e31e0 |
self.assertEqual(stdout.split("\n"), output.split("\n"))
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
def test_dev_data_init(self):
|
|
Pierre-Yves Chibon |
6e31e0 |
"""Check how dev-data --init performs
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
"""
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
config_path = os.path.join(self.path, "config")
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
env = {
|
|
Pierre-Yves Chibon |
6e31e0 |
"USER_NAME": "testuser",
|
|
Pierre-Yves Chibon |
6e31e0 |
"USER_EMAIL": "testuser@example.com",
|
|
Pierre-Yves Chibon |
6e31e0 |
"FORCE_DELETE": "yes",
|
|
Pierre-Yves Chibon |
6e31e0 |
"PAGURE_CONFIG": config_path,
|
|
Pierre-Yves Chibon |
6e31e0 |
}
|
|
Pierre-Yves Chibon |
6e31e0 |
proc1 = subprocess.Popen(
|
|
Pierre-Yves Chibon |
6e31e0 |
[sys.executable, "dev-data.py", "--init"],
|
|
Pierre-Yves Chibon |
6e31e0 |
cwd=REPO_PATH,
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout=subprocess.PIPE,
|
|
Pierre-Yves Chibon |
6e31e0 |
env=env,
|
|
Pierre-Yves Chibon |
6e31e0 |
)
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout, stderr = proc1.communicate()
|
|
Pierre-Yves Chibon |
6e31e0 |
if isinstance(stdout, six.binary_type):
|
|
Pierre-Yves Chibon |
6e31e0 |
stdout = stdout.decode("utf-8")
|
|
Pierre-Yves Chibon |
6e31e0 |
output = "Database created\n"
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
self.assertEqual(len(stdout.split("\n")), 2)
|
|
Pierre-Yves Chibon |
6e31e0 |
self.assertEqual(stdout.split("\n"), output.split("\n"))
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
|
|
Pierre-Yves Chibon |
6e31e0 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
6e31e0 |
unittest.main(verbosity=2)
|