From df852a32a5e39463f9a08eb33230654d7cc7e9f3 Mon Sep 17 00:00:00 2001 From: gtalarico Date: Sat, 14 Mar 2020 23:41:29 -0700 Subject: [PATCH] Removed mirror method - fixes #52 --- HISTORY.md | 4 + airtable/airtable.py | 32 ----- tests/test_airtable.py.old | 263 ------------------------------------- 3 files changed, 4 insertions(+), 295 deletions(-) delete mode 100644 tests/test_airtable.py.old diff --git a/HISTORY.md b/HISTORY.md index 6a6fc3ae..0d9b525e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# 0.14.0 +* Removed `mirror()` method. +* + # 0.13.0 * Fixed: Python 2 compatibility issues * Start CI testing on all supported Python versions diff --git a/airtable/airtable.py b/airtable/airtable.py index c627f82c..40dcc7bc 100644 --- a/airtable/airtable.py +++ b/airtable/airtable.py @@ -548,37 +548,5 @@ def batch_delete(self, record_ids): """ return self._batch_request(self.delete, record_ids) - def mirror(self, records, **options): - """ - Deletes all records on table or view and replaces with records. - - >>> records = [{'Name': 'John'}, {'Name': 'Marc'}] - - >>> record = airtable.,mirror(records) - - If view options are provided, only records visible on that view will - be deleted. - - >>> record = airtable.mirror(records, view='View') - ([{'id': 'recwPQIfs4wKPyc9D', ... }], [{'deleted': True, ... }]) - - Args: - records(``list``): Records to insert - - Keyword Args: - max_records (``int``, optional): The maximum total number of - records that will be returned. See :any:`MaxRecordsParam` - view (``str``, optional): The name or ID of a view. - See :any:`ViewParam`. - - Returns: - records (``tuple``): (new_records, deleted_records) - """ - - all_record_ids = [r["id"] for r in self.get_all(**options)] - deleted_records = self.batch_delete(all_record_ids) - new_records = self.batch_insert(records) - return (new_records, deleted_records) - def __repr__(self): return "".format(self.table_name) diff --git a/tests/test_airtable.py.old b/tests/test_airtable.py.old deleted file mode 100644 index af70ecb7..00000000 --- a/tests/test_airtable.py.old +++ /dev/null @@ -1,263 +0,0 @@ -from __future__ import absolute_import - -import pytest -import os -import requests -from requests_mock import Mocker -from posixpath import join as urljoin -from requests.exceptions import HTTPError - -from airtable.params import AirtableParams - -from .pytest_fixtures import mock_airtable, airtable, Airtable, build_url -from .pytest_fixtures import table_url, base_key, table_name, fake_api_key -from .pytest_fixtures import table_data, reset_table, clean_airtable - - - -@pytest.mark.usefixtures("clean_airtable") -class TestGet(): - - def test_get(self, airtable): - record = airtable.get('rec0LQoJ4Vgp8fPty') - assert isinstance(record, dict) - assert record['id'] == 'rec0LQoJ4Vgp8fPty' - - def test_get_iter(self, airtable): - for n, records in enumerate(airtable.get_iter(), 1): - assert isinstance(records, list) - assert len(records) == 100 or 4 - - def test_get_all(self, airtable): - records = airtable.get_all() - assert isinstance(records, list) - assert len(records) == 104 - - def test_get_all(self, airtable): - records = airtable.get_all(max_records=3) - assert isinstance(records, list) - assert len(records) == 3 - - def test_get_pagesize(self, airtable): - for records in airtable.get_iter(pageSize=50): - assert len(records) == 50 - break - - def test_get_all_view(self, airtable): - records = airtable.get_all(view='One') - assert len(records) == 1 - - def test_get_bad_param(self, airtable): - with pytest.raises(ValueError) as excinfo: - airtable.get_all(view='One', bad_param=True) - assert 'invalid param keyword' in str(excinfo.value).lower() - - def test_get_bad_request_decoded_msg(self, airtable): - with pytest.raises(HTTPError) as excinfo: - airtable.get_all(view='One', sort=['NON_EXISTING'], fields=['X']) - assert 'Unprocessable Entity for url(decoded)' in str(excinfo.value).lower() - assert 'sort[0]' in str(excinfo.value).lower() - assert 'fields[]=' in str(excinfo.value).lower() - - def test_get_all_fields_single(self, airtable): - records = airtable.get_all(view='ViewAll', maxRecords=1, - fields=['COLUMN_STR']) - assert 'COLUMN_STR' in records[0]['fields'] - assert 'COLUMN_INT' not in records[0]['fields'] - - def test_get_all_fields_multiple(self, airtable): - records = airtable.get_all(view='ViewAll', maxRecords=1, - fields=['COLUMN_INT', 'COLUMN_STR']) - assert 'COLUMN_STR' in records[0]['fields'] - assert 'COLUMN_INT' in records[0]['fields'] - - def test_get_all_maxrecords(self, airtable): - records = airtable.get_all(maxRecords=50) - assert len(records) == 50 - - def test_get_all_max_records(self, airtable): - records = airtable.get_all(max_records=50) - assert len(records) == 50 - - def test_get_all_sort_asc(self, airtable): - records = airtable.get_all(maxRecords=5, sort=['COLUMN_INT']) - assert records[0]['fields']['COLUMN_INT'] == 1 - assert records[2]['fields']['COLUMN_INT'] == 3 - - def test_get_all_sort_asc_str(self, airtable): - records = airtable.get_all(maxRecords=5, sort='COLUMN_INT') - assert records[0]['fields']['COLUMN_INT'] == 1 - assert records[2]['fields']['COLUMN_INT'] == 3 - - def test_get_all_sort_desc(self, airtable): - records = airtable.get_all(maxRecords=5, sort=['-COLUMN_INT']) - assert records[0]['fields']['COLUMN_INT'] == 104 - assert records[1]['fields']['COLUMN_INT'] == 104 - assert records[2]['fields']['COLUMN_INT'] == 103 - - def test_get_all_sort_desc_explicit(self, airtable): - records = airtable.get_all(maxRecords=5, sort=[('COLUMN_INT', 'asc')]) - assert records[0]['fields']['COLUMN_INT'] == 1 - assert records[2]['fields']['COLUMN_INT'] == 3 - - def test_get_all_sort_desc_explicit(self, airtable): - records = airtable.get_all(maxRecords=5, sort=[('COLUMN_INT', 'desc')]) - assert records[0]['fields']['COLUMN_INT'] == 104 - assert records[1]['fields']['COLUMN_INT'] == 104 - assert records[2]['fields']['COLUMN_INT'] == 103 - - def test_get_all_filter(self, airtable): - records = airtable.get_all(filterByFormula="COLUMN_INT=5") - assert len(records) == 1 - assert records[0]['fields']['COLUMN_INT'] == 5 - - def test_match(self, airtable): - record = airtable.match('COLUMN_INT', 5, view='ViewAll') - assert isinstance(record, dict) - assert record['fields'].get('COLUMN_INT') == 5 - - def test_match_not(self, airtable): - record = airtable.match('COLUMN_STR', 'FAKE VALUE', view='ViewAll') - assert isinstance(record, dict) - assert len(record) == 0 - - def test_search(self, airtable): - records = airtable.search('COLUMN_INT', 104, view='ViewAll') - assert isinstance(records, list) - assert len(records) == 2 - assert records[0]['fields'].get('COLUMN_INT') == 104 - assert records[1]['fields'].get('COLUMN_INT') == 104 - - def test_search_not(self, airtable): - records = airtable.search('COLUMN_INT', 999, view='ViewAll') - assert isinstance(records, list) - assert len(records) == 0 - - - - -@pytest.mark.usefixtures("clean_airtable") -class TestCreate(): - - def test_create_one(self, airtable): - record = {'COLUMN_INT': 999} - response = airtable.insert(record) - assert 'id' in response - assert response['fields']['COLUMN_INT'] == 999 - - def test_create_one_typecast(self, airtable): - record = {'COLUMN_INT': '50'} - response = airtable.insert(record, typecast=True) - assert 'id' in response - assert response['fields']['COLUMN_INT'] == 50 - - def test_create_batch(self, airtable): - rows = [{'COLUMN_INT': i} for i in range(200, 203)] - responses = airtable.batch_insert(rows) - assert len(responses) == 3 - for response in responses: - assert 'id' in response - assert response['fields']['COLUMN_INT'] in range(200, 203) - - def test_create_type_mismatch(self, airtable): - """ Verify Exception and Exception Message on Type Mismatch """ - record = {'COLUMN_INT': 'aaa'} - with pytest.raises(requests.exceptions.HTTPError) as exc: - response = airtable.insert(record) - assert 'INVALID_VALUE_FOR_COLUMN' in str(exc) - assert 'Field COLUMN_INT can not accept value aaa' in str(exc) - - -@pytest.mark.usefixtures("clean_airtable") -class TestUpdate(): - - @pytest.fixture - def old_field(self): - return {'COLUMN_INT': 1} - - @pytest.fixture - def new_field(self): - return {'COLUMN_INT': 500} - - def test_update(self, airtable, new_field, old_field): - record = airtable.match('COLUMN_INT', 104) - assert record['fields']['COLUMN_INT'] == 104 - - new_record = airtable.update(record['id'], new_field) - record = airtable.get(new_record['id']) - assert record['fields']['COLUMN_INT'] == 500 - assert 'COLUMN_STR' in record['fields'] - - def test_update_by_field(self, airtable, new_field, old_field): - new_record = airtable.update_by_field('COLUMN_INT', 104, - new_field, sort='COLUMN_INT') - record = airtable.get(new_record['id']) - assert record['fields']['COLUMN_INT'] == 500 - -@pytest.mark.usefixtures("clean_airtable") -class TestReplace(): - - @pytest.fixture - def old_field(self): - return {'COLUMN_INT': 1} - - @pytest.fixture - def new_field(self): - return {'COLUMN_INT': 500} - - def test_replace(self, airtable, new_field, old_field): - record = airtable.match('COLUMN_INT', 104) - assert record['fields']['COLUMN_INT'] == 104 - - new_record = airtable.replace(record['id'], new_field) - record = airtable.get(new_record['id']) - assert record['fields']['COLUMN_INT'] == 500 - assert 'COLUMN_STR' not in record['fields'] - - def test_replace_by_field(self, airtable, new_field, old_field): - new_record = airtable.replace_by_field('COLUMN_INT', 103, - new_field, sort='COLUMN_INT') - record = airtable.get(new_record['id']) - assert record['fields']['COLUMN_INT'] == 500 - assert 'COLUMN_STR' not in record['fields'] - - -@pytest.mark.usefixtures("clean_airtable") -class TestDelete(): - - def test_delete(self, airtable): - record = airtable.match('COLUMN_INT', 100) - assert record['fields']['COLUMN_INT'] == 100 - - record = airtable.delete(record['id']) - assert record.get('deleted') is True - assert 'id' in record - - assert len(airtable.match('COLUMN_INT', 100)) == 0 - - - def test_batch_delete(self, airtable): - record = airtable.match('COLUMN_INT', 104) - assert record['fields']['COLUMN_INT'] == 104 - record2 = airtable.match('COLUMN_INT', 103) - assert record2['fields']['COLUMN_INT'] == 103 - - records = airtable.batch_delete([record['id'], record2['id']]) - assert records[0].get('deleted') is True - assert records[1].get('deleted') is True - - def test_delete_by_field(self, airtable): - record = airtable.match('COLUMN_INT', 102) - assert record['fields']['COLUMN_INT'] == 102 - - record = airtable.delete_by_field('COLUMN_INT', 102) - assert record.get('deleted') is True - -@pytest.mark.usefixtures("clean_airtable") -class TestAirtableMirror(): - - def test_mirror(self, airtable): - records = [{'COLUMN_INT': 100}, {'COLUMN_INT': 100}, {'COLUMN_INT': 100}] - airtable.mirror(records, view='One') - new_records = airtable.get_all(view='One') - assert len(new_records) == 3