|
127 | 127 | } |
128 | 128 |
|
129 | 129 |
|
| 130 | +@pytest.fixture |
| 131 | +def s3_client(mocker): |
| 132 | + client = boto3.client("s3", config=Config(signature_version=UNSIGNED)) |
| 133 | + mocker.patch("t4_lambda_es_indexer.index.make_s3_client", return_value=client) |
| 134 | + return client |
| 135 | + |
| 136 | + |
130 | 137 | def _check_event(synthetic, organic): |
131 | 138 | # Ensure that synthetic events have the same shape as actual organic ones, |
132 | 139 | # and that overridden properties like bucket, key, eTag are properly set |
@@ -913,64 +920,10 @@ def test_index_if_pointer_not_exists(self, append_mock, es_mock): |
913 | 920 | ) |
914 | 921 | append_mock.assert_not_called() |
915 | 922 |
|
916 | | - @patch.object(index, "es") |
917 | | - @patch.object(index.DocumentQueue, 'append_document') |
918 | | - def test_index_if_pointer(self, append_mock, es_mock): |
919 | | - bucket = "quilt-example" |
920 | | - handle = "author/semantic" |
921 | | - pointer_file = "1610412903" |
922 | | - key = f"{NAMED_PACKAGES_PREFIX}{handle}/{pointer_file}" |
923 | | - pkg_hash = "a" * 64 |
924 | | - last_modified = datetime.datetime(2021, 1, 1, 0, 0, tzinfo=tzutc()) |
925 | | - |
926 | | - self.s3_stubber.add_response( |
927 | | - method="get_object", |
928 | | - expected_params={ |
929 | | - "Bucket": bucket, |
930 | | - "Key": key, |
931 | | - }, |
932 | | - service_response={ |
933 | | - "Body": BytesIO(pkg_hash.encode()), |
934 | | - "LastModified": last_modified, |
935 | | - }, |
936 | | - ) |
937 | | - |
938 | | - index.index_if_pointer( |
939 | | - self.s3_client, |
940 | | - index.DocumentQueue(None), |
941 | | - bucket=bucket, |
942 | | - key=key, |
943 | | - ) |
944 | | - |
945 | | - es_mock.delete_by_query.assert_called_once_with( |
946 | | - index=bucket + PACKAGE_INDEX_SUFFIX, |
947 | | - body={ |
948 | | - "query": { |
949 | | - "bool": { |
950 | | - "filter": [{"term": {"_id": get_ptr_doc_id("author/semantic", "1610412903")}}], |
951 | | - "must_not": [{"term": {"join_field#mnfst": get_manifest_doc_id("a" * 64)}}], |
952 | | - } |
953 | | - } |
954 | | - }, |
955 | | - ) |
956 | | - append_mock.assert_called_once_with({ |
957 | | - "_index": bucket + PACKAGE_INDEX_SUFFIX, |
958 | | - "_op_type": "index", |
959 | | - "_id": get_ptr_doc_id(handle, pointer_file), |
960 | | - "join_field": { |
961 | | - "name": "ptr", |
962 | | - "parent": get_manifest_doc_id(pkg_hash), |
963 | | - }, |
964 | | - "routing": get_manifest_doc_id(pkg_hash), |
965 | | - "ptr_name": handle, |
966 | | - "ptr_tag": pointer_file, |
967 | | - "ptr_last_modified": last_modified, |
968 | | - }) |
969 | | - |
970 | 923 | def test_index_if_pointer_skip(self): |
971 | 924 | """test cases where index_if_pointer ignores input for different reasons""" |
972 | 925 | # none of these should index due to out-of-range timestamp or non-integer name |
973 | | - for file_name in [1451631500, 1767250801]: |
| 926 | + for file_name in [1451631500]: |
974 | 927 | key = f".quilt/named_packages/foo/bar/{file_name}" |
975 | 928 | assert not index.index_if_pointer( |
976 | 929 | self.s3_client, |
@@ -1695,6 +1648,70 @@ def test_get_object_tagging_no_such_key(self): |
1695 | 1648 | ) |
1696 | 1649 |
|
1697 | 1650 |
|
| 1651 | +@pytest.mark.parametrize( |
| 1652 | + "pointer_file", |
| 1653 | + [ |
| 1654 | + "1610412903", |
| 1655 | + "9999999999", |
| 1656 | + ], |
| 1657 | +) |
| 1658 | +@patch("t4_lambda_es_indexer.index.es") |
| 1659 | +@patch("t4_lambda_es_indexer.document_queue.DocumentQueue.append_document") |
| 1660 | +def test_index_if_pointer(append_mock, es_mock, s3_client, pointer_file): |
| 1661 | + bucket = "quilt-example" |
| 1662 | + handle = "author/semantic" |
| 1663 | + key = f"{NAMED_PACKAGES_PREFIX}{handle}/{pointer_file}" |
| 1664 | + pkg_hash = "a" * 64 |
| 1665 | + last_modified = datetime.datetime(2021, 1, 1, 0, 0, tzinfo=tzutc()) |
| 1666 | + |
| 1667 | + with Stubber(s3_client) as s3_stubber: |
| 1668 | + s3_stubber.add_response( |
| 1669 | + method="get_object", |
| 1670 | + expected_params={ |
| 1671 | + "Bucket": bucket, |
| 1672 | + "Key": key, |
| 1673 | + }, |
| 1674 | + service_response={ |
| 1675 | + "Body": BytesIO(pkg_hash.encode()), |
| 1676 | + "LastModified": last_modified, |
| 1677 | + }, |
| 1678 | + ) |
| 1679 | + |
| 1680 | + index.index_if_pointer( |
| 1681 | + s3_client, |
| 1682 | + index.DocumentQueue(None), |
| 1683 | + bucket=bucket, |
| 1684 | + key=key, |
| 1685 | + ) |
| 1686 | + |
| 1687 | + es_mock.delete_by_query.assert_called_once_with( |
| 1688 | + index=bucket + PACKAGE_INDEX_SUFFIX, |
| 1689 | + body={ |
| 1690 | + "query": { |
| 1691 | + "bool": { |
| 1692 | + "filter": [{"term": {"_id": get_ptr_doc_id("author/semantic", pointer_file)}}], |
| 1693 | + "must_not": [{"term": {"join_field#mnfst": get_manifest_doc_id("a" * 64)}}], |
| 1694 | + } |
| 1695 | + } |
| 1696 | + }, |
| 1697 | + ) |
| 1698 | + append_mock.assert_called_once_with({ |
| 1699 | + "_index": bucket + PACKAGE_INDEX_SUFFIX, |
| 1700 | + "_op_type": "index", |
| 1701 | + "_id": get_ptr_doc_id(handle, pointer_file), |
| 1702 | + "join_field": { |
| 1703 | + "name": "ptr", |
| 1704 | + "parent": get_manifest_doc_id(pkg_hash), |
| 1705 | + }, |
| 1706 | + "routing": get_manifest_doc_id(pkg_hash), |
| 1707 | + "ptr_name": handle, |
| 1708 | + "ptr_tag": pointer_file, |
| 1709 | + "ptr_last_modified": last_modified, |
| 1710 | + }) |
| 1711 | + |
| 1712 | + s3_stubber.assert_no_pending_responses() |
| 1713 | + |
| 1714 | + |
1698 | 1715 | def test_extract_pptx(): |
1699 | 1716 | lorem = "Lorem ipsum dolor sit amet, consectetur" |
1700 | 1717 |
|
|
0 commit comments