{"action":"created","comment":{"url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/comments/63880394","id":63880394,"diff_hunk":"@@ -1,7 +1,339 @@\n-from django.test import TestCase\n+from django.contrib.auth.models import User\n+from django.core.urlresolvers import reverse\n+from rest_framework import status\n+from rest_framework.request import Request\n+from rest_framework.reverse import reverse as drt_reverse\n+from rest_framework.test import APITestCase, APIRequestFactory\n \n+from authapi.serializers import (\n+    UserSerializer, TeamSerializer, OrganizationSummarySerializer,\n+    TeamSummarySerializer, PermissionSerializer, UserSummarySerializer,\n+    OrganizationSerializer)\n+from authapi.models import SeedTeam, SeedOrganization, SeedPermission\n \n-class RunningTests(TestCase):\n-    def test_tests_are_run(self):\n-        '''Make sure that our tests are actually running.'''\n-        pass\n+\n+class AuthAPITestCase(APITestCase):\n+    def get_context(self, url):\n+        '''Returns the request context for a given url.'''\n+        factory = APIRequestFactory()\n+        request = factory.get(url)\n+        return {\n+            'request': Request(request)\n+        }\n+\n+    def get_full_url(self, viewname, *args, **kwargs):\n+        '''Returns the full URL, with host and port. Takes the same arguments\n+        as reverse.'''\n+        factory = APIRequestFactory()\n+        part_url = reverse(viewname, *args, **kwargs)\n+        request = factory.get(part_url)\n+        kwargs['request'] = request\n+        return drt_reverse(viewname, *args, **kwargs)\n+\n+\n+class UserTests(AuthAPITestCase):\n+    def test_get_account_list_empty(self):\n+        '''If there are no accounts, and empty list should be returned.'''\n+        response = self.client.get(reverse('user-list'))\n+        self.assertEqual(response.data, [])\n+\n+    def test_get_account_list_multiple(self):\n+        '''If there are multiple users, it should return them all in a list.'''\n+        user1 = User.objects.create_user(username=\"user1@example.org\")\n+        user2 = User.objects.create_user(username=\"user2@example.org\")\n+\n+        context = self.get_context(reverse('user-list'))\n+        expected = [\n+            UserSerializer(instance=u, context=context).data\n+            for u in [user1, user2]\n+        ]\n+\n+        response = self.client.get(reverse('user-list'))\n+        self.assertEqual(\n+            sorted(expected, key=lambda i: i['id']),\n+            sorted(response.data, key=lambda i: i['id']))\n+\n+    def test_create_user_no_required_fields(self):\n+        '''A POST request to the user endpoint should return an error if there\n+        is no email field, as it is required.'''\n+        response = self.client.post(reverse('user-list'), data={})\n+        self.assertEqual(response.data, {\n+            'email': ['This field is required.']\n+        })\n+\n+    def test_create_user(self):\n+        '''A POST request to the user endpoint should create a user with all\n+        of the supplied details.'''\n+        data = {\n+            'email': 'user1@example.org',\n+            'first_name': 'user1',\n+            'last_name': 'example',\n+            'admin': True,\n+        }","path":"authapi/tests.py","position":77,"original_position":77,"commit_id":"932857f0926c06fa0346b30ffbc47cf77143fe7b","original_commit_id":"932857f0926c06fa0346b30ffbc47cf77143fe7b","user":{"login":"justinvdm","id":1731223,"avatar_url":"https://avatars.githubusercontent.com/u/1731223?v=3","gravatar_id":"","url":"https://api.github.com/users/justinvdm","html_url":"https://github.com/justinvdm","followers_url":"https://api.github.com/users/justinvdm/followers","following_url":"https://api.github.com/users/justinvdm/following{/other_user}","gists_url":"https://api.github.com/users/justinvdm/gists{/gist_id}","starred_url":"https://api.github.com/users/justinvdm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinvdm/subscriptions","organizations_url":"https://api.github.com/users/justinvdm/orgs","repos_url":"https://api.github.com/users/justinvdm/repos","events_url":"https://api.github.com/users/justinvdm/events{/privacy}","received_events_url":"https://api.github.com/users/justinvdm/received_events","type":"User","site_admin":false},"body":"Perfect, thanks.","created_at":"2016-05-19T13:45:08Z","updated_at":"2016-05-19T13:45:08Z","html_url":"https://github.com/praekelt/seed-auth-api/pull/5#discussion_r63880394","pull_request_url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/comments/63880394"},"html":{"href":"https://github.com/praekelt/seed-auth-api/pull/5#discussion_r63880394"},"pull_request":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5","id":70653046,"html_url":"https://github.com/praekelt/seed-auth-api/pull/5","diff_url":"https://github.com/praekelt/seed-auth-api/pull/5.diff","patch_url":"https://github.com/praekelt/seed-auth-api/pull/5.patch","issue_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues/5","number":5,"state":"open","locked":false,"title":"Add django-rest-framework","user":{"login":"rudigiesler","id":8234653,"avatar_url":"https://avatars.githubusercontent.com/u/8234653?v=3","gravatar_id":"","url":"https://api.github.com/users/rudigiesler","html_url":"https://github.com/rudigiesler","followers_url":"https://api.github.com/users/rudigiesler/followers","following_url":"https://api.github.com/users/rudigiesler/following{/other_user}","gists_url":"https://api.github.com/users/rudigiesler/gists{/gist_id}","starred_url":"https://api.github.com/users/rudigiesler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudigiesler/subscriptions","organizations_url":"https://api.github.com/users/rudigiesler/orgs","repos_url":"https://api.github.com/users/rudigiesler/repos","events_url":"https://api.github.com/users/rudigiesler/events{/privacy}","received_events_url":"https://api.github.com/users/rudigiesler/received_events","type":"User","site_admin":false},"body":"We need to add a skeleton for our various models, as well as adding django-rest-framework and setting it up.","created_at":"2016-05-19T08:20:26Z","updated_at":"2016-05-19T13:45:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d970580a9b50de18b3d5de076e76fa300b8ebb24","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5/commits","review_comments_url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5/comments","review_comment_url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues/5/comments","statuses_url":"https://api.github.com/repos/praekelt/seed-auth-api/statuses/932857f0926c06fa0346b30ffbc47cf77143fe7b","head":{"label":"praekelt:feature/issue-5-add-django-rest-framework","ref":"feature/issue-5-add-django-rest-framework","sha":"932857f0926c06fa0346b30ffbc47cf77143fe7b","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":58546064,"name":"seed-auth-api","full_name":"praekelt/seed-auth-api","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/seed-auth-api","description":"Authentication, authorization, and user store for seed applications.","fork":false,"url":"https://api.github.com/repos/praekelt/seed-auth-api","forks_url":"https://api.github.com/repos/praekelt/seed-auth-api/forks","keys_url":"https://api.github.com/repos/praekelt/seed-auth-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/seed-auth-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/seed-auth-api/teams","hooks_url":"https://api.github.com/repos/praekelt/seed-auth-api/hooks","issue_events_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/seed-auth-api/events","assignees_url":"https://api.github.com/repos/praekelt/seed-auth-api/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/seed-auth-api/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/seed-auth-api/tags","blobs_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/seed-auth-api/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/seed-auth-api/languages","stargazers_url":"https://api.github.com/repos/praekelt/seed-auth-api/stargazers","contributors_url":"https://api.github.com/repos/praekelt/seed-auth-api/contributors","subscribers_url":"https://api.github.com/repos/praekelt/seed-auth-api/subscribers","subscription_url":"https://api.github.com/repos/praekelt/seed-auth-api/subscription","commits_url":"https://api.github.com/repos/praekelt/seed-auth-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/seed-auth-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/seed-auth-api/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/seed-auth-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/seed-auth-api/merges","archive_url":"https://api.github.com/repos/praekelt/seed-auth-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/seed-auth-api/downloads","issues_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/seed-auth-api/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/seed-auth-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/seed-auth-api/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/seed-auth-api/releases{/id}","deployments_url":"https://api.github.com/repos/praekelt/seed-auth-api/deployments","created_at":"2016-05-11T13:12:50Z","updated_at":"2016-05-17T13:40:33Z","pushed_at":"2016-05-19T08:57:12Z","git_url":"git://github.com/praekelt/seed-auth-api.git","ssh_url":"git@github.com:praekelt/seed-auth-api.git","clone_url":"https://github.com/praekelt/seed-auth-api.git","svn_url":"https://github.com/praekelt/seed-auth-api","homepage":null,"size":144,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"develop"}},"base":{"label":"praekelt:develop","ref":"develop","sha":"7c222938842e87234b3dfeaa4fea1edc68dc4e53","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":58546064,"name":"seed-auth-api","full_name":"praekelt/seed-auth-api","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/seed-auth-api","description":"Authentication, authorization, and user store for seed applications.","fork":false,"url":"https://api.github.com/repos/praekelt/seed-auth-api","forks_url":"https://api.github.com/repos/praekelt/seed-auth-api/forks","keys_url":"https://api.github.com/repos/praekelt/seed-auth-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/seed-auth-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/seed-auth-api/teams","hooks_url":"https://api.github.com/repos/praekelt/seed-auth-api/hooks","issue_events_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/seed-auth-api/events","assignees_url":"https://api.github.com/repos/praekelt/seed-auth-api/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/seed-auth-api/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/seed-auth-api/tags","blobs_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/seed-auth-api/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/seed-auth-api/languages","stargazers_url":"https://api.github.com/repos/praekelt/seed-auth-api/stargazers","contributors_url":"https://api.github.com/repos/praekelt/seed-auth-api/contributors","subscribers_url":"https://api.github.com/repos/praekelt/seed-auth-api/subscribers","subscription_url":"https://api.github.com/repos/praekelt/seed-auth-api/subscription","commits_url":"https://api.github.com/repos/praekelt/seed-auth-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/seed-auth-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/seed-auth-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/seed-auth-api/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/seed-auth-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/seed-auth-api/merges","archive_url":"https://api.github.com/repos/praekelt/seed-auth-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/seed-auth-api/downloads","issues_url":"https://api.github.com/repos/praekelt/seed-auth-api/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/seed-auth-api/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/seed-auth-api/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/seed-auth-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/seed-auth-api/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/seed-auth-api/releases{/id}","deployments_url":"https://api.github.com/repos/praekelt/seed-auth-api/deployments","created_at":"2016-05-11T13:12:50Z","updated_at":"2016-05-17T13:40:33Z","pushed_at":"2016-05-19T08:57:12Z","git_url":"git://github.com/praekelt/seed-auth-api.git","ssh_url":"git@github.com:praekelt/seed-auth-api.git","clone_url":"https://github.com/praekelt/seed-auth-api.git","svn_url":"https://github.com/praekelt/seed-auth-api","homepage":null,"size":144,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5"},"html":{"href":"https://github.com/praekelt/seed-auth-api/pull/5"},"issue":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/issues/5"},"comments":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/praekelt/seed-auth-api/statuses/932857f0926c06fa0346b30ffbc47cf77143fe7b"}}}}