def test_merge_strategy_unknown_strategy_some_data_raises(self): self.set_mock_response_data(captions={'sv': 'hello'}) with self.assertRaises(ValueError) as ve: merge_strategy(self.mid, self.mock_site, self.base_sdc, 'foo') self.assertTrue( str(ve.exception).startswith('The `strategy` parameter')) self.assertTrue('Foo' in str(ve.exception))
def test_merge_strategy_add_strategy_all_conflicting_data(self): self.set_mock_response_data(captions={ 'sv': 'hello', 'en': 'hi' }, claims={'P123': [{}]}) with self.assertRaises(SdcException) as se: merge_strategy(self.mid, self.mock_site, self.base_sdc, 'Add') self.assertEqual(se.exception.data, 'all conflicting pre-existing sdc-data')
def test_merge_strategy_nuke_strategy_some_conflicting_data(self): input_data = deepcopy(self.base_sdc) self.set_mock_response_data(captions={'sv': 'hello'}, claims={'P123': [{}]}) r = merge_strategy(self.mid, self.mock_site, input_data, 'Nuke') self.assertEqual(input_data, self.base_sdc) self.assertIsNone(r)
def test_merge_strategy_add_strategy_some_non_conflicting_data(self): input_data = deepcopy(self.base_sdc) self.set_mock_response_data(captions={'fr': 'hello'}, claims={'P456': [{}]}) r = merge_strategy(self.mid, self.mock_site, input_data, 'Add') self.assertEqual(input_data, self.base_sdc) self.assertIsNone(r)
def test_merge_strategy_any_strategy_no_data(self): # Any strategy, even an unknown one, should pass if no prior data. for strategy in (None, 'new', 'blind', 'add', 'nuke', 'foo'): input_data = deepcopy(self.base_sdc) r = merge_strategy(self.mid, self.mock_site, input_data, strategy) self.assertIsNone(r, msg=strategy) self.assertEqual(input_data, self.base_sdc, msg=strategy)
def test_merge_strategy_add_strategy_some_conflicting_data(self): expected_data = deepcopy(self.base_sdc) expected_data['caption'].pop('sv') expected_data.pop('P123') self.set_mock_response_data(captions={ 'sv': 'hello', 'fr': 'hi' }, claims={'P123': [{}]}) r = merge_strategy(self.mid, self.mock_site, self.base_sdc, 'Add') self.assertEqual(self.base_sdc, expected_data) self.assertEqual(r, {'pids': {'P123'}, 'langs': {'sv'}})
def test_merge_strategy_new_strategy_some_conflicting_claim_data(self): self.set_mock_response_data(claims={'P123': [{}]}) with self.assertRaises(SdcException) as se: merge_strategy(self.mid, self.mock_site, self.base_sdc, 'New') self.assertEqual(se.exception.data, 'conflicting pre-existing sdc-data')
def test_merge_strategy_new_strategy_some_conflicting_label_data(self): self.set_mock_response_data(captions={'sv': 'hello'}) with self.assertRaises(SdcException) as se: merge_strategy(self.mid, self.mock_site, self.base_sdc, 'New') self.assertEqual(se.exception.data, 'conflicting pre-existing sdc-data')
def test_merge_strategy_none_strategy_some_non_conflicting_data(self): self.set_mock_response_data(captions={'fr': 'hello'}) with self.assertRaises(SdcException) as se: merge_strategy(self.mid, self.mock_site, self.base_sdc, None) self.assertEqual(se.exception.data, 'pre-existing sdc-data')