def test_remove(self): """Remove a skill Test that the remove method was called on the skill being installed and that the new skill was removed from the device's skill state. """ skill_to_remove = self.skill_entry_mock() skill_to_remove.name = 'skill-foo' pre_install_hash = device_skill_state_hash(self.msm.device_skill_state) with patch('msm.mycroft_skills_manager.isinstance') as isinstance_mock: isinstance_mock.return_value = True self.msm.remove(skill_to_remove) with open(self.skills_json_path) as skills_json: device_skill_state = json.load(skills_json) skill_names = [skill['name'] for skill in device_skill_state['skills']] self.assertNotIn('skill_foo', skill_names) skill_names = [ skill['name'] for skill in self.msm.device_skill_state['skills'] ] self.assertNotIn('skill_foo', skill_names) self.assertListEqual([call.remove()], skill_to_remove.method_calls) self.assertNotIn('all_skills', self.msm._cache) self.assertIsNone(self.msm._local_skills) post_install_hash = device_skill_state_hash( self.msm.device_skill_state) self.assertNotEqual(pre_install_hash, post_install_hash)
def test_do_via_core_change(self): char = Character(alias='test char 1') skill_core = Skill(6, level=3) char.skills.add(skill_core) fit = Fit(name='test fit 1') fit.character_core = char skill_proxy_removed = next(iter(fit.character_proxy.skills)) # Action econt_calls_before = len(fit._eos_fit.skills.mock_calls) char.skills.remove(skill_core) econt_calls_after = len(fit._eos_fit.skills.mock_calls) # Pyfa model self.assertEqual(len(fit.character_proxy.skills), 0) # Eos model self.assertEqual(econt_calls_after - econt_calls_before, 1) self.assertEqual(fit._eos_fit.skills.mock_calls[-1], call.remove(skill_proxy_removed._eos_item)) # Command queue self.assertIs(fit.has_undo, False) self.assertIs(fit.has_redo, False) # Reload model via persistence (DB check) fit.persist() econt_calls_before = len(fit._eos_fit.skills.mock_calls) self.pyfadb_force_reload() fits = self.query_fits() self.assertEqual(len(fits), 1) fit = fits[0] econt_calls_after = len(fit._eos_fit.skills.mock_calls) # Pyfa model self.assertEqual(len(fit.character_proxy.skills), 0) # Eos model self.assertEqual(econt_calls_after - econt_calls_before, 0)
def test_undo(self): fit = Fit(name='test fit 1') ship = Ship(1) subsystem = Subsystem(4) ship.subsystems.add(subsystem) fit.ship = ship # Action econt_calls_before = len(fit._eos_fit.subsystems.mock_calls) fit.undo() econt_calls_after = len(fit._eos_fit.subsystems.mock_calls) # Pyfa model self.assertEqual(len(ship.subsystems), 1) self.assertIn(subsystem, ship.subsystems) self.assertEqual(subsystem.eve_id, 4) self.assertIs(subsystem.eve_name, None) # Eos model self.assertEqual(econt_calls_after - econt_calls_before, 1) self.assertEqual(fit._eos_fit.subsystems.mock_calls[-1], call.remove(subsystem._eos_item)) # Command queue self.assertIs(fit.has_undo, False) self.assertIs(fit.has_redo, True) # Reload model via persistence (DB check) fit.persist() econt_calls_before = len(fit._eos_fit.subsystems.mock_calls) self.pyfadb_force_reload() fits = self.query_fits() self.assertEqual(len(fits), 1) fit = fits[0] econt_calls_after = len(fit._eos_fit.subsystems.mock_calls) # Pyfa model self.assertIs(fit.ship, None) # Eos model self.assertEqual(econt_calls_after - econt_calls_before, 0)
def test_restore(self, subprocess_mock, gcs_service_mock, storage_mock, os_mock): expected_backup_name = "mongodb-backup-mongo-operator-cluster-mongo-cluster-2018-02-28_140000.archive.gz" self.restore_helper.restore(self.cluster_object, expected_backup_name) self.assertEqual([ call.getSecret("storage-serviceaccount", "mongo-operator-cluster") ], self.kubernetes_service.mock_calls) subprocess_mock.assert_called_once_with([ "mongorestore", "--host", ",".join(self.expected_cluster_members), "--gzip", "--archive=/tmp/" + expected_backup_name ]) expected_service_call = call.from_service_account_info( {"user": "******"}) self.assertEqual([expected_service_call], gcs_service_mock.mock_calls) expected_storage_calls = [ call( gcs_service_mock.from_service_account_info.return_value. project_id, gcs_service_mock.from_service_account_info.return_value), call().get_bucket("ultimaker-mongo-backups"), call().get_bucket().blob("test-backups/" + expected_backup_name), call().get_bucket().blob().download_to_filename( "/tmp/" + expected_backup_name), ] self.assertEqual(expected_storage_calls, storage_mock.mock_calls) expected_os_call = call.remove("/tmp/" + expected_backup_name) self.assertEqual([expected_os_call], os_mock.mock_calls)
def test_do(self): char = Character(alias='test char 1') skill = Skill(9, level=5) char.skills.add(skill) # Action econt_calls_before = len(char._eos_fit.skills.mock_calls) char.skills.remove(skill) econt_calls_after = len(char._eos_fit.skills.mock_calls) # Pyfa model self.assertEqual(len(char.skills), 0) self.assertEqual(skill.eve_id, 9) self.assertEqual(skill.level, 5) self.assertIs(skill.eve_name, None) # Eos model self.assertEqual(econt_calls_after - econt_calls_before, 1) self.assertEqual(char._eos_fit.skills.mock_calls[-1], call.remove(skill._eos_item)) # Reload model via persistence (DB check) char.persist() econt_calls_before = len(char._eos_fit.skills.mock_calls) self.pyfadb_force_reload() chars = self.query_chars() self.assertEqual(len(chars), 1) char = chars[0] econt_calls_after = len(char._eos_fit.skills.mock_calls) # Pyfa model self.assertEqual(len(char.skills), 0) # Eos model self.assertEqual(econt_calls_after - econt_calls_before, 0)
def test_backup(self, subprocess_mock, gcs_service_mock, storage_mock, os_mock): current_date = datetime(2018, 2, 28, 14, 0, 0) expected_backup_name = "mongodb-backup-default-mongo-cluster-2018-02-28_140000.archive.gz" self.checker.backup(self.cluster_object, current_date) self.assertEqual([call.getSecret('storage-serviceaccount', 'default')], self.kubernetes_service.mock_calls) subprocess_mock.assert_called_once_with([ 'mongodump', '--host', 'mongo-cluster-2.mongo-cluster.default.svc.cluster.local', '--gzip', '--archive=/tmp/' + expected_backup_name ]) expected_service_call = call.from_service_account_info( {'user': '******'}) self.assertEqual([expected_service_call], gcs_service_mock.mock_calls) expected_storage_calls = [ call( gcs_service_mock.from_service_account_info.return_value. project_id, gcs_service_mock.from_service_account_info.return_value), call().bucket('ultimaker-mongo-backups'), call().bucket().blob('test-backups/' + expected_backup_name), call().bucket().blob().upload_from_filename('/tmp/' + expected_backup_name), ] self.assertEqual(expected_storage_calls, storage_mock.mock_calls) expected_os_call = call.remove('/tmp/' + expected_backup_name) self.assertEqual([expected_os_call], os_mock.mock_calls)
def test_backup(self, subprocess_mock, gcs_service_mock, storage_mock, os_mock): current_date = datetime(2018, 2, 28, 14, 0, 0) expected_backup_name = "mongodb-backup-mongo-operator-cluster-mongo-cluster-2018-02-28_140000.archive.gz" self.checker.backup(self.cluster_object, current_date) self.assertEqual([ call.getSecret("storage-serviceaccount", "mongo-operator-cluster") ], self.kubernetes_service.mock_calls) subprocess_mock.assert_called_once_with([ "mongodump", "--host", "mongo-cluster-2.mongo-cluster.mongo-operator-cluster.svc.cluster.local", "--gzip", "--archive=/tmp/" + expected_backup_name ]) expected_service_call = call.from_service_account_info( {"user": "******"}) self.assertEqual([expected_service_call], gcs_service_mock.mock_calls) expected_storage_calls = [ call( gcs_service_mock.from_service_account_info.return_value. project_id, gcs_service_mock.from_service_account_info.return_value), call().bucket("ultimaker-mongo-backups"), call().bucket().blob("test-backups/" + expected_backup_name), call().bucket().blob().upload_from_filename("/tmp/" + expected_backup_name), ] self.assertEqual(expected_storage_calls, storage_mock.mock_calls) expected_os_call = call.remove("/tmp/" + expected_backup_name) self.assertEqual([expected_os_call], os_mock.mock_calls)
def test_already_removed(self): """Attempt removal of skill already removed from the device. When this happens, an AlreadyRemoved exception is raised and the device skill state is not modified. """ skill_to_remove = self.skill_entry_mock() skill_to_remove.name = 'skill-foo' skill_to_remove.remove = Mock(side_effect=AlreadyRemoved()) pre_install_hash = device_skill_state_hash(self.msm.device_skill_state) with patch('msm.mycroft_skills_manager.isinstance') as isinstance_mock: isinstance_mock.return_value = True self.msm.remove(skill_to_remove) self.assertListEqual([call.remove()], skill_to_remove.method_calls) self.assertIsNotNone(self.msm._local_skills) self.assertIn('all_skills', self.msm._cache) post_install_hash = device_skill_state_hash( self.msm.device_skill_state) self.assertEqual(pre_install_hash, post_install_hash)
def test_remove_failure(self): """Skill removal attempt fails for whatever reason When n removal fails, a MsmException is raised. The removal will not be saved to the device skill state. """ skill_to_remove = self.skill_entry_mock() skill_to_remove.name = 'skill-test' skill_to_remove.remove = Mock(side_effect=MsmException('RED ALERT!')) pre_install_hash = device_skill_state_hash(self.msm.device_skill_state) with patch('msm.mycroft_skills_manager.isinstance') as isinstance_mock: isinstance_mock.return_value = True with self.assertRaises(MsmException): self.msm.remove(skill_to_remove) self.assertListEqual([call.remove()], skill_to_remove.method_calls) self.assertIsNotNone(self.msm._local_skills) self.assertIn('all_skills', self.msm._cache) post_install_hash = device_skill_state_hash( self.msm.device_skill_state) self.assertEqual(pre_install_hash, post_install_hash)