-
Notifications
You must be signed in to change notification settings - Fork 200
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
Alexander rubin dm code challenge #49
Open
LXwaru
wants to merge
3
commits into
datamade:master
Choose a base branch
from
LXwaru:alexander-rubin-dm-code-challenge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,45 @@ | ||
/* TODO: Flesh this out to connect the form to the API and render results | ||
in the #address-results div. */ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
document.querySelector('form').addEventListener('submit', function(event) { | ||
event.preventDefault(); | ||
|
||
var address = document.querySelector('#address').value; | ||
|
||
fetch('/api/parse?address=' + encodeURIComponent(address), { | ||
headers: { | ||
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value | ||
} | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
var resultsDiv = document.getElementById('address-results'); | ||
var resultsTableBody = resultsDiv.querySelector('tbody'); | ||
var parseType = document.getElementById('parse-type'); | ||
|
||
resultsTableBody.innerHTML = ''; // Clear previous results | ||
|
||
if (data.error) { | ||
resultsDiv.style.display = 'block'; | ||
parseType.innerText = 'Error'; | ||
resultsTableBody.innerHTML = '<tr><td colspan="2">' + data.error + '</td></tr>'; | ||
} else { | ||
resultsDiv.style.display = 'block'; | ||
parseType.innerText = data.address_type; | ||
|
||
var components = data.address_components; | ||
for (var part in components) { | ||
var row = document.createElement('tr'); | ||
var partCell = document.createElement('td'); | ||
var tagCell = document.createElement('td'); | ||
partCell.innerText = part; | ||
tagCell.innerText = components[part]; | ||
row.appendChild(partCell); | ||
row.appendChild(tagCell); | ||
resultsTableBody.appendChild(row); | ||
} | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
# Define test fixtures here. | ||
import os | ||
import sys | ||
import django | ||
|
||
# Add the parent directory to the sys.path | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
||
def pytest_configure(): | ||
os.environ['DJANGO_SETTINGS_MODULE'] = 'parserator_web.settings' | ||
django.setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import pytest | ||
from rest_framework.test import APIClient | ||
|
||
@pytest.fixture | ||
def client(): | ||
return APIClient() | ||
|
||
def test_api_parse_succeeds(client): | ||
# TODO: Finish this test. Send a request to the API and confirm that the | ||
# data comes back in the appropriate format. | ||
# Send a request to the API with a valid address | ||
address_string = '123 main st chicago il' | ||
pytest.fail() | ||
response = client.get('/api/parse/', {'address': address_string}) | ||
|
||
# Check if the response status code is 200 OK | ||
assert response.status_code == 200 | ||
|
||
# Check if the response contains the expected data | ||
data = response.json() | ||
assert 'input_string' in data | ||
assert data['input_string'] == address_string | ||
assert 'address_components' in data | ||
assert 'address_type' in data | ||
|
||
# Check some known components (example, update as needed) | ||
assert 'AddressNumber' in data['address_components'] | ||
assert data['address_components']['AddressNumber'] == '123' | ||
assert 'PlaceName' in data['address_components'] | ||
assert data['address_components']['PlaceName'] == 'chicago' | ||
assert 'StateName' in data['address_components'] | ||
assert data['address_components']['StateName'] == 'il' | ||
|
||
def test_api_parse_raises_error(client): | ||
# TODO: Finish this test. The address_string below will raise a | ||
# RepeatedLabelError, so ParseAddress.parse() will not be able to parse it. | ||
# Send a request to the API with an invalid address | ||
address_string = '123 main st chicago il 123 main st' | ||
pytest.fail() | ||
response = client.get('/api/parse/', {'address': address_string}) | ||
|
||
# Check if the response status code is 400 Bad Request | ||
assert response.status_code == 400 | ||
|
||
# Check if the response contains the error message | ||
data = response.json() | ||
assert 'detail' in data | ||
assert data['detail'] == 'Invalid address' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason docker build fails on this step and I couldn't figure out how to solve it. Commenting it out didn't break the app, so this is my Dockerfile solution for now.