from django.core.urlresolvers import NoReverseMatch, Resolver404, reverse, resolve
from django.test import TestCase

from users import resources


COLLECTION_METHODS = {
    'GET': 'index',
    'POST': 'create'
}
MEMBER_METHODS = {
    'GET': 'show',
    'POST': 'update',
    'PUT': 'update',
    'DELETE': 'destroy'
}
SINGLETON_METHODS = {
    'GET': 'show',
    'POST': 'update',
    'PUT': 'update',
    'DELETE': 'destroy'
}
EDIT_METHODS = {'GET': 'edit'}
NEW_METHODS = {'GET': 'new'}


class RoutingTest(TestCase):

    def assert_resolves(self, url, func, *args, **kwargs):
        resolved = resolve(url)
        self.assertEqual(resolved.func, func)
        self.assertEqual(resolved.args, args)
        # Check that `resolved.kwargs` is a superset of `kwargs`.
        for kw, value in kwargs.items():
            self.assertIn(kw, resolved.kwargs)
            self.assertEqual(resolved.kwargs[kw], value)
        # Allows for further user-level assertions.
        return resolved


class DefaultRoutingTest(RoutingTest):

    def test_index(self):
        self.assertEqual(reverse('User#index'), '/users/')