Esempio n. 1
0
def test_phase_1(db_conn, caplog, monkeypatch):
    """Test add product and repo."""
    basearch = 'x86_64'
    releasever = '7Server'
    base_url = 'http://localhost:8888/%s/%s' % (releasever, basearch)
    content_set = 'content_set_1'
    content_set_label = 'Content set 1'

    # Test store product.
    products = dict(
        prod1=dict(product_id=None,
                   content_sets={content_set: {
                       "name": content_set_label
                   }}))
    prod_store = product_store.ProductStore()
    prod_store.store(products)

    monkeypatch.setattr(FileDownloadThread, '_download', download_mock)

    # Test store repo.
    rep_con = RepositoryController()
    rep_con.add_repository(repo_url=base_url,
                           content_set=content_set,
                           basearch=basearch,
                           releasever=releasever)
    rep_con.import_repositories()

    rep_con1 = RepositoryController()
    rep_con1.add_db_repositories()
    rep_con1.store()

    for file in ["repomd.xml", "updateinfo.xml.gz", "primary_db.sqlite.gz"]:
        assert f"File {file} mock-downloaded." in caplog.messages

    with db_conn.cursor() as cur:
        cur.execute("""select * from content_set""")
        rows = cur.fetchall()
        assert len(rows) == 1

        cur.execute("""select * from repo""")
        rows = cur.fetchall()
        assert len(rows) == 1

        cur.execute("""select * from package""")
        rows = cur.fetchall()
        assert len(rows) == 18

        cur.execute("""select * from errata_refs""")
        rows = cur.fetchall()
        assert len(rows) == 5

        cur.execute("""select * from cve""")
        rows = cur.fetchall()
        assert len(rows) == 2
Esempio n. 2
0
 def run_task(*args, **kwargs):
     """Function to start syncing all repositories available from database."""
     try:
         init_logging()
         init_db()
         repository_controller = RepositoryController()
         repository_controller.add_db_repositories()
         repository_controller.store()
     except Exception as err:  # pylint: disable=broad-except
         msg = "Internal server error <%s>" % err.__hash__()
         LOGGER.exception(msg)
         DatabaseHandler.rollback()
         return "ERROR"
     return "OK"