Skip to content

Commit

Permalink
Added get_contact_information
Browse files Browse the repository at this point in the history
  • Loading branch information
ereOn committed Feb 22, 2015
1 parent 12c6c5a commit 3e9b3f5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pyfreelan/server/application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,30 @@ def set_contact_information():
'accepted_endpoints': accepted_endpoints,
'rejected_endpoints': rejected_endpoints,
})


@APP.route('/get_contact_information/', methods={'POST'})
@log_activity
@login_required
def get_contact_information():
"""
get contact information.
Expects JSON data in the following format:
{
"requested_contacts": [
"YWxwaGE=",
"YmV0YQ==",
]
}
"""
contact_information = request.get_json()

contacts = g.http_server.callbacks['get_contact_information'](
contact_information.get('requested_contacts', []),
)

return jsonify({
'contacts': contacts,
})
34 changes: 34 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,37 @@ def set_contact_information(public_endpoints):
rejected_endpoints,
result['rejected_endpoints'],
)

def test_get_contact_information(self):
def get_contact_information(requested_contacts):
return {
hash: [
"127.0.0.1:12000",
"[::]:12000",
]
for hash in requested_contacts
}

contact_information = {
'requested_contacts': [
"YWxwaGE=",
"YmV0YQ==",
]
}

with self.with_credentials(True), \
self.register_callback(get_contact_information):
response = self.client.post(
'/get_contact_information/',
data=json.dumps(contact_information),
headers={'content-type': 'application/json'},
)

self.assertEqual(200, response.status_code)
self.assertEqual('application/json', response.content_type)

result = json.loads(response.data)
self.assertEqual(
set(contact_information['requested_contacts']),
set(result['contacts']),
)

0 comments on commit 3e9b3f5

Please sign in to comment.