github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/lib/python/camli/schema_test.py (about)

     1  #!/usr/bin/env python
     2  #
     3  # Camlistore uploader client for Python.
     4  #
     5  # Copyright 2011 Google Inc.
     6  #
     7  # Licensed under the Apache License, Version 2.0 (the "License");
     8  # you may not use this file except in compliance with the License.
     9  # You may obtain a copy of the License at
    10  #
    11  #     http://www.apache.org/licenses/LICENSE-2.0
    12  #
    13  # Unless required by applicable law or agreed to in writing, software
    14  # distributed under the License is distributed on an "AS IS" BASIS,
    15  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  # See the License for the specific language governing permissions and
    17  # limitations under the License.
    18  #
    19  """Schema blob library for Camlistore."""
    20  
    21  __author__ = 'Brett Slatkin (bslatkin@gmail.com)'
    22  
    23  import datetime
    24  import os
    25  import sys
    26  import unittest
    27  
    28  sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
    29  
    30  import camli.schema
    31  import simplejson
    32  
    33  
    34  class SchemaTest(unittest.TestCase):
    35    """End-to-end tests for Schema blobs."""
    36  
    37    def testFile(self):
    38      schema_blob = camli.schema.decode('asdf-myblobref', """{
    39        "camliVersion": 1,
    40        "camliType": "file",
    41        "size": 0,
    42        "contentParts": [],
    43        "unixMtime": "2010-07-10T17:14:51.5678Z",
    44        "unixCtime": "2010-07-10T17:20:03Z"
    45      }""")
    46      self.assertTrue(isinstance(schema_blob, camli.schema.File))
    47      self.assertTrue(isinstance(schema_blob, camli.schema.FileCommon))
    48      self.assertTrue(isinstance(schema_blob, camli.schema.SchemaBlob))
    49      expected = {
    50        'unexpected_fields': {},
    51        'unix_mtime': datetime.datetime(2010, 7, 10, 17, 14, 51, 567800),
    52        'content_parts': [],
    53        'blobref': 'asdf-myblobref',
    54        'unix_ctime': datetime.datetime(2010, 7, 10, 17, 20, 3),
    55        'camli_version': 1,
    56        'camli_type': u'file',
    57        'size': 0
    58      }
    59      self.assertEquals(expected, schema_blob.__dict__)
    60      result = schema_blob.encode()
    61      result_parsed = simplejson.loads(result)
    62      expected = {
    63        'camliType': 'file',
    64        'camliVersion': 1,
    65        'unixMtime': '2010-07-10T17:14:51.567800Z',
    66        'unixCtime': '2010-07-10T17:20:03Z',
    67        'contentParts': [],
    68        'size': 0,
    69      }
    70      self.assertEquals(expected, result_parsed)
    71  
    72  
    73  if __name__ == '__main__':
    74    unittest.main()