def test_put(self, get_proxy: MagicMock, RequestParser: MagicMock) -> None: mock_proxy = get_proxy.return_value = Mock() RequestParser().parse_args.return_value = dict(data=[], index='fake_index') response = DocumentTablesAPI().put() self.assertEqual(list(response)[1], HTTPStatus.OK) mock_proxy.update_document.assert_called_with(data=[], index='fake_index')
def test_put(self, get_proxy, RequestParser, TableSchema) -> None: mock_proxy = get_proxy.return_value = Mock() RequestParser().parse_args.return_value = dict(data='{}', index='fake_index') expected_value = TableSchema().loads.return_value = Mock() response = DocumentTablesAPI().put() self.assertEqual(list(response)[1], HTTPStatus.OK) mock_proxy.update_document.assert_called_with(data=expected_value, index='fake_index')
def test_put_multiple_tables_fails(self, get_proxy: MagicMock, RequestParser: MagicMock) -> None: input_data = [ json.dumps({'anykey1': 'anyval1'}), json.dumps({'anykey2': 'anyval2'}) ] RequestParser().parse_args.return_value = dict(data=input_data, index='fake_index') with self.assertRaises(ValidationError): DocumentTablesAPI().put()
def test_put_multiple_tables(self, get_proxy: MagicMock, RequestParser: MagicMock) -> None: mock_proxy = get_proxy.return_value = Mock() input_data = [ json.dumps({ 'id': 'table1', 'key': 'table1', 'cluster': 'cluster1', 'database': 'database1', 'name': 'name1', 'schema': 'schema1', 'last_updated_timestamp': 12345678, 'tags': [{'tag_name': 'tag1'}, {'tag_name': 'tag2'}] }), json.dumps({ 'id': 'table2', 'key': 'table2', 'cluster': 'cluster2', 'database': 'database2', 'name': 'name2', 'schema': 'schema2', 'last_updated_timestamp': 12345678, 'tags': [{'tag_name': 'tag3'}, {'tag_name': 'tag4'}] }) ] RequestParser().parse_args.return_value = dict(data=input_data, index='fake_index') expected_data = [Table(id='table1', database='database1', cluster='cluster1', schema='schema1', name='name1', key='table1', tags=[Tag(tag_name='tag1'), Tag(tag_name='tag2')], last_updated_timestamp=12345678), Table(id='table2', database='database2', cluster='cluster2', schema='schema2', name='name2', key='table2', tags=[Tag(tag_name='tag3'), Tag(tag_name='tag4')], last_updated_timestamp=12345678)] response = DocumentTablesAPI().put() self.assertEqual(list(response)[1], HTTPStatus.OK) mock_proxy.update_document.assert_called_with(data=expected_data, index='fake_index')