def test_update_server_last_updated(self): api_key_response = get_file_contents(self.get_api_key_valid_response) httpretty.register_uri(httpretty.GET, self.get_api_key_uri_regex, body=api_key_response) update_response = get_file_contents(self.update_valid_response) httpretty.register_uri(httpretty.POST, self.update_uri_regex, body=update_response) SettingProperties.set_bool(constants.OPPIA_SERVER_REGISTERED, True) SettingProperties.set_string(constants.OPPIA_SERVER_REGISTER_LAST_SENT, timezone.now()) out = StringIO() call_command(self.STR_COMMAND, stdout=out)
def test_prepare_migration_scripts(): configs = [ SourceFiles('source_host1', 'source_dir1', 'target_dir1', rsync_args=['--checksum'], files=[], exclude=[]), SourceFiles('source_host1', 'source_dir2', 'target_dir2', files=['file3', 'file4'], exclude=[]), SourceFiles('source_host2', 'source_dir1', 'target_dir1', files=['file5', 'file6'], exclude=['logs/*', 'file.conf']) ] target_host = 'target_host1' prepare_file_copy_scripts(target_host, configs, SCRIPT_ROOT) _check_file_contents( os.path.join(SCRIPT_ROOT, target_host, FILE_MIGRATION_RSYNC_SCRIPT), os.path.join(TEST_DATA_DIR, FILE_MIGRATION_RSYNC_SCRIPT)) for config in configs[1:]: # first config has no files list file_list_filename = get_file_list_filename(config) file_path = os.path.join(SCRIPT_ROOT, target_host, file_list_filename) file_list = get_file_contents(file_path).splitlines() assert_equal(file_list, config.files)
def test_update_server_unregistered(self): api_key_response = get_file_contents(self.get_api_key_valid_response) httpretty.register_uri(httpretty.GET, self.get_api_key_uri_regex, body=api_key_response) update_response = get_file_contents(self.update_valid_response) httpretty.register_uri(httpretty.POST, self.update_uri_regex, body=update_response) out = StringIO() call_command(self.STR_COMMAND, stdout=out) # check api key matches the one returned api_key = SettingProperties.get_property( constants.OPPIA_SERVER_REGISTER_APIKEY, '') self.assertEqual('', api_key)
def test_cartodb_no_key_account(self): cartodb_response = get_file_contents(self.cartodb_valid_response) httpretty.register_uri(httpretty.GET, self.cartodb_uri_regex, body=cartodb_response) SettingProperties.set_string(constants.OPPIA_CARTODB_ACCOUNT, None) SettingProperties.set_string(constants.OPPIA_CARTODB_KEY, None) SettingProperties.set_string(constants.OPPIA_HOSTNAME, None) out = StringIO() call_command('cartodb_update', stdout=out)
def test_update_server_registered(self): api_key_response = get_file_contents(self.get_api_key_valid_response) httpretty.register_uri(httpretty.GET, self.get_api_key_uri_regex, body=api_key_response) update_response = get_file_contents(self.update_valid_response) httpretty.register_uri(httpretty.POST, self.update_uri_regex, body=update_response) SettingProperties.set_bool(constants.OPPIA_SERVER_REGISTERED, True) SettingProperties.set_bool(constants.OPPIA_SERVER_REGISTER_EMAIL_NOTIF, True) SettingProperties.set_bool(constants.OPPIA_SERVER_REGISTER_NO_COURSES, True) SettingProperties.set_bool(constants.OPPIA_SERVER_REGISTER_NO_USERS, True) out = StringIO() call_command(self.STR_COMMAND, stdout=out) # check api key matches the one returned api_key = SettingProperties.get_property( constants.OPPIA_SERVER_REGISTER_APIKEY, '') self.assertEqual('AwZfRgB.rxpVnadfn8K6sgY8qYOp8', api_key)
def test_get_migration_file_configs(plan_name): migration = _get_migration(plan_name) migration_file_configs = _generate_plan_and_rsync_lists( migration, plan_name) for target_host, migration_configs in migration_file_configs.items(): for config in migration_configs: file_name = get_file_list_filename(config) actual = get_file_contents( os.path.join(migration.rsync_files_path, target_host, file_name)) expected = _get_test_file(plan_name, 'expected_{}'.format(file_name)) assert expected == actual, "file lists mismatch:\n\nExpected\n{}\nActual\n{}".format( expected, actual)
def test_ip2location_output(self): ipstack_response = get_file_contents(self.ipstack_valid_response) httpretty.register_uri(httpretty.GET, self.ipstack_uri_regex, body=ipstack_response) SettingProperties.set_string(constants.OPPIA_IPSTACK_APIKEY, "FAKE_APIKEY") old_count = UserLocationVisualization.objects.all().count() call_command('ip2location', stdout=StringIO()) self.assertRaises(UserLocationVisualization.DoesNotExist) new_count = UserLocationVisualization.objects.all().count() self.assertEqual(old_count + 2, new_count)
def _get_test_file(plan_name, filename): return get_file_contents(os.path.join(PLANS_DIR, plan_name, filename))
def _check_file_contents(generated_path, expected_path): expected_script = get_file_contents(expected_path) script_source = get_file_contents(generated_path) assert_multi_line_equal.__self__.maxDiff = None assert_multi_line_equal(expected_script.strip(), script_source.strip())