| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | import re | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2021-08-26 10:49:41 +01:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2018-07-10 13:50:47 -04:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2018-07-11 11:39:40 -04:00
										 |  |  | from botocore.client import ClientError | 
					
						
							| 
									
										
										
										
											2018-07-10 13:50:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-10 00:56:08 +01:00
										 |  |  | from datetime import datetime, timezone | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  | from freezegun import freeze_time | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  | from moto import mock_glue, settings | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  | from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | from . import helpers | 
					
						
							| 
									
										
										
										
											2018-07-10 13:50:47 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-09 15:42:16 +02:00
										 |  |  | FROZEN_CREATE_TIME = datetime(2015, 1, 1, 0, 0, 0, tzinfo=timezone.utc) | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-10 13:50:47 -04:00
										 |  |  | @mock_glue | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  | @freeze_time(FROZEN_CREATE_TIME) | 
					
						
							| 
									
										
										
										
											2018-07-10 13:50:47 -04:00
										 |  |  | def test_create_database(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2022-07-27 14:38:08 +02:00
										 |  |  |     database_catalog_id = ACCOUNT_ID | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  |     database_input = helpers.create_database_input(database_name) | 
					
						
							| 
									
										
										
										
											2022-07-27 14:38:08 +02:00
										 |  |  |     helpers.create_database(client, database_name, database_input, database_catalog_id) | 
					
						
							| 
									
										
										
										
											2018-07-10 13:50:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |     response = helpers.get_database(client, database_name) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     database = response["Database"] | 
					
						
							| 
									
										
										
										
											2018-07-10 13:50:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  |     database.get("Name").should.equal(database_name) | 
					
						
							|  |  |  |     database.get("Description").should.equal(database_input.get("Description")) | 
					
						
							|  |  |  |     database.get("LocationUri").should.equal(database_input.get("LocationUri")) | 
					
						
							|  |  |  |     database.get("Parameters").should.equal(database_input.get("Parameters")) | 
					
						
							|  |  |  |     if not settings.TEST_SERVER_MODE: | 
					
						
							| 
									
										
										
										
											2023-02-09 15:42:16 +02:00
										 |  |  |         database.get("CreateTime").timestamp().should.equal( | 
					
						
							|  |  |  |             FROZEN_CREATE_TIME.timestamp() | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  |     database.get("CreateTableDefaultPermissions").should.equal( | 
					
						
							|  |  |  |         database_input.get("CreateTableDefaultPermissions") | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     database.get("TargetDatabase").should.equal(database_input.get("TargetDatabase")) | 
					
						
							| 
									
										
										
										
											2022-07-27 14:38:08 +02:00
										 |  |  |     database.get("CatalogId").should.equal(database_catalog_id) | 
					
						
							| 
									
										
										
										
											2018-07-11 11:39:40 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_create_database_already_exists(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "cantcreatethisdatabasetwice" | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							| 
									
										
										
										
											2018-07-11 11:39:40 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |         helpers.create_database(client, database_name) | 
					
						
							| 
									
										
										
										
											2018-07-11 11:39:40 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("AlreadyExistsException") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_database_not_exits(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "nosuchdatabase" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |         helpers.get_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Database nosuchdatabase not found" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 20:10:39 +02:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_databases_empty(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     response = client.get_databases() | 
					
						
							|  |  |  |     response["DatabaseList"].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_databases_several_items(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name_1, database_name_2 = "firstdatabase", "seconddatabase" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  |     helpers.create_database(client, database_name_1, {"Name": database_name_1}) | 
					
						
							|  |  |  |     helpers.create_database(client, database_name_2, {"Name": database_name_2}) | 
					
						
							| 
									
										
										
										
											2020-04-21 20:10:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 22:33:55 +02:00
										 |  |  |     database_list = sorted( | 
					
						
							|  |  |  |         client.get_databases()["DatabaseList"], key=lambda x: x["Name"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-04-21 20:10:39 +02:00
										 |  |  |     database_list.should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2021-01-11 13:10:18 +00:00
										 |  |  |     database_list[0]["Name"].should.equal(database_name_1) | 
					
						
							|  |  |  |     database_list[1]["Name"].should.equal(database_name_2) | 
					
						
							| 
									
										
										
										
											2020-04-21 20:10:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-24 11:24:05 +02:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_update_database(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "existingdatabase" | 
					
						
							|  |  |  |     database_catalog_id = ACCOUNT_ID | 
					
						
							|  |  |  |     helpers.create_database( | 
					
						
							|  |  |  |         client, database_name, {"Name": database_name}, database_catalog_id | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_database(client, database_name) | 
					
						
							|  |  |  |     database = response["Database"] | 
					
						
							|  |  |  |     database.get("CatalogId").should.equal(database_catalog_id) | 
					
						
							|  |  |  |     database.get("Description").should.be.none | 
					
						
							|  |  |  |     database.get("LocationUri").should.be.none | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     database_input = { | 
					
						
							|  |  |  |         "Name": database_name, | 
					
						
							|  |  |  |         "Description": "desc", | 
					
						
							|  |  |  |         "LocationUri": "s3://bucket/existingdatabase/", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     client.update_database( | 
					
						
							|  |  |  |         CatalogId=database_catalog_id, Name=database_name, DatabaseInput=database_input | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_database(client, database_name) | 
					
						
							|  |  |  |     database = response["Database"] | 
					
						
							|  |  |  |     database.get("CatalogId").should.equal(database_catalog_id) | 
					
						
							|  |  |  |     database.get("Description").should.equal("desc") | 
					
						
							|  |  |  |     database.get("LocationUri").should.equal("s3://bucket/existingdatabase/") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_update_unknown_database(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.update_database(Name="x", DatabaseInput={"Name": "x"}) | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     err["Message"].should.equal("Database x not found.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 12:21:45 -01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_database(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name_1, database_name_2 = "firstdatabase", "seconddatabase" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_database(client, database_name_1, {"Name": database_name_1}) | 
					
						
							|  |  |  |     helpers.create_database(client, database_name_2, {"Name": database_name_2}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.delete_database(Name=database_name_1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     database_list = sorted( | 
					
						
							|  |  |  |         client.get_databases()["DatabaseList"], key=lambda x: x["Name"] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     [db["Name"] for db in database_list].should.equal([database_name_2]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_unknown_database(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.delete_database(Name="x") | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     err["Message"].should.equal("Database x not found.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | @mock_glue | 
					
						
							| 
									
										
										
										
											2022-06-20 17:29:16 -05:00
										 |  |  | @freeze_time(FROZEN_CREATE_TIME) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | def test_create_table(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table_name = "myspecialtable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     table_input = helpers.create_table_input(database_name, table_name) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |     helpers.create_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_table(client, database_name, table_name) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table = response["Table"] | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-20 17:29:16 -05:00
										 |  |  |     if not settings.TEST_SERVER_MODE: | 
					
						
							| 
									
										
										
										
											2023-02-09 15:42:16 +02:00
										 |  |  |         table["CreateTime"].timestamp().should.equal(FROZEN_CREATE_TIME.timestamp()) | 
					
						
							| 
									
										
										
										
											2022-06-20 17:29:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table["Name"].should.equal(table_input["Name"]) | 
					
						
							|  |  |  |     table["StorageDescriptor"].should.equal(table_input["StorageDescriptor"]) | 
					
						
							|  |  |  |     table["PartitionKeys"].should.equal(table_input["PartitionKeys"]) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_create_table_already_exists(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table_name = "cantcreatethistabletwice" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |         helpers.create_table(client, database_name, table_name) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("AlreadyExistsException") | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_tables(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table_names = ["myfirsttable", "mysecondtable", "mythirdtable"] | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |     table_inputs = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for table_name in table_names: | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |         table_input = helpers.create_table_input(database_name, table_name) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  |         table_inputs[table_name] = table_input | 
					
						
							|  |  |  |         helpers.create_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_tables(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     tables = response["TableList"] | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     tables.should.have.length_of(3) | 
					
						
							| 
									
										
										
										
											2018-07-26 17:05:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for table in tables: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         table_name = table["Name"] | 
					
						
							|  |  |  |         table_name.should.equal(table_inputs[table_name]["Name"]) | 
					
						
							|  |  |  |         table["StorageDescriptor"].should.equal( | 
					
						
							|  |  |  |             table_inputs[table_name]["StorageDescriptor"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         table["PartitionKeys"].should.equal(table_inputs[table_name]["PartitionKeys"]) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 11:44:01 +01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_tables_expression(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     table_names = [ | 
					
						
							|  |  |  |         "mytableprefix_123", | 
					
						
							|  |  |  |         "mytableprefix_something_test", | 
					
						
							|  |  |  |         "something_mytablepostfix", | 
					
						
							|  |  |  |         "test_catchthis123_test", | 
					
						
							|  |  |  |         "asduas6781catchthisasdas", | 
					
						
							|  |  |  |         "fakecatchthisfake", | 
					
						
							| 
									
										
										
										
											2022-10-05 22:27:08 +01:00
										 |  |  |         "trailingtest.", | 
					
						
							|  |  |  |         "trailingtest...", | 
					
						
							| 
									
										
										
										
											2022-09-28 11:44:01 +01:00
										 |  |  |     ] | 
					
						
							|  |  |  |     table_inputs = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for table_name in table_names: | 
					
						
							|  |  |  |         table_input = helpers.create_table_input(database_name, table_name) | 
					
						
							|  |  |  |         table_inputs[table_name] = table_input | 
					
						
							|  |  |  |         helpers.create_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     prefix_expression = "mytableprefix_\\w+" | 
					
						
							|  |  |  |     postfix_expression = "\\w+_mytablepostfix" | 
					
						
							|  |  |  |     string_expression = "\\w+catchthis\\w+" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-05 22:27:08 +01:00
										 |  |  |     # even though * is an invalid regex, sadly glue api treats it as a glob-like wildcard | 
					
						
							|  |  |  |     star_expression1 = "*" | 
					
						
							|  |  |  |     star_expression2 = "mytable*" | 
					
						
							|  |  |  |     star_expression3 = "*table*" | 
					
						
							|  |  |  |     star_expression4 = "*catch*is*" | 
					
						
							|  |  |  |     star_expression5 = ".*catch*is*" | 
					
						
							|  |  |  |     star_expression6 = "trailing*.*" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 11:44:01 +01:00
										 |  |  |     response_prefix = helpers.get_tables(client, database_name, prefix_expression) | 
					
						
							|  |  |  |     response_postfix = helpers.get_tables(client, database_name, postfix_expression) | 
					
						
							|  |  |  |     response_string_match = helpers.get_tables(client, database_name, string_expression) | 
					
						
							| 
									
										
										
										
											2022-10-05 22:27:08 +01:00
										 |  |  |     response_star_expression1 = helpers.get_tables( | 
					
						
							|  |  |  |         client, database_name, star_expression1 | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response_star_expression2 = helpers.get_tables( | 
					
						
							|  |  |  |         client, database_name, star_expression2 | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response_star_expression3 = helpers.get_tables( | 
					
						
							|  |  |  |         client, database_name, star_expression3 | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response_star_expression4 = helpers.get_tables( | 
					
						
							|  |  |  |         client, database_name, star_expression4 | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response_star_expression5 = helpers.get_tables( | 
					
						
							|  |  |  |         client, database_name, star_expression5 | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response_star_expression6 = helpers.get_tables( | 
					
						
							|  |  |  |         client, database_name, star_expression6 | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2022-09-28 11:44:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     tables_prefix = response_prefix["TableList"] | 
					
						
							|  |  |  |     tables_postfix = response_postfix["TableList"] | 
					
						
							|  |  |  |     tables_string_match = response_string_match["TableList"] | 
					
						
							| 
									
										
										
										
											2022-10-05 22:27:08 +01:00
										 |  |  |     tables_star_expression1 = response_star_expression1["TableList"] | 
					
						
							|  |  |  |     tables_star_expression2 = response_star_expression2["TableList"] | 
					
						
							|  |  |  |     tables_star_expression3 = response_star_expression3["TableList"] | 
					
						
							|  |  |  |     tables_star_expression4 = response_star_expression4["TableList"] | 
					
						
							|  |  |  |     tables_star_expression5 = response_star_expression5["TableList"] | 
					
						
							|  |  |  |     tables_star_expression6 = response_star_expression6["TableList"] | 
					
						
							| 
									
										
										
										
											2022-09-28 11:44:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     tables_prefix.should.have.length_of(2) | 
					
						
							|  |  |  |     tables_postfix.should.have.length_of(1) | 
					
						
							|  |  |  |     tables_string_match.should.have.length_of(3) | 
					
						
							| 
									
										
										
										
											2022-10-05 22:27:08 +01:00
										 |  |  |     tables_star_expression1.should.have.length_of(8) | 
					
						
							|  |  |  |     tables_star_expression2.should.have.length_of(2) | 
					
						
							|  |  |  |     tables_star_expression3.should.have.length_of(3) | 
					
						
							|  |  |  |     tables_star_expression4.should.have.length_of(3) | 
					
						
							|  |  |  |     tables_star_expression5.should.have.length_of(3) | 
					
						
							|  |  |  |     tables_star_expression6.should.have.length_of(2) | 
					
						
							| 
									
										
										
										
											2022-09-28 11:44:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_table_versions(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     version_inputs = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     table_input = helpers.create_table_input(database_name, table_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  |     version_inputs["1"] = table_input | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-03 18:43:44 -01:00
										 |  |  |     # Get table should retrieve the first version | 
					
						
							|  |  |  |     table = client.get_table(DatabaseName=database_name, Name=table_name)["Table"] | 
					
						
							|  |  |  |     table["StorageDescriptor"]["Columns"].should.equal([]) | 
					
						
							|  |  |  |     table["VersionId"].should.equal("1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     columns = [{"Name": "country", "Type": "string"}] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     table_input = helpers.create_table_input(database_name, table_name, columns=columns) | 
					
						
							|  |  |  |     helpers.update_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  |     version_inputs["2"] = table_input | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:21:11 -08:00
										 |  |  |     # Updateing with an identical input should still create a new version | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.update_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  |     version_inputs["3"] = table_input | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_table_versions(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vers = response["TableVersions"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     vers.should.have.length_of(3) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     vers[0]["Table"]["StorageDescriptor"]["Columns"].should.equal([]) | 
					
						
							|  |  |  |     vers[-1]["Table"]["StorageDescriptor"]["Columns"].should.equal(columns) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for n, ver in enumerate(vers): | 
					
						
							|  |  |  |         n = str(n + 1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ver["VersionId"].should.equal(n) | 
					
						
							| 
									
										
										
										
											2023-02-17 10:35:15 -01:00
										 |  |  |         ver["Table"]["VersionId"].should.equal(n) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         ver["Table"]["Name"].should.equal(table_name) | 
					
						
							|  |  |  |         ver["Table"]["StorageDescriptor"].should.equal( | 
					
						
							|  |  |  |             version_inputs[n]["StorageDescriptor"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         ver["Table"]["PartitionKeys"].should.equal(version_inputs[n]["PartitionKeys"]) | 
					
						
							| 
									
										
										
										
											2023-02-17 10:35:15 -01:00
										 |  |  |         ver["Table"].should.have.key("UpdateTime") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_table_version(client, database_name, table_name, "3") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ver = response["TableVersion"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ver["VersionId"].should.equal("3") | 
					
						
							|  |  |  |     ver["Table"]["Name"].should.equal(table_name) | 
					
						
							|  |  |  |     ver["Table"]["StorageDescriptor"]["Columns"].should.equal(columns) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-03 18:43:44 -01:00
										 |  |  |     # get_table should retrieve the latest version | 
					
						
							|  |  |  |     table = client.get_table(DatabaseName=database_name, Name=table_name)["Table"] | 
					
						
							|  |  |  |     table["StorageDescriptor"]["Columns"].should.equal(columns) | 
					
						
							|  |  |  |     table["VersionId"].should.equal("3") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     table = client.get_tables(DatabaseName=database_name)["TableList"][0] | 
					
						
							|  |  |  |     table["StorageDescriptor"]["Columns"].should.equal(columns) | 
					
						
							|  |  |  |     table["VersionId"].should.equal("3") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_table_version_not_found(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         helpers.get_table_version(client, database_name, "myfirsttable", "20") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match("version", re.I) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_table_version_invalid_input(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         helpers.get_table_version(client, database_name, "myfirsttable", "10not-an-int") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("InvalidInputException") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-24 20:24:01 -01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_table_version(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     version_inputs = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     table_input = helpers.create_table_input(database_name, table_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  |     version_inputs["1"] = table_input | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     columns = [{"Name": "country", "Type": "string"}] | 
					
						
							|  |  |  |     table_input = helpers.create_table_input(database_name, table_name, columns=columns) | 
					
						
							|  |  |  |     helpers.update_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  |     version_inputs["2"] = table_input | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Updateing with an identical input should still create a new version | 
					
						
							|  |  |  |     helpers.update_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  |     version_inputs["3"] = table_input | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_table_versions(client, database_name, table_name) | 
					
						
							|  |  |  |     vers = response["TableVersions"] | 
					
						
							|  |  |  |     vers.should.have.length_of(3) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.delete_table_version( | 
					
						
							|  |  |  |         DatabaseName=database_name, TableName=table_name, VersionId="2" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.get_table_versions(client, database_name, table_name) | 
					
						
							|  |  |  |     vers = response["TableVersions"] | 
					
						
							|  |  |  |     vers.should.have.length_of(2) | 
					
						
							|  |  |  |     [v["VersionId"] for v in vers].should.equal(["1", "3"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_table_not_exits(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         helpers.get_table(client, database_name, "myfirsttable") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:46:05 +02:00
										 |  |  |     exc.value.response["Error"]["Message"].should.match("Table myfirsttable not found") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_table_when_database_not_exits(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "nosuchdatabase" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         helpers.get_table(client, database_name, "myfirsttable") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Database nosuchdatabase not found" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 04:58:41 -05:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_table(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2019-05-25 04:58:41 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table_name = "myspecialtable" | 
					
						
							| 
									
										
										
										
											2019-05-25 04:58:41 -05:00
										 |  |  |     table_input = helpers.create_table_input(database_name, table_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     result = client.delete_table(DatabaseName=database_name, Name=table_name) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							| 
									
										
										
										
											2019-05-25 04:58:41 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # confirm table is deleted | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-05-25 04:58:41 -05:00
										 |  |  |         helpers.get_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Table myspecialtable not found" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 04:58:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-10 14:14:30 -05:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_delete_table(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							| 
									
										
										
										
											2019-06-10 14:14:30 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     table_name = "myspecialtable" | 
					
						
							| 
									
										
										
										
											2019-06-10 14:14:30 -05:00
										 |  |  |     table_input = helpers.create_table_input(database_name, table_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name, table_input) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     result = client.batch_delete_table( | 
					
						
							|  |  |  |         DatabaseName=database_name, TablesToDelete=[table_name] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							| 
									
										
										
										
											2019-06-10 14:14:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # confirm table is deleted | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-06-10 14:14:30 -05:00
										 |  |  |         helpers.get_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Table myspecialtable not found" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-06-10 14:14:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 04:58:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_partitions_empty(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_partitions(DatabaseName=database_name, TableName=table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response["Partitions"].should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_create_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-10 00:56:08 +01:00
										 |  |  |     before = datetime.now(timezone.utc) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     part_input = helpers.create_partition_input( | 
					
						
							|  |  |  |         database_name, table_name, values=values | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_partition(client, database_name, table_name, part_input) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-10 00:56:08 +01:00
										 |  |  |     after = datetime.now(timezone.utc) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_partitions(DatabaseName=database_name, TableName=table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partitions = response["Partitions"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     partitions.should.have.length_of(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partition = partitions[0] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partition["TableName"].should.equal(table_name) | 
					
						
							|  |  |  |     partition["StorageDescriptor"].should.equal(part_input["StorageDescriptor"]) | 
					
						
							|  |  |  |     partition["Values"].should.equal(values) | 
					
						
							|  |  |  |     partition["CreationTime"].should.be.greater_than(before) | 
					
						
							|  |  |  |     partition["CreationTime"].should.be.lower_than(after) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_create_partition_already_exist(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |         helpers.create_partition(client, database_name, table_name, values=values) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("AlreadyExistsException") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_partition_not_found(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |         helpers.get_partition(client, database_name, table_name, values) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match("partition") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_create_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-10 00:56:08 +01:00
										 |  |  |     before = datetime.now(timezone.utc) | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     partition_inputs = [] | 
					
						
							|  |  |  |     for i in range(0, 20): | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         values = [f"2018-10-{i:2}"] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         part_input = helpers.create_partition_input( | 
					
						
							|  |  |  |             database_name, table_name, values=values | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  |         partition_inputs.append(part_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.batch_create_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         PartitionInputList=partition_inputs, | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-10 00:56:08 +01:00
										 |  |  |     after = datetime.now(timezone.utc) | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_partitions(DatabaseName=database_name, TableName=table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partitions = response["Partitions"] | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     partitions.should.have.length_of(20) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for idx, partition in enumerate(partitions): | 
					
						
							|  |  |  |         partition_input = partition_inputs[idx] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         partition["TableName"].should.equal(table_name) | 
					
						
							|  |  |  |         partition["StorageDescriptor"].should.equal( | 
					
						
							|  |  |  |             partition_input["StorageDescriptor"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         partition["Values"].should.equal(partition_input["Values"]) | 
					
						
							|  |  |  |         partition["CreationTime"].should.be.greater_than(before) | 
					
						
							|  |  |  |         partition["CreationTime"].should.be.lower_than(after) | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_create_partition_already_exist(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partition_input = helpers.create_partition_input( | 
					
						
							|  |  |  |         database_name, table_name, values=values | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.batch_create_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         PartitionInputList=[partition_input], | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response.should.have.key("Errors") | 
					
						
							|  |  |  |     response["Errors"].should.have.length_of(1) | 
					
						
							|  |  |  |     response["Errors"][0]["PartitionValues"].should.equal(values) | 
					
						
							|  |  |  |     response["Errors"][0]["ErrorDetail"]["ErrorCode"].should.equal( | 
					
						
							|  |  |  |         "AlreadyExistsException" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-06-07 03:28:10 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     values = [["2018-10-01"], ["2018-09-01"]] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[0]) | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[1]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response = client.get_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, TableName=table_name, PartitionValues=values[1] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partition = response["Partition"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partition["TableName"].should.equal(table_name) | 
					
						
							|  |  |  |     partition["Values"].should.equal(values[1]) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_get_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     values = [["2018-10-01"], ["2018-09-01"]] | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[0]) | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[1]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partitions_to_get = [{"Values": values[0]}, {"Values": values[1]}] | 
					
						
							|  |  |  |     response = client.batch_get_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							|  |  |  |         PartitionsToGet=partitions_to_get, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partitions = response["Partitions"] | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  |     partitions.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partition = partitions[1] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partition["TableName"].should.equal(table_name) | 
					
						
							|  |  |  |     partition["Values"].should.equal(values[1]) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_get_partition_missing_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     values = [["2018-10-01"], ["2018-09-01"], ["2018-08-01"]] | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[0]) | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[2]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partitions_to_get = [ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         {"Values": values[0]}, | 
					
						
							|  |  |  |         {"Values": values[1]}, | 
					
						
							|  |  |  |         {"Values": values[2]}, | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  |     ] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response = client.batch_get_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							|  |  |  |         PartitionsToGet=partitions_to_get, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partitions = response["Partitions"] | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  |     partitions.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partitions[0]["Values"].should.equal(values[0]) | 
					
						
							|  |  |  |     partitions[1]["Values"].should.equal(values[2]) | 
					
						
							| 
									
										
										
										
											2019-07-17 14:07:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_update_partition_not_found_moving(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         helpers.update_partition( | 
					
						
							|  |  |  |             client, | 
					
						
							|  |  |  |             database_name, | 
					
						
							|  |  |  |             table_name, | 
					
						
							|  |  |  |             old_values=["0000-00-00"], | 
					
						
							|  |  |  |             values=["2018-10-02"], | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match("partition") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_update_partition_not_found_change_in_place(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         helpers.update_partition( | 
					
						
							|  |  |  |             client, database_name, table_name, old_values=values, values=values | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match("partition") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_update_partition_cannot_overwrite(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     values = [["2018-10-01"], ["2018-09-01"]] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[0]) | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values[1]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         helpers.update_partition( | 
					
						
							|  |  |  |             client, database_name, table_name, old_values=values[0], values=values[1] | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("AlreadyExistsException") | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_update_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.update_partition( | 
					
						
							|  |  |  |         client, | 
					
						
							|  |  |  |         database_name, | 
					
						
							|  |  |  |         table_name, | 
					
						
							|  |  |  |         old_values=values, | 
					
						
							|  |  |  |         values=values, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         columns=[{"Name": "country", "Type": "string"}], | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response = client.get_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, TableName=table_name, PartitionValues=values | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     partition = response["Partition"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partition["TableName"].should.equal(table_name) | 
					
						
							|  |  |  |     partition["StorageDescriptor"]["Columns"].should.equal( | 
					
						
							|  |  |  |         [{"Name": "country", "Type": "string"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_update_partition_move(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							|  |  |  |     new_values = ["2018-09-01"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  |     helpers.create_partition(client, database_name, table_name, values=values) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = helpers.update_partition( | 
					
						
							|  |  |  |         client, | 
					
						
							|  |  |  |         database_name, | 
					
						
							|  |  |  |         table_name, | 
					
						
							|  |  |  |         old_values=values, | 
					
						
							|  |  |  |         values=new_values, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         columns=[{"Name": "country", "Type": "string"}], | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  |         helpers.get_partition(client, database_name, table_name, values) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Old partition shouldn't exist anymore | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, TableName=table_name, PartitionValues=new_values | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     partition = response["Partition"] | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partition["TableName"].should.equal(table_name) | 
					
						
							|  |  |  |     partition["StorageDescriptor"]["Columns"].should.equal( | 
					
						
							|  |  |  |         [{"Name": "country", "Type": "string"}] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-10-02 17:25:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-10 14:03:37 -06:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_update_partition(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     values = [ | 
					
						
							|  |  |  |         ["2020-12-04"], | 
					
						
							|  |  |  |         ["2020-12-05"], | 
					
						
							|  |  |  |         ["2020-12-06"], | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_values = [ | 
					
						
							|  |  |  |         ["2020-11-04"], | 
					
						
							|  |  |  |         ["2020-11-05"], | 
					
						
							|  |  |  |         ["2020-11-06"], | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     batch_update_values = [] | 
					
						
							|  |  |  |     for idx, value in enumerate(values): | 
					
						
							|  |  |  |         helpers.create_partition(client, database_name, table_name, values=value) | 
					
						
							|  |  |  |         batch_update_values.append( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "PartitionValueList": value, | 
					
						
							|  |  |  |                 "PartitionInput": helpers.create_partition_input( | 
					
						
							|  |  |  |                     database_name, | 
					
						
							|  |  |  |                     table_name, | 
					
						
							|  |  |  |                     values=new_values[idx], | 
					
						
							|  |  |  |                     columns=[{"Name": "country", "Type": "string"}], | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.batch_update_partition( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         DatabaseName=database_name, TableName=table_name, Entries=batch_update_values | 
					
						
							| 
									
										
										
										
											2020-12-10 14:03:37 -06:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for value in values: | 
					
						
							|  |  |  |         with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |             helpers.get_partition(client, database_name, table_name, value) | 
					
						
							|  |  |  |         exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for value in new_values: | 
					
						
							|  |  |  |         response = client.get_partition( | 
					
						
							|  |  |  |             DatabaseName=database_name, TableName=table_name, PartitionValues=value | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         partition = response["Partition"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         partition["TableName"].should.equal(table_name) | 
					
						
							|  |  |  |         partition["StorageDescriptor"]["Columns"].should.equal( | 
					
						
							|  |  |  |             [{"Name": "country", "Type": "string"}] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_update_partition_missing_partition(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     values = [ | 
					
						
							|  |  |  |         ["2020-12-05"], | 
					
						
							|  |  |  |         ["2020-12-06"], | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_values = [ | 
					
						
							|  |  |  |         ["2020-11-05"], | 
					
						
							|  |  |  |         ["2020-11-06"], | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     batch_update_values = [] | 
					
						
							|  |  |  |     for idx, value in enumerate(values): | 
					
						
							|  |  |  |         helpers.create_partition(client, database_name, table_name, values=value) | 
					
						
							|  |  |  |         batch_update_values.append( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "PartitionValueList": value, | 
					
						
							|  |  |  |                 "PartitionInput": helpers.create_partition_input( | 
					
						
							|  |  |  |                     database_name, | 
					
						
							|  |  |  |                     table_name, | 
					
						
							|  |  |  |                     values=new_values[idx], | 
					
						
							|  |  |  |                     columns=[{"Name": "country", "Type": "string"}], | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # add a non-existent partition to the batch update values | 
					
						
							|  |  |  |     batch_update_values.append( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "PartitionValueList": ["2020-10-10"], | 
					
						
							|  |  |  |             "PartitionInput": helpers.create_partition_input( | 
					
						
							|  |  |  |                 database_name, | 
					
						
							|  |  |  |                 table_name, | 
					
						
							|  |  |  |                 values=["2019-09-09"], | 
					
						
							|  |  |  |                 columns=[{"Name": "country", "Type": "string"}], | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.batch_update_partition( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         DatabaseName=database_name, TableName=table_name, Entries=batch_update_values | 
					
						
							| 
									
										
										
										
											2020-12-10 14:03:37 -06:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.should.have.key("Errors") | 
					
						
							|  |  |  |     response["Errors"].should.have.length_of(1) | 
					
						
							|  |  |  |     response["Errors"][0]["PartitionValueList"].should.equal(["2020-10-10"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     part_input = helpers.create_partition_input( | 
					
						
							|  |  |  |         database_name, table_name, values=values | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     helpers.create_partition(client, database_name, table_name, part_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.delete_partition( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         DatabaseName=database_name, TableName=table_name, PartitionValues=values | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_partitions(DatabaseName=database_name, TableName=table_name) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     partitions = response["Partitions"] | 
					
						
							| 
									
										
										
										
											2022-04-18 20:44:56 +00:00
										 |  |  |     partitions.should.equal([]) | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_partition_bad_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							|  |  |  |     values = ["2018-10-01"] | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |         client.delete_partition( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             DatabaseName=database_name, TableName=table_name, PartitionValues=values | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_delete_partition(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partition_inputs = [] | 
					
						
							|  |  |  |     for i in range(0, 20): | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         values = [f"2018-10-{i:2}"] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         part_input = helpers.create_partition_input( | 
					
						
							|  |  |  |             database_name, table_name, values=values | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |         partition_inputs.append(part_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.batch_create_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         PartitionInputList=partition_inputs, | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partition_values = [{"Values": p["Values"]} for p in partition_inputs] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.batch_delete_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							|  |  |  |         PartitionsToDelete=partition_values, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response.should_not.have.key("Errors") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_batch_delete_partition_with_bad_partitions(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     database_name = "myspecialdatabase" | 
					
						
							|  |  |  |     table_name = "myfirsttable" | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     helpers.create_database(client, database_name) | 
					
						
							|  |  |  |     helpers.create_table(client, database_name, table_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partition_inputs = [] | 
					
						
							|  |  |  |     for i in range(0, 20): | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         values = [f"2018-10-{i:2}"] | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         part_input = helpers.create_partition_input( | 
					
						
							|  |  |  |             database_name, table_name, values=values | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |         partition_inputs.append(part_input) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.batch_create_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         PartitionInputList=partition_inputs, | 
					
						
							| 
									
										
										
										
											2019-06-11 14:14:28 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partition_values = [{"Values": p["Values"]} for p in partition_inputs] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     partition_values.insert(5, {"Values": ["2018-11-01"]}) | 
					
						
							|  |  |  |     partition_values.insert(10, {"Values": ["2018-11-02"]}) | 
					
						
							|  |  |  |     partition_values.insert(15, {"Values": ["2018-11-03"]}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.batch_delete_partition( | 
					
						
							|  |  |  |         DatabaseName=database_name, | 
					
						
							|  |  |  |         TableName=table_name, | 
					
						
							|  |  |  |         PartitionsToDelete=partition_values, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     response.should.have.key("Errors") | 
					
						
							|  |  |  |     response["Errors"].should.have.length_of(3) | 
					
						
							|  |  |  |     error_partitions = map(lambda x: x["PartitionValues"], response["Errors"]) | 
					
						
							|  |  |  |     ["2018-11-01"].should.be.within(error_partitions) | 
					
						
							|  |  |  |     ["2018-11-02"].should.be.within(error_partitions) | 
					
						
							|  |  |  |     ["2018-11-03"].should.be.within(error_partitions) | 
					
						
							| 
									
										
										
										
											2021-08-26 10:49:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | @freeze_time(FROZEN_CREATE_TIME) | 
					
						
							|  |  |  | def test_create_crawler_scheduled(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     role = "arn:aws:iam::123456789012:role/Glue/Role" | 
					
						
							|  |  |  |     database_name = "my_database_name" | 
					
						
							|  |  |  |     description = "my crawler description" | 
					
						
							|  |  |  |     targets = { | 
					
						
							|  |  |  |         "S3Targets": [{"Path": "s3://my-source-bucket/"}], | 
					
						
							|  |  |  |         "JdbcTargets": [], | 
					
						
							|  |  |  |         "MongoDBTargets": [], | 
					
						
							|  |  |  |         "DynamoDBTargets": [], | 
					
						
							|  |  |  |         "CatalogTargets": [], | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     schedule = "cron(15 12 * * ? *)" | 
					
						
							|  |  |  |     classifiers = [] | 
					
						
							|  |  |  |     table_prefix = "my_table_prefix_" | 
					
						
							|  |  |  |     schema_change_policy = { | 
					
						
							|  |  |  |         "UpdateBehavior": "LOG", | 
					
						
							|  |  |  |         "DeleteBehavior": "LOG", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     recrawl_policy = {"RecrawlBehavior": "CRAWL_NEW_FOLDERS_ONLY"} | 
					
						
							|  |  |  |     lineage_configuration = {"CrawlerLineageSettings": "DISABLE"} | 
					
						
							|  |  |  |     configuration = json.dumps( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "Version": 1.0, | 
					
						
							|  |  |  |             "CrawlerOutput": { | 
					
						
							|  |  |  |                 "Partitions": {"AddOrUpdateBehavior": "InheritFromTable"}, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             "Grouping": {"TableGroupingPolicy": "CombineCompatibleSchemas"}, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     crawler_security_configuration = "my_security_configuration" | 
					
						
							|  |  |  |     tags = {"tag_key": "tag_value"} | 
					
						
							|  |  |  |     helpers.create_crawler( | 
					
						
							|  |  |  |         client, | 
					
						
							|  |  |  |         name, | 
					
						
							|  |  |  |         role, | 
					
						
							|  |  |  |         targets, | 
					
						
							|  |  |  |         database_name=database_name, | 
					
						
							|  |  |  |         description=description, | 
					
						
							|  |  |  |         schedule=schedule, | 
					
						
							|  |  |  |         classifiers=classifiers, | 
					
						
							|  |  |  |         table_prefix=table_prefix, | 
					
						
							|  |  |  |         schema_change_policy=schema_change_policy, | 
					
						
							|  |  |  |         recrawl_policy=recrawl_policy, | 
					
						
							|  |  |  |         lineage_configuration=lineage_configuration, | 
					
						
							|  |  |  |         configuration=configuration, | 
					
						
							|  |  |  |         crawler_security_configuration=crawler_security_configuration, | 
					
						
							|  |  |  |         tags=tags, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_crawler(Name=name) | 
					
						
							|  |  |  |     crawler = response["Crawler"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crawler.get("Name").should.equal(name) | 
					
						
							|  |  |  |     crawler.get("Role").should.equal(role) | 
					
						
							|  |  |  |     crawler.get("DatabaseName").should.equal(database_name) | 
					
						
							|  |  |  |     crawler.get("Description").should.equal(description) | 
					
						
							|  |  |  |     crawler.get("Targets").should.equal(targets) | 
					
						
							|  |  |  |     crawler.get("Schedule").should.equal( | 
					
						
							|  |  |  |         {"ScheduleExpression": schedule, "State": "SCHEDULED"} | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     crawler.get("Classifiers").should.equal(classifiers) | 
					
						
							|  |  |  |     crawler.get("TablePrefix").should.equal(table_prefix) | 
					
						
							|  |  |  |     crawler.get("SchemaChangePolicy").should.equal(schema_change_policy) | 
					
						
							|  |  |  |     crawler.get("RecrawlPolicy").should.equal(recrawl_policy) | 
					
						
							|  |  |  |     crawler.get("LineageConfiguration").should.equal(lineage_configuration) | 
					
						
							|  |  |  |     crawler.get("Configuration").should.equal(configuration) | 
					
						
							|  |  |  |     crawler.get("CrawlerSecurityConfiguration").should.equal( | 
					
						
							|  |  |  |         crawler_security_configuration | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crawler.get("State").should.equal("READY") | 
					
						
							|  |  |  |     crawler.get("CrawlElapsedTime").should.equal(0) | 
					
						
							|  |  |  |     crawler.get("Version").should.equal(1) | 
					
						
							|  |  |  |     if not settings.TEST_SERVER_MODE: | 
					
						
							| 
									
										
										
										
											2023-02-09 15:42:16 +02:00
										 |  |  |         crawler.get("CreationTime").timestamp().should.equal( | 
					
						
							|  |  |  |             FROZEN_CREATE_TIME.timestamp() | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         crawler.get("LastUpdated").timestamp().should.equal( | 
					
						
							|  |  |  |             FROZEN_CREATE_TIME.timestamp() | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-08-26 10:49:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     crawler.should.not_have.key("LastCrawl") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | @freeze_time(FROZEN_CREATE_TIME) | 
					
						
							|  |  |  | def test_create_crawler_unscheduled(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     role = "arn:aws:iam::123456789012:role/Glue/Role" | 
					
						
							|  |  |  |     database_name = "my_database_name" | 
					
						
							|  |  |  |     description = "my crawler description" | 
					
						
							|  |  |  |     targets = { | 
					
						
							|  |  |  |         "S3Targets": [{"Path": "s3://my-source-bucket/"}], | 
					
						
							|  |  |  |         "JdbcTargets": [], | 
					
						
							|  |  |  |         "MongoDBTargets": [], | 
					
						
							|  |  |  |         "DynamoDBTargets": [], | 
					
						
							|  |  |  |         "CatalogTargets": [], | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     classifiers = [] | 
					
						
							|  |  |  |     table_prefix = "my_table_prefix_" | 
					
						
							|  |  |  |     schema_change_policy = { | 
					
						
							|  |  |  |         "UpdateBehavior": "LOG", | 
					
						
							|  |  |  |         "DeleteBehavior": "LOG", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     recrawl_policy = {"RecrawlBehavior": "CRAWL_NEW_FOLDERS_ONLY"} | 
					
						
							|  |  |  |     lineage_configuration = {"CrawlerLineageSettings": "DISABLE"} | 
					
						
							|  |  |  |     configuration = json.dumps( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "Version": 1.0, | 
					
						
							|  |  |  |             "CrawlerOutput": { | 
					
						
							|  |  |  |                 "Partitions": {"AddOrUpdateBehavior": "InheritFromTable"}, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             "Grouping": {"TableGroupingPolicy": "CombineCompatibleSchemas"}, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     crawler_security_configuration = "my_security_configuration" | 
					
						
							|  |  |  |     tags = {"tag_key": "tag_value"} | 
					
						
							|  |  |  |     helpers.create_crawler( | 
					
						
							|  |  |  |         client, | 
					
						
							|  |  |  |         name, | 
					
						
							|  |  |  |         role, | 
					
						
							|  |  |  |         targets, | 
					
						
							|  |  |  |         database_name=database_name, | 
					
						
							|  |  |  |         description=description, | 
					
						
							|  |  |  |         classifiers=classifiers, | 
					
						
							|  |  |  |         table_prefix=table_prefix, | 
					
						
							|  |  |  |         schema_change_policy=schema_change_policy, | 
					
						
							|  |  |  |         recrawl_policy=recrawl_policy, | 
					
						
							|  |  |  |         lineage_configuration=lineage_configuration, | 
					
						
							|  |  |  |         configuration=configuration, | 
					
						
							|  |  |  |         crawler_security_configuration=crawler_security_configuration, | 
					
						
							|  |  |  |         tags=tags, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_crawler(Name=name) | 
					
						
							|  |  |  |     crawler = response["Crawler"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crawler.get("Name").should.equal(name) | 
					
						
							|  |  |  |     crawler.get("Role").should.equal(role) | 
					
						
							|  |  |  |     crawler.get("DatabaseName").should.equal(database_name) | 
					
						
							|  |  |  |     crawler.get("Description").should.equal(description) | 
					
						
							|  |  |  |     crawler.get("Targets").should.equal(targets) | 
					
						
							|  |  |  |     crawler.should.not_have.key("Schedule") | 
					
						
							|  |  |  |     crawler.get("Classifiers").should.equal(classifiers) | 
					
						
							|  |  |  |     crawler.get("TablePrefix").should.equal(table_prefix) | 
					
						
							|  |  |  |     crawler.get("SchemaChangePolicy").should.equal(schema_change_policy) | 
					
						
							|  |  |  |     crawler.get("RecrawlPolicy").should.equal(recrawl_policy) | 
					
						
							|  |  |  |     crawler.get("LineageConfiguration").should.equal(lineage_configuration) | 
					
						
							|  |  |  |     crawler.get("Configuration").should.equal(configuration) | 
					
						
							|  |  |  |     crawler.get("CrawlerSecurityConfiguration").should.equal( | 
					
						
							|  |  |  |         crawler_security_configuration | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crawler.get("State").should.equal("READY") | 
					
						
							|  |  |  |     crawler.get("CrawlElapsedTime").should.equal(0) | 
					
						
							|  |  |  |     crawler.get("Version").should.equal(1) | 
					
						
							|  |  |  |     if not settings.TEST_SERVER_MODE: | 
					
						
							| 
									
										
										
										
											2023-02-09 15:42:16 +02:00
										 |  |  |         crawler.get("CreationTime").timestamp().should.equal( | 
					
						
							|  |  |  |             FROZEN_CREATE_TIME.timestamp() | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         crawler.get("LastUpdated").timestamp().should.equal( | 
					
						
							|  |  |  |             FROZEN_CREATE_TIME.timestamp() | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-08-26 10:49:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     crawler.should.not_have.key("LastCrawl") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_create_crawler_already_exists(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     helpers.create_crawler(client, name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         helpers.create_crawler(client, name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     exc.value.response["Error"]["Code"].should.equal("AlreadyExistsException") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_crawler_not_exits(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.get_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match( | 
					
						
							|  |  |  |         "Crawler my_crawler_name not found" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_crawlers_empty(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     response = client.get_crawlers() | 
					
						
							|  |  |  |     response["Crawlers"].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_get_crawlers_several_items(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name_1, name_2 = "my_crawler_name_1", "my_crawler_name_2" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     helpers.create_crawler(client, name_1) | 
					
						
							|  |  |  |     helpers.create_crawler(client, name_2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crawlers = sorted(client.get_crawlers()["Crawlers"], key=lambda x: x["Name"]) | 
					
						
							|  |  |  |     crawlers.should.have.length_of(2) | 
					
						
							|  |  |  |     crawlers[0].get("Name").should.equal(name_1) | 
					
						
							|  |  |  |     crawlers[1].get("Name").should.equal(name_2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-29 02:50:08 +05:30
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_start_crawler(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     helpers.create_crawler(client, name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.start_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_crawler(Name=name) | 
					
						
							|  |  |  |     crawler = response["Crawler"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crawler.get("State").should.equal("RUNNING") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_start_crawler_should_raise_exception_if_already_running(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     helpers.create_crawler(client, name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.start_crawler(Name=name) | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.start_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     exc.value.response["Error"]["Code"].should.equal("CrawlerRunningException") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_stop_crawler(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     helpers.create_crawler(client, name) | 
					
						
							|  |  |  |     client.start_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.stop_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.get_crawler(Name=name) | 
					
						
							|  |  |  |     crawler = response["Crawler"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     crawler.get("State").should.equal("STOPPING") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_stop_crawler_should_raise_exception_if_not_running(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     helpers.create_crawler(client, name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.stop_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     exc.value.response["Error"]["Code"].should.equal("CrawlerNotRunningException") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 10:49:41 +01:00
										 |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_crawler(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  |     helpers.create_crawler(client, name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     result = client.delete_crawler(Name=name) | 
					
						
							|  |  |  |     result["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # confirm crawler is deleted | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.get_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match( | 
					
						
							|  |  |  |         "Crawler my_crawler_name not found" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_glue | 
					
						
							|  |  |  | def test_delete_crawler_not_exists(): | 
					
						
							|  |  |  |     client = boto3.client("glue", region_name="us-east-1") | 
					
						
							|  |  |  |     name = "my_crawler_name" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.delete_crawler(Name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException") | 
					
						
							|  |  |  |     exc.value.response["Error"]["Message"].should.match( | 
					
						
							|  |  |  |         "Crawler my_crawler_name not found" | 
					
						
							|  |  |  |     ) |