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
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() if isinstance(err, DatabaseError): return "DB_ERROR" return "ERROR" finally: DatabaseHandler.close_connection() return "OK"
def test_phase_1(db_conn, caplog, monkeypatch): """Test add product and repo.""" DatabaseHandler.connection = db_conn reset_db(db_conn) # write_testing_data(db_conn) 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 _assert_rows_in_table(db_conn, 'content_set', 1) _assert_rows_in_table(db_conn, 'repo', 1) _assert_rows_in_table(db_conn, 'package', 18) _assert_rows_in_table(db_conn, 'errata_refs', 5) _assert_rows_in_table(db_conn, 'cve', 2)