Skip to content

Commit

Permalink
Added new dump for mock testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalarico committed Oct 9, 2017
1 parent cd4f02f commit 5428ad0
Show file tree
Hide file tree
Showing 72 changed files with 7,533 additions and 98 deletions.
13 changes: 5 additions & 8 deletions Airtable.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<Airtable table:TABLE READ>\n",
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
"<Airtable table:TABLE READ>\n"
]
}
],
Expand All @@ -35,7 +33,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -90,15 +88,14 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found!\n",
"[{'id': 'rec5eR7IzKSAOBHCz', 'fields': {'COLUMN_STR': 'DUPLICATE', 'COLUMN_ID': '3'}, 'createdTime': '2017-08-05T21:47:52.000Z'}]\n"
"[{'fields': {'COLUMN_ID': 3, 'COLUMN_STR': 'DUPLICATE'}, 'id': 'rec5eR7IzKSAOBHCz', 'createdTime': '2017-08-05T21:47:52.000Z'}]\n"
]
}
],
Expand Down
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 0.8.0
* Docs: New Documentation on Parameter filters Docs
* Docs: More documentation and examples.

* Feature: Search now uses filterByFormula
* Added Formula Generator

# 0.7.3
* Removed Unencoded Debug Msg due to IronPython Bug #242
Expand Down
42 changes: 34 additions & 8 deletions airtable/airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,29 @@ def record_url(self, record_id):

def _request(self, method, url, params=None, json_data=None):
response = self.session.request(method, url, params=params, json=json_data)
# self._dump_request_data(response)
return self._process_response(response)

# def _dump_request_data(self, response):
# """ For Debugging """
# timestamp = str(time.time()).split('.')[-1]
# url = response.request.url
# method = response.request.method
# response_json = response.json()
# status = response.status_code
# filepath = os.path.join('tests', 'dump', '{}-{}_{}.json'.format(
# method,
# status,
# timestamp))
# dump = {
# 'url': url,
# 'method': method,
# 'response_json': response_json,
# }
# with open(filepath, 'w') as fp:
# json.dump(dump, fp, indent=4)


def _get(self, url, **params):
processed_params = self._process_params(params)
return self._request('get', url, params=processed_params)
Expand Down Expand Up @@ -282,8 +303,7 @@ def match(self, field_name, field_value, **options):
Returns:
record (``dict``): First record to match the field_value provided
"""
formula = "{{{name}}}={value}".format(name=field_name,
value=field_value)
formula = self.formula_from_name_and_value(field_name, field_value)
options['formula'] = formula
for record in self.get_all(**options):
return record
Expand Down Expand Up @@ -316,13 +336,9 @@ def search(self, field_name, field_value, record=None, **options):
"""
records = []
formula = "{{{name}}}={value}".format(name=field_name,
value=field_value)
formula = self.formula_from_name_and_value(field_name, field_value)
options['formula'] = formula

for record in self.get_all(**options):
if record.get('fields', {}).get(field_name) == field_value:
records.append(record)
records = self.get_all(**options)
return records

def insert(self, fields):
Expand Down Expand Up @@ -551,5 +567,15 @@ def mirror(self, records, **options):
new_records = self.batch_insert(records)
return (new_records, deleted_records)

@staticmethod
def formula_from_name_and_value(field_name, field_value):
""" Creates a formula to match cells from from field_name and value """
if isinstance(field_value, str):
field_value = "'{}'".format(field_value)

formula = "{{{name}}}={value}".format(name=field_name,
value=field_value)
return formula

def __repr__(self):
return '<Airtable table:{}>'.format(self.table_name)
8 changes: 8 additions & 0 deletions tests/dump/DELETE-200_215193.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"url": "https://api.airtable.com/v0/appJMY16gZDQrMWpA/TABLE%20WRITE/reclIoucZv0XVI56B",
"method": "DELETE",
"response_json": {
"deleted": true,
"id": "reclIoucZv0XVI56B"
}
}
17 changes: 17 additions & 0 deletions tests/dump/GET-200_0081942.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"url": "https://api.airtable.com/v0/appJMY16gZDQrMWpA/TABLE%20READ?view=ViewAll&maxRecords=1",
"method": "GET",
"response_json": {
"records": [
{
"createdTime": "2017-03-14T22:04:31.000Z",
"fields": {
"COLUMN_ID": "1",
"COLUMN_STR": "UNIQUE",
"COLUMN_UPDATE": "A"
},
"id": "recwPQIfs4wKPyc9D"
}
]
}
}
15 changes: 15 additions & 0 deletions tests/dump/GET-200_0262082.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"url": "https://api.airtable.com/v0/appJMY16gZDQrMWpA/TABLE%20READ?fields%5B%5D=COLUMN_UPDATE&view=ViewAll&maxRecords=1",
"method": "GET",
"response_json": {
"records": [
{
"createdTime": "2017-03-14T22:04:31.000Z",
"fields": {
"COLUMN_UPDATE": "A"
},
"id": "recwPQIfs4wKPyc9D"
}
]
}
}
17 changes: 17 additions & 0 deletions tests/dump/GET-200_0466983.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"url": "https://api.airtable.com/v0/appJMY16gZDQrMWpA/TABLE%20READ?view=ViewAll&maxRecords=1",
"method": "GET",
"response_json": {
"records": [
{
"createdTime": "2017-03-14T22:04:31.000Z",
"fields": {
"COLUMN_ID": "1",
"COLUMN_STR": "UNIQUE",
"COLUMN_UPDATE": "B"
},
"id": "recwPQIfs4wKPyc9D"
}
]
}
}

0 comments on commit 5428ad0

Please sign in to comment.