def test_api_users(self):
     """
     Test users listing.
     """
     resp = self.client.get('/api/v1/users')
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(resp.content_type, 'application/json')
     data = json.loads(resp.data)
     details = utils.get_details()
     self.assertEqual(len(data), len(details))
     self.assertDictEqual(data[0], {
         'user_id': 10,
         'name': 'Adam P.',
         'avatar': '/api/images/users/10'
     })
     self.assertDictEqual(data[1], {
         'user_id': 11,
         'name': 'Adrian K.',
         'avatar': '/api/images/users/11'
     })
     self.assertDictEqual(data[2], {
         'user_id': 12,
         'name': 'Agata J.',
         'avatar': '/api/images/users/12'
     })
def avatar_view(user_id=0):
    """
    Returns avatar path for given user.
    """
    details = get_details()
    if user_id in details:
        return details[user_id]['avatar']
    return None
 def test_get_details(self):
     details = utils.get_details()
     self.assertIsInstance(details, dict)
     self.assertIsInstance(details[10], dict)
     self.assertItemsEqual(details.keys(), [10, 11, 12])
     self.assertItemsEqual(details[10].keys(), ['name', 'avatar'])
     self.assertEqual(details[11]['name'], 'Adrian K.')
     self.assertEqual(details[11]['avatar'], '/api/images/users/11')
def users_view():
    """
    Users listing for dropdown.
    """
    details = get_details()

    loc = locale.getlocale()
    locale.setlocale(locale.LC_ALL, 'pl_PL.UTF-8')

    result = [{'user_id': i, 'name': val['name'], 'avatar': val['avatar']}
              for i, val in details.items()]
    result.sort(key=lambda k: locale.strxfrm(k['name']))

    locale.setlocale(locale.LC_ALL, loc)

    return result