{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/26398855","id":26398855,"diff_hunk":"@@ -344,7 +346,99 @@ def login(self, profile):\n JINJA_INSTRUMENTED = False\n \n \n-class TestCase(MockEsMixin, RedisTest, MockBrowserIdMixin, test.TestCase):\n+class ClassFixtureTestCase(test.TestCase):\n+    \"\"\" Based on the changes to TestCase (& TransactionTestCase) in Django1.8.\n+\n+    Fixtures are loaded once per class, and a class setUpTestData method is\n+    added to be overridden by sublasses.  `transaction.atomic()` is used to\n+    achieve test isolation.\n+    See orginal code:\n+    https://github.com/django/django/blob/1.8b2/django/test/testcases.py\n+    #L747-990.\n+\n+    A noteable difference is that this class assumes the database supports\n+    transactions.  This class will be obsolete on upgrade to 1.8.\n+    \"\"\"\n+    fixtures = None\n+\n+    @classmethod\n+    def _databases_names(cls, include_mirrors=True):\n+        # If the test case has a multi_db=True flag, act on all databases,\n+        # including mirrors or not. Otherwise, just on the default DB.\n+        if getattr(cls, 'multi_db', False):\n+            return [alias for alias in connections\n+                    if (include_mirrors or\n+                        connections[alias].settings_dict['TEST']['MIRROR'])]\n+        else:\n+            return [DEFAULT_DB_ALIAS]\n+\n+    @classmethod\n+    def _enter_atomics(cls):\n+        \"\"\"Helper method to open atomic blocks for multiple databases\"\"\"\n+        atomics = {}\n+        for db_name in cls._databases_names():\n+            atomics[db_name] = transaction.atomic(using=db_name)\n+            atomics[db_name].__enter__()\n+        return atomics\n+\n+    @classmethod\n+    def _rollback_atomics(cls, atomics):\n+        \"\"\"Rollback atomic blocks opened through the previous method\"\"\"\n+        for db_name in reversed(cls._databases_names()):\n+            transaction.set_rollback(True, using=db_name)\n+            atomics[db_name].__exit__(None, None, None)\n+\n+    @classmethod\n+    def setUpClass(cls):\n+        cls.cls_atomics = cls._enter_atomics()\n+\n+        if cls.fixtures:\n+            for db_name in cls._databases_names(include_mirrors=False):\n+                    try:\n+                        call_command('loaddata', *cls.fixtures, **{\n+                            'verbosity': 0,\n+                            'commit': False,\n+                            'database': db_name,\n+                        })\n+                    except Exception:\n+                        cls._rollback_atomics(cls.cls_atomics)\n+                        raise\n+        cls.setUpTestData()\n+\n+    @classmethod\n+    def tearDownClass(cls):\n+        cls._rollback_atomics(cls.cls_atomics)\n+        for conn in connections.all():\n+            conn.close()\n+\n+    @classmethod\n+    def setUpTestData(cls):\n+        \"\"\"Load initial data for the TestCase\"\"\"\n+        pass\n+\n+    def _should_reload_connections(self):\n+        return False\n+\n+    def _fixture_setup(self):\n+        assert not self.reset_sequences, (\n+            'reset_sequences cannot be used on TestCase instances')\n+        self.atomics = self._enter_atomics()\n+\n+    def _fixture_teardown(self):\n+        self._rollback_atomics(self.atomics)\n+\n+    def _post_teardown(self):\n+        # Monkey-patch so connections don't get closed","path":"mkt/site/tests/__init__.py","position":100,"original_position":100,"commit_id":"d290429710540def8b8c266dd15c4ccfa38b6dc9","original_commit_id":"d290429710540def8b8c266dd15c4ccfa38b6dc9","user":{"login":"eviljeff","id":768592,"avatar_url":"https://avatars.githubusercontent.com/u/768592?v=3","gravatar_id":"","url":"https://api.github.com/users/eviljeff","html_url":"https://github.com/eviljeff","followers_url":"https://api.github.com/users/eviljeff/followers","following_url":"https://api.github.com/users/eviljeff/following{/other_user}","gists_url":"https://api.github.com/users/eviljeff/gists{/gist_id}","starred_url":"https://api.github.com/users/eviljeff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eviljeff/subscriptions","organizations_url":"https://api.github.com/users/eviljeff/orgs","repos_url":"https://api.github.com/users/eviljeff/repos","events_url":"https://api.github.com/users/eviljeff/events{/privacy}","received_events_url":"https://api.github.com/users/eviljeff/received_events","type":"User","site_admin":false},"body":"That's an original hack/monkeypatch :)\r\nIn 1.6 django's _post_teardown connections are closed and we don't want that to happen after each test anymore. https://github.com/django/django/blob/1.6.10/django/test/testcases.py#L788","created_at":"2015-03-13T16:13:31Z","updated_at":"2015-03-13T16:13:31Z","html_url":"https://github.com/mozilla/zamboni/pull/2979#discussion_r26398855","pull_request_url":"https://api.github.com/repos/mozilla/zamboni/pulls/2979","_links":{"self":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/26398855"},"html":{"href":"https://github.com/mozilla/zamboni/pull/2979#discussion_r26398855"},"pull_request":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2979"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/zamboni/pulls/2979","id":31119004,"html_url":"https://github.com/mozilla/zamboni/pull/2979","diff_url":"https://github.com/mozilla/zamboni/pull/2979.diff","patch_url":"https://github.com/mozilla/zamboni/pull/2979.patch","issue_url":"https://api.github.com/repos/mozilla/zamboni/issues/2979","number":2979,"state":"open","locked":false,"title":"class fixture loading support (bug 1142943)","user":{"login":"eviljeff","id":768592,"avatar_url":"https://avatars.githubusercontent.com/u/768592?v=3","gravatar_id":"","url":"https://api.github.com/users/eviljeff","html_url":"https://github.com/eviljeff","followers_url":"https://api.github.com/users/eviljeff/followers","following_url":"https://api.github.com/users/eviljeff/following{/other_user}","gists_url":"https://api.github.com/users/eviljeff/gists{/gist_id}","starred_url":"https://api.github.com/users/eviljeff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eviljeff/subscriptions","organizations_url":"https://api.github.com/users/eviljeff/orgs","repos_url":"https://api.github.com/users/eviljeff/repos","events_url":"https://api.github.com/users/eviljeff/events{/privacy}","received_events_url":"https://api.github.com/users/eviljeff/received_events","type":"User","site_admin":false},"body":"based on the implementation in TestCase and TransactionTestCase in Django 1.8","created_at":"2015-03-13T11:42:19Z","updated_at":"2015-03-13T16:13:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c33222e2e3ce440236d61fb48897db58ffb4c75d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/zamboni/pulls/2979/commits","review_comments_url":"https://api.github.com/repos/mozilla/zamboni/pulls/2979/comments","review_comment_url":"https://api.github.com/repos/mozilla/zamboni/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/zamboni/issues/2979/comments","statuses_url":"https://api.github.com/repos/mozilla/zamboni/statuses/d290429710540def8b8c266dd15c4ccfa38b6dc9","head":{"label":"eviljeff:test-case-class-fixtures2","ref":"test-case-class-fixtures2","sha":"d290429710540def8b8c266dd15c4ccfa38b6dc9","user":{"login":"eviljeff","id":768592,"avatar_url":"https://avatars.githubusercontent.com/u/768592?v=3","gravatar_id":"","url":"https://api.github.com/users/eviljeff","html_url":"https://github.com/eviljeff","followers_url":"https://api.github.com/users/eviljeff/followers","following_url":"https://api.github.com/users/eviljeff/following{/other_user}","gists_url":"https://api.github.com/users/eviljeff/gists{/gist_id}","starred_url":"https://api.github.com/users/eviljeff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eviljeff/subscriptions","organizations_url":"https://api.github.com/users/eviljeff/orgs","repos_url":"https://api.github.com/users/eviljeff/repos","events_url":"https://api.github.com/users/eviljeff/events{/privacy}","received_events_url":"https://api.github.com/users/eviljeff/received_events","type":"User","site_admin":false},"repo":{"id":2621451,"name":"zamboni","full_name":"eviljeff/zamboni","owner":{"login":"eviljeff","id":768592,"avatar_url":"https://avatars.githubusercontent.com/u/768592?v=3","gravatar_id":"","url":"https://api.github.com/users/eviljeff","html_url":"https://github.com/eviljeff","followers_url":"https://api.github.com/users/eviljeff/followers","following_url":"https://api.github.com/users/eviljeff/following{/other_user}","gists_url":"https://api.github.com/users/eviljeff/gists{/gist_id}","starred_url":"https://api.github.com/users/eviljeff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eviljeff/subscriptions","organizations_url":"https://api.github.com/users/eviljeff/orgs","repos_url":"https://api.github.com/users/eviljeff/repos","events_url":"https://api.github.com/users/eviljeff/events{/privacy}","received_events_url":"https://api.github.com/users/eviljeff/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eviljeff/zamboni","description":"A clandestine operation to make AMO happy","fork":true,"url":"https://api.github.com/repos/eviljeff/zamboni","forks_url":"https://api.github.com/repos/eviljeff/zamboni/forks","keys_url":"https://api.github.com/repos/eviljeff/zamboni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eviljeff/zamboni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eviljeff/zamboni/teams","hooks_url":"https://api.github.com/repos/eviljeff/zamboni/hooks","issue_events_url":"https://api.github.com/repos/eviljeff/zamboni/issues/events{/number}","events_url":"https://api.github.com/repos/eviljeff/zamboni/events","assignees_url":"https://api.github.com/repos/eviljeff/zamboni/assignees{/user}","branches_url":"https://api.github.com/repos/eviljeff/zamboni/branches{/branch}","tags_url":"https://api.github.com/repos/eviljeff/zamboni/tags","blobs_url":"https://api.github.com/repos/eviljeff/zamboni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eviljeff/zamboni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eviljeff/zamboni/git/refs{/sha}","trees_url":"https://api.github.com/repos/eviljeff/zamboni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eviljeff/zamboni/statuses/{sha}","languages_url":"https://api.github.com/repos/eviljeff/zamboni/languages","stargazers_url":"https://api.github.com/repos/eviljeff/zamboni/stargazers","contributors_url":"https://api.github.com/repos/eviljeff/zamboni/contributors","subscribers_url":"https://api.github.com/repos/eviljeff/zamboni/subscribers","subscription_url":"https://api.github.com/repos/eviljeff/zamboni/subscription","commits_url":"https://api.github.com/repos/eviljeff/zamboni/commits{/sha}","git_commits_url":"https://api.github.com/repos/eviljeff/zamboni/git/commits{/sha}","comments_url":"https://api.github.com/repos/eviljeff/zamboni/comments{/number}","issue_comment_url":"https://api.github.com/repos/eviljeff/zamboni/issues/comments{/number}","contents_url":"https://api.github.com/repos/eviljeff/zamboni/contents/{+path}","compare_url":"https://api.github.com/repos/eviljeff/zamboni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eviljeff/zamboni/merges","archive_url":"https://api.github.com/repos/eviljeff/zamboni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eviljeff/zamboni/downloads","issues_url":"https://api.github.com/repos/eviljeff/zamboni/issues{/number}","pulls_url":"https://api.github.com/repos/eviljeff/zamboni/pulls{/number}","milestones_url":"https://api.github.com/repos/eviljeff/zamboni/milestones{/number}","notifications_url":"https://api.github.com/repos/eviljeff/zamboni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eviljeff/zamboni/labels{/name}","releases_url":"https://api.github.com/repos/eviljeff/zamboni/releases{/id}","created_at":"2011-10-21T16:18:20Z","updated_at":"2014-07-24T18:07:38Z","pushed_at":"2015-03-13T15:28:06Z","git_url":"git://github.com/eviljeff/zamboni.git","ssh_url":"git@github.com:eviljeff/zamboni.git","clone_url":"https://github.com/eviljeff/zamboni.git","svn_url":"https://github.com/eviljeff/zamboni","homepage":"http://mozilla.github.com/zamboni/","size":332762,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"39f569790a69557f753c23e144241b3408b31539","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":347655,"name":"zamboni","full_name":"mozilla/zamboni","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/zamboni","description":"Backend for the Firefox Marketplace","fork":false,"url":"https://api.github.com/repos/mozilla/zamboni","forks_url":"https://api.github.com/repos/mozilla/zamboni/forks","keys_url":"https://api.github.com/repos/mozilla/zamboni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/zamboni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/zamboni/teams","hooks_url":"https://api.github.com/repos/mozilla/zamboni/hooks","issue_events_url":"https://api.github.com/repos/mozilla/zamboni/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/zamboni/events","assignees_url":"https://api.github.com/repos/mozilla/zamboni/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/zamboni/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/zamboni/tags","blobs_url":"https://api.github.com/repos/mozilla/zamboni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/zamboni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/zamboni/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/zamboni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/zamboni/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/zamboni/languages","stargazers_url":"https://api.github.com/repos/mozilla/zamboni/stargazers","contributors_url":"https://api.github.com/repos/mozilla/zamboni/contributors","subscribers_url":"https://api.github.com/repos/mozilla/zamboni/subscribers","subscription_url":"https://api.github.com/repos/mozilla/zamboni/subscription","commits_url":"https://api.github.com/repos/mozilla/zamboni/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/zamboni/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/zamboni/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/zamboni/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/zamboni/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/zamboni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/zamboni/merges","archive_url":"https://api.github.com/repos/mozilla/zamboni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/zamboni/downloads","issues_url":"https://api.github.com/repos/mozilla/zamboni/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/zamboni/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/zamboni/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/zamboni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/zamboni/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/zamboni/releases{/id}","created_at":"2009-10-23T19:35:34Z","updated_at":"2015-03-13T13:57:56Z","pushed_at":"2015-03-13T13:57:55Z","git_url":"git://github.com/mozilla/zamboni.git","ssh_url":"git@github.com:mozilla/zamboni.git","clone_url":"https://github.com/mozilla/zamboni.git","svn_url":"https://github.com/mozilla/zamboni","homepage":"http://marketplace.readthedocs.org/en/latest/topics/backend.html","size":397599,"stargazers_count":456,"watchers_count":456,"language":"Gettext Catalog","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":236,"mirror_url":null,"open_issues_count":14,"forks":236,"open_issues":14,"watchers":456,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2979"},"html":{"href":"https://github.com/mozilla/zamboni/pull/2979"},"issue":{"href":"https://api.github.com/repos/mozilla/zamboni/issues/2979"},"comments":{"href":"https://api.github.com/repos/mozilla/zamboni/issues/2979/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2979/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2979/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/zamboni/statuses/d290429710540def8b8c266dd15c4ccfa38b6dc9"}}}}