{"action":"created","comment":{"url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments/35961997","id":35961997,"diff_hunk":"@@ -0,0 +1,181 @@\n+# Copyright ClusterHQ Inc.  See LICENSE file for details.\n+\n+\"\"\"\n+Tests for the Flocker REST API client.\n+\"\"\"\n+\n+from uuid import uuid4\n+\n+from bitmath import GiB\n+\n+from zope.interface.verify import verifyObject\n+\n+from twisted.trial.unittest import TestCase\n+\n+from .._client import (\n+    IFlockerAPIV1, FakeFlockerAPIV1, Dataset, DatasetAlreadyExists,\n+    DatasetState,\n+)\n+\n+DATASET_SIZE = int(GiB(1).to_Byte().value)\n+\n+\n+def make_clientv1_tests(client_factory, synchronize_state):\n+    \"\"\"\n+    Create a ``TestCase`` for testing ``IFlockerAPIV1``.\n+\n+    The presumption is that the state of datasets is completely under\n+    control of this process. So when testing a real client it will be\n+    talking to a in-process server.\n+\n+    :param client_factory: 0-argument callable that returns a\n+        ``IFlockerAPIV1`` provider.\n+\n+    :param synchronize_state: 1-argument callable that takes a client\n+        instances and makes or waits for state to match configuration.\n+    \"\"\"\n+    class InterfaceTests(TestCase):\n+        def setUp(self):\n+            self.node_1 = uuid4()\n+            self.node_2 = uuid4()\n+\n+        def test_interface(self):\n+            \"\"\"\n+            The created client provides ``IFlockerAPIV1``.\n+            \"\"\"\n+            client = client_factory()\n+            self.assertTrue(verifyObject(IFlockerAPIV1, client))\n+\n+        def assert_creates(self, client, dataset_id=None, **create_kwargs):\n+            \"\"\"\n+            Create a dataset and ensure it shows up in the configuration and\n+            return result of the ``create_dataset`` call.\n+\n+            :param IFlockerAPIV1 client: Client to use.\n+            :param dataset_id: Dataset ID to use, or ``None`` if it should\n+                be generated.\n+            :param create_kwargs: Additional arguments to pass to\n+                ``create_dataset``.\n+\n+            :return: ``Deferred`` firing with result of\n+                ``create_dataset``.\n+            \"\"\"\n+            created = client.create_dataset(\n+                dataset_id=dataset_id, **create_kwargs)\n+\n+            def got_result(dataset):\n+                if dataset_id is None:\n+                    expected_dataset_id = dataset.dataset_id\n+                else:\n+                    expected_dataset_id = dataset_id\n+                expected = Dataset(dataset_id=expected_dataset_id,\n+                                   **create_kwargs)\n+                self.assertEqual(expected, dataset)\n+\n+                listed = client.list_datasets_configuration()\n+                listed.addCallback(\n+                    lambda result: self.assertIn(expected, result))\n+                listed.addCallback(lambda _: dataset)\n+                return listed\n+\n+            created.addCallback(got_result)\n+            return created\n+\n+        def test_create_assigns_dataset(self):\n+            \"\"\"\n+            If no ``dataset_id`` is specified when calling ``create_dataset``,\n+            a new one is generated.\n+            \"\"\"\n+            return self.assert_creates(client_factory(), primary=self.node_1,\n+                                       maximum_size=DATASET_SIZE)\n+\n+        def test_create_given_dataset(self):\n+            \"\"\"\n+            If no ``dataset_id`` is specified when calling ``create_dataset``,\n+            a new one is generated.\n+            \"\"\"\n+            return self.assert_creates(client_factory(), primary=self.node_1,\n+                                       maximum_size=DATASET_SIZE,\n+                                       dataset_id=uuid4())\n+\n+        def test_create_with_metadata(self):\n+            \"\"\"\n+            The metadata passed to ``create_dataset`` is stored with the\n+            dataset.\n+            \"\"\"\n+            return self.assert_creates(client_factory(), primary=self.node_1,\n+                                       maximum_size=DATASET_SIZE,\n+                                       metadata={u\"hello\": u\"there\"})\n+\n+        def test_create_conflicting_dataset_id(self):\n+            \"\"\"\n+            Creating two datasets with same ``dataset_id`` results in an\n+            ``DatasetAlreadyExists``.\n+            \"\"\"\n+            client = client_factory()\n+            d = self.assert_creates(client, primary=self.node_1,\n+                                    maximum_size=DATASET_SIZE)\n+\n+            def got_result(dataset):\n+                d = client.create_dataset(primary=self.node_1,\n+                                          maximum_size=DATASET_SIZE,\n+                                          dataset_id=dataset.dataset_id)\n+                return self.assertFailure(d, DatasetAlreadyExists)\n+            d.addCallback(got_result)\n+            return d\n+\n+        def test_move(self):\n+            \"\"\"\n+            ``move_dataset`` changes the dataset's primary.\n+            \"\"\"\n+            client = client_factory()\n+            dataset_id = uuid4()\n+\n+            d = self.assert_creates(client, primary=self.node_1,\n+                                    maximum_size=DATASET_SIZE,\n+                                    dataset_id=dataset_id)\n+            d.addCallback(\n+                lambda _: client.move_dataset(self.node_2, dataset_id))\n+\n+            def got_result(dataset):\n+                listed = client.list_datasets_configuration()\n+                listed.addCallback(lambda l: (dataset, l))\n+                return listed\n+            d.addCallback(got_result)\n+\n+            d.addCallback(lambda result:\n+                          self.assertEqual((result[0], result[0] in result[1]),\n+                                           (Dataset(dataset_id=dataset_id,\n+                                                    primary=self.node_2,\n+                                                    maximum_size=DATASET_SIZE),\n+                                            True)))\n+            return d\n+\n+        def test_list_state(self):\n+            \"\"\"\n+            ``list_datasets_state`` returns information about state.\n+            \"\"\"\n+            client = client_factory()\n+            dataset_id = uuid4()\n+            d = self.assert_creates(client, primary=self.node_1,\n+                                    maximum_size=DATASET_SIZE * 2,\n+                                    dataset_id=dataset_id)\n+            d.addCallback(lambda _: synchronize_state(client))\n+            d.addCallback(lambda _: client.list_datasets_state())\n+            d.addCallback(lambda states:\n+                          self.assertIn(\n+                              DatasetState(dataset_id=dataset_id,\n+                                           primary=self.node_1,\n+                                           maximum_size=DATASET_SIZE * 2),\n+                              states))\n+            return d\n+","path":"flocker/apiclient/test/test_client.py","position":172,"original_position":172,"commit_id":"a04741fa443d5a11c1d474e8f70143043c6b9cfe","original_commit_id":"a04741fa443d5a11c1d474e8f70143043c6b9cfe","user":{"login":"jml","id":125674,"avatar_url":"https://avatars.githubusercontent.com/u/125674?v=3","gravatar_id":"","url":"https://api.github.com/users/jml","html_url":"https://github.com/jml","followers_url":"https://api.github.com/users/jml/followers","following_url":"https://api.github.com/users/jml/following{/other_user}","gists_url":"https://api.github.com/users/jml/gists{/gist_id}","starred_url":"https://api.github.com/users/jml/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jml/subscriptions","organizations_url":"https://api.github.com/users/jml/orgs","repos_url":"https://api.github.com/users/jml/repos","events_url":"https://api.github.com/users/jml/events{/privacy}","received_events_url":"https://api.github.com/users/jml/received_events","type":"User","site_admin":false},"body":":question: Other tests to consider adding:\r\n\r\n* what if `maximum_size` is zero, or negative\r\n* initial state and configuration of supplied client","created_at":"2015-07-31T10:18:23Z","updated_at":"2015-07-31T10:18:23Z","html_url":"https://github.com/ClusterHQ/flocker/pull/1814#discussion_r35961997","pull_request_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814","_links":{"self":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments/35961997"},"html":{"href":"https://github.com/ClusterHQ/flocker/pull/1814#discussion_r35961997"},"pull_request":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814"}}},"pull_request":{"url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814","id":41246770,"html_url":"https://github.com/ClusterHQ/flocker/pull/1814","diff_url":"https://github.com/ClusterHQ/flocker/pull/1814.diff","patch_url":"https://github.com/ClusterHQ/flocker/pull/1814.patch","issue_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/1814","number":1814,"state":"open","locked":false,"title":"[FLOC-2752] Flocker client interface and in-memory fake","user":{"login":"itamarst","id":3266662,"avatar_url":"https://avatars.githubusercontent.com/u/3266662?v=3","gravatar_id":"","url":"https://api.github.com/users/itamarst","html_url":"https://github.com/itamarst","followers_url":"https://api.github.com/users/itamarst/followers","following_url":"https://api.github.com/users/itamarst/following{/other_user}","gists_url":"https://api.github.com/users/itamarst/gists{/gist_id}","starred_url":"https://api.github.com/users/itamarst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itamarst/subscriptions","organizations_url":"https://api.github.com/users/itamarst/orgs","repos_url":"https://api.github.com/users/itamarst/repos","events_url":"https://api.github.com/users/itamarst/events{/privacy}","received_events_url":"https://api.github.com/users/itamarst/received_events","type":"User","site_admin":false},"body":"The interface will be implemented by real client in follow-up issue; the fake will be used by the Docker plugin to test the plugin logic.","created_at":"2015-07-30T15:24:12Z","updated_at":"2015-07-31T10:18:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d0adeb5d6ad2b7fa6d89838461226dc6b8119304","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814/commits","review_comments_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814/comments","review_comment_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/1814/comments","statuses_url":"https://api.github.com/repos/ClusterHQ/flocker/statuses/a04741fa443d5a11c1d474e8f70143043c6b9cfe","head":{"label":"ClusterHQ:flocker-client-interface-FLOC-2752","ref":"flocker-client-interface-FLOC-2752","sha":"a04741fa443d5a11c1d474e8f70143043c6b9cfe","user":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"repo":{"id":19248542,"name":"flocker","full_name":"ClusterHQ/flocker","owner":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ClusterHQ/flocker","description":"Easily manage Docker containers & their data","fork":false,"url":"https://api.github.com/repos/ClusterHQ/flocker","forks_url":"https://api.github.com/repos/ClusterHQ/flocker/forks","keys_url":"https://api.github.com/repos/ClusterHQ/flocker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ClusterHQ/flocker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ClusterHQ/flocker/teams","hooks_url":"https://api.github.com/repos/ClusterHQ/flocker/hooks","issue_events_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/events{/number}","events_url":"https://api.github.com/repos/ClusterHQ/flocker/events","assignees_url":"https://api.github.com/repos/ClusterHQ/flocker/assignees{/user}","branches_url":"https://api.github.com/repos/ClusterHQ/flocker/branches{/branch}","tags_url":"https://api.github.com/repos/ClusterHQ/flocker/tags","blobs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ClusterHQ/flocker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/refs{/sha}","trees_url":"https://api.github.com/repos/ClusterHQ/flocker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ClusterHQ/flocker/statuses/{sha}","languages_url":"https://api.github.com/repos/ClusterHQ/flocker/languages","stargazers_url":"https://api.github.com/repos/ClusterHQ/flocker/stargazers","contributors_url":"https://api.github.com/repos/ClusterHQ/flocker/contributors","subscribers_url":"https://api.github.com/repos/ClusterHQ/flocker/subscribers","subscription_url":"https://api.github.com/repos/ClusterHQ/flocker/subscription","commits_url":"https://api.github.com/repos/ClusterHQ/flocker/commits{/sha}","git_commits_url":"https://api.github.com/repos/ClusterHQ/flocker/git/commits{/sha}","comments_url":"https://api.github.com/repos/ClusterHQ/flocker/comments{/number}","issue_comment_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/comments{/number}","contents_url":"https://api.github.com/repos/ClusterHQ/flocker/contents/{+path}","compare_url":"https://api.github.com/repos/ClusterHQ/flocker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ClusterHQ/flocker/merges","archive_url":"https://api.github.com/repos/ClusterHQ/flocker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ClusterHQ/flocker/downloads","issues_url":"https://api.github.com/repos/ClusterHQ/flocker/issues{/number}","pulls_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls{/number}","milestones_url":"https://api.github.com/repos/ClusterHQ/flocker/milestones{/number}","notifications_url":"https://api.github.com/repos/ClusterHQ/flocker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ClusterHQ/flocker/labels{/name}","releases_url":"https://api.github.com/repos/ClusterHQ/flocker/releases{/id}","created_at":"2014-04-28T18:02:14Z","updated_at":"2015-07-31T06:11:56Z","pushed_at":"2015-07-31T09:54:53Z","git_url":"git://github.com/ClusterHQ/flocker.git","ssh_url":"git@github.com:ClusterHQ/flocker.git","clone_url":"https://github.com/ClusterHQ/flocker.git","svn_url":"https://github.com/ClusterHQ/flocker","homepage":"https://clusterhq.com","size":62219,"stargazers_count":1747,"watchers_count":1747,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":116,"mirror_url":null,"open_issues_count":28,"forks":116,"open_issues":28,"watchers":1747,"default_branch":"master"}},"base":{"label":"ClusterHQ:master","ref":"master","sha":"533832e3f79184482067460f6c57e5eb026be5e4","user":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"repo":{"id":19248542,"name":"flocker","full_name":"ClusterHQ/flocker","owner":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ClusterHQ/flocker","description":"Easily manage Docker containers & their data","fork":false,"url":"https://api.github.com/repos/ClusterHQ/flocker","forks_url":"https://api.github.com/repos/ClusterHQ/flocker/forks","keys_url":"https://api.github.com/repos/ClusterHQ/flocker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ClusterHQ/flocker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ClusterHQ/flocker/teams","hooks_url":"https://api.github.com/repos/ClusterHQ/flocker/hooks","issue_events_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/events{/number}","events_url":"https://api.github.com/repos/ClusterHQ/flocker/events","assignees_url":"https://api.github.com/repos/ClusterHQ/flocker/assignees{/user}","branches_url":"https://api.github.com/repos/ClusterHQ/flocker/branches{/branch}","tags_url":"https://api.github.com/repos/ClusterHQ/flocker/tags","blobs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ClusterHQ/flocker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/refs{/sha}","trees_url":"https://api.github.com/repos/ClusterHQ/flocker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ClusterHQ/flocker/statuses/{sha}","languages_url":"https://api.github.com/repos/ClusterHQ/flocker/languages","stargazers_url":"https://api.github.com/repos/ClusterHQ/flocker/stargazers","contributors_url":"https://api.github.com/repos/ClusterHQ/flocker/contributors","subscribers_url":"https://api.github.com/repos/ClusterHQ/flocker/subscribers","subscription_url":"https://api.github.com/repos/ClusterHQ/flocker/subscription","commits_url":"https://api.github.com/repos/ClusterHQ/flocker/commits{/sha}","git_commits_url":"https://api.github.com/repos/ClusterHQ/flocker/git/commits{/sha}","comments_url":"https://api.github.com/repos/ClusterHQ/flocker/comments{/number}","issue_comment_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/comments{/number}","contents_url":"https://api.github.com/repos/ClusterHQ/flocker/contents/{+path}","compare_url":"https://api.github.com/repos/ClusterHQ/flocker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ClusterHQ/flocker/merges","archive_url":"https://api.github.com/repos/ClusterHQ/flocker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ClusterHQ/flocker/downloads","issues_url":"https://api.github.com/repos/ClusterHQ/flocker/issues{/number}","pulls_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls{/number}","milestones_url":"https://api.github.com/repos/ClusterHQ/flocker/milestones{/number}","notifications_url":"https://api.github.com/repos/ClusterHQ/flocker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ClusterHQ/flocker/labels{/name}","releases_url":"https://api.github.com/repos/ClusterHQ/flocker/releases{/id}","created_at":"2014-04-28T18:02:14Z","updated_at":"2015-07-31T06:11:56Z","pushed_at":"2015-07-31T09:54:53Z","git_url":"git://github.com/ClusterHQ/flocker.git","ssh_url":"git@github.com:ClusterHQ/flocker.git","clone_url":"https://github.com/ClusterHQ/flocker.git","svn_url":"https://github.com/ClusterHQ/flocker","homepage":"https://clusterhq.com","size":62219,"stargazers_count":1747,"watchers_count":1747,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":116,"mirror_url":null,"open_issues_count":28,"forks":116,"open_issues":28,"watchers":1747,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814"},"html":{"href":"https://github.com/ClusterHQ/flocker/pull/1814"},"issue":{"href":"https://api.github.com/repos/ClusterHQ/flocker/issues/1814"},"comments":{"href":"https://api.github.com/repos/ClusterHQ/flocker/issues/1814/comments"},"review_comments":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814/comments"},"review_comment":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1814/commits"},"statuses":{"href":"https://api.github.com/repos/ClusterHQ/flocker/statuses/a04741fa443d5a11c1d474e8f70143043c6b9cfe"}}}}