Skip to content

Commit

Permalink
add ngpvn bulk apply suppressions (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
codygordon authored May 22, 2023
1 parent 88fda5c commit 853b27c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
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

0 comments on commit 853b27c

Please sign in to comment.