Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NGPVAN bulk apply suppressions function #823

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion parsons/ngpvan/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class BulkImport(object):
def __init__(self):

pass

def get_bulk_import_resources(self):
Expand Down Expand Up @@ -339,6 +338,50 @@ def bulk_upsert_contacts(self, tbl, url_type, result_fields=None, **url_kwargs):
**url_kwargs,
)

def bulk_apply_suppressions(self, tbl, url_type, **url_kwargs):
"""
Bulk apply contact suppressions codes.

The table may include the following columns. The first column
must be ``vanid``.

.. list-table::
:widths: 25 25
:header-rows: 1

* - Column Name
- Required
- Description
* - ``vanid``
- Yes
- A valid VANID primary key
* - ``suppressionid``
- Yes
- A valid suppression id

`Args:`
table: Parsons table
A Parsons table.
url_type: str
The cloud file storage to use to post the file (``S3`` or ``GCS``).
See :ref:`Cloud Storage <cloud-storage>` for more details.
**url_kwargs: kwargs
Arguments to configure your cloud storage url type. See
:ref:`Cloud Storage <cloud-storage>` for more details.
`Returns:`
int
The bulk import job id
"""

return self.post_bulk_import(
tbl,
url_type,
"Contacts",
[{"name": "Suppressions"}],
"Apply Suppressions",
**url_kwargs,
)


# This is a column mapper that is used to accept additional column names and provide
# flexibility for the user.
Expand Down
17 changes: 17 additions & 0 deletions test/test_van/test_bulkimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ def test_bulk_apply_activist_codes(self, m):

self.assertEqual(job_id, 54679)

@requests_mock.Mocker()
def test_bulk_apply_suppressions(self, m):

# Mock Cloud Storage
cloud_storage.post_file = mock.MagicMock()
cloud_storage.post_file.return_value = "https://s3.com/my_file.zip"

tbl = Table([["Vanid", "suppressionid"], [1234, 18]])

m.post(self.van.connection.uri + "bulkImportJobs", json={"jobId": 54679})

job_id = self.van.bulk_apply_suppressions(
tbl, url_type="S3", bucket="my-bucket"
)

self.assertEqual(job_id, 54679)

@requests_mock.Mocker()
def test_bulk_upsert_contacts(self, m):

Expand Down