Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/319395
Change subject: Merge branch 'master' into deploy ...................................................................... Merge branch 'master' into deploy And delete tests b876678 Fix couple blank lines in silverpop_export test 3e62739 Add timezone column to export Change-Id: Id34d11bf3fb150fe99c0ae08af6122878846aa1b --- D silverpop_export/tests/minimal_schema.sql D silverpop_export/tests/test_update.py 2 files changed, 0 insertions(+), 247 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/tools refs/changes/95/319395/1 diff --git a/silverpop_export/tests/minimal_schema.sql b/silverpop_export/tests/minimal_schema.sql deleted file mode 100644 index 4f8682a..0000000 --- a/silverpop_export/tests/minimal_schema.sql +++ /dev/null @@ -1,115 +0,0 @@ --- TODO: Do something SQLy to make *sure* we're not in a real database. - -drop table if exists civicrm_email; -create table civicrm_email ( - id int(10) unsigned auto_increment primary key, - contact_id int(10) unsigned, - email varchar(254) COLLATE utf8_unicode_ci, - is_primary tinyint(4) default '1', - on_hold tinyint(4) default '0', - key UI_email (email) -); - -drop table if exists civicrm_contact; -create table civicrm_contact ( - id int(10) unsigned auto_increment primary key, - do_not_email tinyint(4) default '0', - do_not_phone tinyint(4) default '0', - do_not_mail tinyint(4) default '0', - do_not_sms tinyint(4) default '0', - do_not_trade tinyint(4) default '1', - is_opt_out tinyint(4) default '0', - preferred_language varchar(32) COLLATE utf8_unicode_ci, - first_name varchar(64) COLLATE utf8_unicode_ci, - middle_name varchar(64) COLLATE utf8_unicode_ci, - last_name varchar(64) COLLATE utf8_unicode_ci, - is_deleted tinyint(4) default '0' -); - -drop table if exists wmf_donor; -create table wmf_donor ( - id int(10) unsigned, - entity_id int(10) unsigned, - do_not_solicit tinyint(4), - is_2006_donor tinyint(4), - is_2007_donor tinyint(4), - is_2008_donor tinyint(4), - is_2009_donor tinyint(4), - is_2010_donor tinyint(4), - is_2011_donor tinyint(4), - is_2012_donor tinyint(4), - is_2013_donor tinyint(4), - is_2014_donor tinyint(4), - is_2015_donor tinyint(4), - is_2016_donor tinyint(4), - is_2017_donor tinyint(4), - is_2018_donor tinyint(4), - is_2019_donor tinyint(4), - is_2020_donor tinyint(4), - is_2021_donor tinyint(4), - is_2022_donor tinyint(4), - is_2023_donor tinyint(4), - is_2024_donor tinyint(4), - is_2025_donor tinyint(4), - last_donation_date datetime, - last_donation_currency varchar(255) COLLATE utf8_unicode_ci, - last_donation_amount decimal(20,2), - last_donation_usd decimal(20,2), - lifetime_usd_total decimal(20,2) -); - -drop table if exists civicrm_contribution; -create table civicrm_contribution ( - id int(10) unsigned, - contact_id int(10) unsigned, - receive_date datetime, - total_amount decimal(20,2), - trxn_id varchar(255) COLLATE utf8_unicode_ci, - contribution_status_id int(10) unsigned -); - -drop table if exists civicrm_address; -create table civicrm_address ( - contact_id int(10) unsigned, - is_primary tinyint(4), - city varchar(64) COLLATE utf8_unicode_ci, - postal_code varchar(64) COLLATE utf8_unicode_ci, - country_id int(10) unsigned, - state_province_id int(10) unsigned, - timezone varchar(8) COLLATE utf8_unicode_ci -); - -drop table if exists civicrm_country; -create table civicrm_country ( - id int(10) unsigned, - iso_code char(2) COLLATE utf8_unicode_ci -); - -drop table if exists civicrm_state_province; -create table civicrm_state_province ( - id int(10) unsigned, - name varchar(64) COLLATE utf8_unicode_ci -); - -drop table if exists wmf_contribution_extra; -create table wmf_contribution_extra ( - entity_id int(10) unsigned, - original_amount decimal(20,2), - original_currency varchar(255) COLLATE utf8_unicode_ci -); - -drop table if exists contribution_tracking; -create table contribution_tracking ( - contribution_id int(10) unsigned, - country varchar(2) -); - -drop table if exists log_civicrm_email; -create table log_civicrm_email ( - email varchar(254) COLLATE utf8_unicode_ci -); - -drop table if exists civicrm_uf_match; -create table civicrm_uf_match ( - uf_name varchar(128) COLLATE utf8_unicode_ci -); diff --git a/silverpop_export/tests/test_update.py b/silverpop_export/tests/test_update.py deleted file mode 100644 index a8d6440..0000000 --- a/silverpop_export/tests/test_update.py +++ /dev/null @@ -1,132 +0,0 @@ -import datetime -from decimal import Decimal -import mock -import MySQLdb -import os -import warnings - -import database.db -import silverpop_export.update - -conn = None -db_name = None - - -def setup(): - global conn - global db_name - # FIXME: parameterize test configuration better - db_host = "127.0.0.1" - db_pass = None - if 'EXECUTOR_NUMBER' in os.environ: - # We're running under Jenkins. Assume things. - db_name = "test" - db_user = "root" - else: - db_name = "test" - db_user = "test" - - db_params = {"user": db_user, "host": db_host} - if db_pass: - db_params['passwd'] = db_pass - - conn = database.db.Connection(**db_params) - conn.execute("set default_storage_engine=memory") - conn.execute("drop database if exists " + db_name) - conn.execute("create database " + db_name) - conn.db_conn.select_db(db_name) - - -def test_test_setup(): - ''' - Set up the civcrm and export databases and run the update with no data. - ''' - run_update_with_fixtures(fixture_queries=[]) - - -def test_duplicate(): - ''' - Test that we export one record for a duplicate contact. - ''' - - run_update_with_fixtures(fixture_queries=[""" - insert into civicrm_email (contact_id, email, is_primary, on_hold) values - (1, 'person1@localhost', 1, 0), - (2, 'person1@localhost', 1, 0); - """, """ - insert into civicrm_contact (id) values - (1), - (2); - """]) - - cursor = conn.db_conn.cursor() - cursor.execute("select count(*) from silverpop_export") - assert cursor.fetchone() == (1,) - - -def test_refund_history(): - ''' - Test that we don't include refunded donations in a donor's history - ''' - - run_update_with_fixtures(fixture_queries=[""" - insert into civicrm_email (contact_id, email, is_primary, on_hold) values - (1, 'person1@localhost', 1, 0); - """, """ - insert into civicrm_contact (id) values - (1); - """, """ - insert into civicrm_contribution (id, contact_id, receive_date, total_amount, trxn_id, contribution_status_id) values - (1, 1, '2015-01-03', 15.25, 'xyz123', 1), - (2, 1, '2016-05-05', 25.25, 'abc456', 9); - """, """ - insert into wmf_contribution_extra (entity_id, original_amount, original_currency) values - (1, 20.15, 'CAD'), - (2, 35.15, 'CAD'); - """]) - - cursor = conn.db_conn.cursor() - cursor.execute("select highest_usd_amount, lifetime_usd_total, donation_count, latest_currency, latest_native_amount, latest_usd_amount, latest_donation from silverpop_export") - expected = (Decimal('15.25'), Decimal('15.25'), 1, 'CAD', Decimal('20.15'), Decimal('15.25'), datetime.datetime(2015, 1, 3)) - assert cursor.fetchone() == expected - - -def run_update_with_fixtures(fixture_path=None, fixture_queries=None): - with mock.patch("database.db.Connection") as MockConnection: - - # Always return our test database connection. - MockConnection.return_value = conn - - with mock.patch("process.globals.get_config") as MockConfig: - # Point all config at our test database. - MockConfig().civicrm_db.db = db_name - MockConfig().drupal_db.db = db_name - MockConfig().silverpop_db.db = db_name - MockConfig().log_civicrm_db.db = db_name - - # Silence predictable warnings about "if not exists" table stuff. - warnings.filterwarnings('ignore', category=MySQLdb.Warning) - - # Create fixtures - tests_dir = os.path.dirname(__file__) - script_path = os.path.join(tests_dir, "minimal_schema.sql") - database.db.run_script(script_path) - - parent_dir = os.path.dirname(os.path.dirname(__file__)) - script_path = os.path.join(parent_dir, "silverpop_countrylangs.sql") - database.db.run_script(script_path) - - if fixture_path: - database.db.run_script(fixture_path) - - if fixture_queries: - for statement in fixture_queries: - conn.execute(statement) - - # Reenable warnings - warnings.filterwarnings('default', category=MySQLdb.Warning) - - # Run the bulk update. - # FIXME: Implementation should provide this as a single function. - update_queries = silverpop_export.update.load_queries('update_table.sql') - silverpop_export.update.run_queries(conn, update_queries) -- To view, visit https://gerrit.wikimedia.org/r/319395 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id34d11bf3fb150fe99c0ae08af6122878846aa1b Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/tools Gerrit-Branch: deploy Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits