autotest_quickmerge_unittest.py: Ensure that needed portage API exists

BUG=chromium:306099
TEST=Unit test passes in the chroot, is skipped outside the chroot, and
fails for when I revert the recent portage API fix.

Change-Id: Iad9bfbe00ddf056ee1ee71d0b2d92daeff2243dd
Reviewed-on: https://chromium-review.googlesource.com/172639
Tested-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
diff --git a/scripts/autotest_quickmerge_unittest.py b/scripts/autotest_quickmerge_unittest.py
index 21cdb7a..f9ee8c3 100755
--- a/scripts/autotest_quickmerge_unittest.py
+++ b/scripts/autotest_quickmerge_unittest.py
@@ -8,6 +8,7 @@
 
 import os
 import sys
+import types
 import unittest
 import mox
 
@@ -179,7 +180,24 @@
 
     self.mox.VerifyAll()
 
+class PortageAPITest(unittest.TestCase):
+  """Ensures that required portage API exists."""
+  def runTest(self):
+    try:
+      import portage
+    except ImportError:
+      self.skipTest('Portage not available in test environment. Re-run test '
+                    'in chroot.')
+    try:
+      # pylint: disable-msg=E1101
+      f = portage.vardbapi.writeContentsToContentsFile
+    except AttributeError:
+      self.fail('Required writeContentsToContentsFile function does '
+                'not exist.')
 
+    self.assertIsInstance(f, types.UnboundMethodType,
+                          'Required writeContentsToContentsFile is not '
+                          'a function.')
 
 if __name__ == '__main__':
   cros_test_lib.main()