def test_handle(self): c = loader.Command() with patch.object(c, 'stdout') as stdout: c.handle() stdout.write.assert_any_call( '\nFor SearchPlugin\nLoaded 0 lookup lists\n\n\nNew items report:\n\n\n0 new items 0 new synonyms' )
def test_add_arguments(self): c = loader.Command() parser = MagicMock() c.add_arguments(parser) parser.add_argument.assert_called_once_with('--file', help="Specify import file", dest="filename")
def test_handle_explicit_filename(self): c = loader.Command() with patch.object(c, 'stdout') as stdout: c.handle(filename='this.json') stdout.write.assert_any_call( '\nFor this.json\nLoaded 0 lookup lists\n\n\nNew items report:\n\n\n0 new items 0 new synonyms' )
def test_from_path_does_not_exist(self): mock_path = MagicMock() if hasattr(mock_path, '__bool__'): mock_path.__bool__.return_value = False else: mock_path.__nonzero__.return_value = False c = loader.Command() self.assertEqual({}, c.from_path(mock_path))
def test_from_path_json(self): mock_path = MagicMock() if hasattr(mock_path, '__bool__'): mock_path.__bool__.return_value = True else: mock_path.__nonzero__.return_value = True mock_path.json_load.return_value = {'hai': 'world'} c = loader.Command() self.assertEqual({'hai': 'world'}, c.from_path(mock_path))
def test_from_file_when_no_file(self, path, isfile): plugin = MagicMock() plugin.directory = MagicMock(return_value="somePlugin") plugin.__name__ = "somePlugin" isfile.return_value = False path.return_value.json_load.return_value = {} c = loader.Command() c._from_file(plugin) self.assertEqual(path.called, False)
def test_from_file(self, path, isfile): plugin = MagicMock() plugin.directory = MagicMock(return_value="somePlugin") plugin.__name__ = "somePlugin" isfile.return_value = True path.return_value.json_load.return_value = {} c = loader.Command() c._from_file(plugin) path.assert_called_with('somePlugin/data/lookuplists/lookuplists.json')
def test_from_component(self, path): c = loader.Command() c.from_component(application.get_app()) calls = [c[0][0] for c in path.call_args_list] expected = [ 'data/lookuplists/lookuplists.json', 'data/lookuplists/drug.json', 'data/lookuplists/condition.json' ] for e in expected: self.assertTrue(len([c for c in calls if c.endswith(e)]) == 1)
def test_handle_load_colour(self, path): path.return_value.json_load.return_value = { 'dog': [{ 'name': 'terrier', 'synonyms': ['yorkshire terrier'] }] } c = loader.Command() with patch.object(c.stdout, 'write'): # Quiet down our test running c.handle(filename='this.json') self.assertEqual(1, Dog.objects.filter(name='terrier').count())
def test_handle(self, is_file, load_lookup_lists, get_all_components): plugin = MagicMock() plugin.directory = MagicMock(return_value="somePlugin") plugin.__name__ = "somePlugin" get_all_components.return_value = [plugin] is_file.return_value = {} load_lookup_lists.return_value = (1, 2, 3) cmd = loader.Command() cmd.stdout = MagicMock() cmd.handle() self.assertEqual( cmd.stdout.write.call_args[0][0], '\nFor somePlugin\nLoaded 1 lookup lists\n\n\nNew items report:\n\n\n2 new items 3 new synonyms' )
def test_handle_empty_file(self, path): path.return_value.json_load.return_value = {} c = loader.Command() with patch.object(c.stdout, 'write'): # Quiet down our test running c.handle(filename='this.json') path.assert_called_with('this.json')
def test_handle_no_lookuplist(self): c = loader.Command() with self.assertRaises(ValueError): c.handle()
def test_init(self): c = loader.Command() self.assertEqual(0, c.items_created) self.assertEqual(0, c.synonyms_created)
def test_handle_with_filename(self): c = loader.Command() with patch.object(c, 'handle_explicit_filename') as handler: c.handle(filename="this.json") handler.assert_called_with(filename='this.json')
def test_init_sets_counter(self): c = loader.Command() self.assertEqual(0, c.num) self.assertEqual(0, c.created) self.assertEqual(0, c.synonyms)