# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import json
import mock
import sys
import unittest

from dashboard.pinpoint.models.change import commit
from dashboard.pinpoint import test


@unittest.skipIf(sys.version_info.major == 3,
                   'Skipping old handler tests for python 3.')
class CommitTest(test.TestCase):

  @mock.patch.object(commit.Commit, 'FromDict')
  def testPost(self, mock_dict):
    mock_dict.return_value = mock.MagicMock()
    mock_dict.return_value.AsDict = mock.MagicMock(return_value=['abc'])

    data = json.loads(self.testapp.post('/api/commit').body)

    self.assertEqual(['abc'], data)

  @mock.patch.object(commit.Commit, 'FromDict')
  def testPost_Fail(self, mock_dict):
    mock_dict.return_value = mock.MagicMock()
    mock_dict.return_value.AsDict = mock.MagicMock(side_effect=KeyError('foo'))

    self.testapp.post('/api/commit', status=400)

@@ -293,35 +293,8 @@
 mock
-%0Aimport sys%0Aimport unittest
 %0A%0Afr
@@ -385,117 +385,8 @@
 t%0A%0A%0A
-@unittest.skipIf(sys.version_info.major == 3,%0A                   'Skipping old handler tests for python 3.')%0A
 clas
@@ -616,16 +616,43 @@
 abc'%5D)%0A%0A
+    args = '?git_hash=abc'%0A
     data
@@ -696,16 +696,23 @@
 /commit'
+ + args
 ).body)%0A
@@ -737,191 +737,304 @@
 ual(
-%5B'abc'%5D, data)%0A%0A  @mock.patch.object(commit.Commit, 'FromDict')%0A  def testPost_Fail(self, mock_dict):%0A    
+mock_dict.call_args,%0A                     mock.call(%7B%0A                         'repository': 'chromium',%0A                         'git_hash': 'abc'%0A                     %7D))%0A    self.assertEqual(%5B'abc'%5D, data)%0A%0A  @
 mock
-_dict.return_value = mock.MagicMock()%0A    mock_dict.return_value.AsDict =
+.patch('dashboard.pinpoint.models.change.commit.Commit.FromDict',%0A             
  moc
@@ -1073,17 +1073,44 @@
 ('foo'))
-%0A
+)%0A  def testPost_Fail(self):
 %0A    sel

enable py3 tests on handlers/commit