예제 #1
0
    def test_simple(self):
        d = datetime.today()
        s = AnalyzeReObject(num=1,
                            str='foo',
                            date=d,
                            list=[1, 2, 3],
                            dict={
                                'foo': 'bar'
                            },
                            ref=Reference('https://api/layers/abc123'),
                            res=Resource(id='abc123', foo='bar')).to_dict()

        assert s == {
            'num': 1,
            'str': 'foo',
            'date': d,
            'list': [1, 2, 3],
            'dict': {
                'foo': 'bar'
            },
            'ref': {
                'ref_id': 'abc123'
            },
            'res': {
                'ref_id': 'abc123'
            }
        }
예제 #2
0
 def test_nested(self):
     d = datetime.today()
     num = AnalyzeReObject(num=1)
     str_ = AnalyzeReObject(str='foo')
     date = AnalyzeReObject(date=d)
     list_ = AnalyzeReObject(list=[1, 2, 3])
     dict_ = AnalyzeReObject(dict={'foo': 'bar'})
     ref = AnalyzeReObject(ref=Reference('https://api/layers/abc123'))
     res = AnalyzeReObject(res=Resource(id='abc123', foo='bar'))
     s = AnalyzeReObject(num=num,
                         str=str_,
                         date=date,
                         list=list_,
                         dict=dict_,
                         ref=ref,
                         res=res).to_dict()
     assert s == {
         'num': {
             'num': 1
         },
         'str': {
             'str': 'foo'
         },
         'date': {
             'date': d
         },
         'list': {
             'list': [1, 2, 3]
         },
         'dict': {
             'dict': {
                 'foo': 'bar'
             }
         },
         'ref': {
             'ref': {
                 'ref_id': 'abc123'
             }
         },
         'res': {
             'res': {
                 'ref_id': 'abc123'
             }
         }
     }
예제 #3
0
 def test_resources_without_id_inlined(self):
     s = AnalyzeReObject(res=Resource(foo='bar')).to_dict()
     assert 'foo' in s['res']
     assert s['res']['foo'] == 'bar'
     assert 'ref_id' not in s['res']
예제 #4
0
 def test_type_renamed(self):
     s = AnalyzeReObject(type='bar').to_dict()
     assert 'type' not in s
     assert s['_type'] == 'bar'
예제 #5
0
 def test_private_stripped(self):
     s = AnalyzeReObject(_foo='bar').to_dict()
     assert '_foo' not in s
예제 #6
0
 def test_id_not_stripped(self):
     s = AnalyzeReObject(id='abc123').to_dict()
     assert 'id' in s
예제 #7
0
    def test_hash(self):
        common_id = str(uuid.uuid4())
        different_id = str(uuid.uuid4())

        compare_object = AnalyzeReObject(id=common_id, foo='bar', baz='qux')
        no_id_object = AnalyzeReObject(foo='bar', baz='qux')
        different_id_object = AnalyzeReObject(id=different_id,
                                              foo='bar',
                                              baz='qux')
        same_id_object = AnalyzeReObject(id=common_id, foo='bar', baz='qux')
        invalid_uuid_object = AnalyzeReObject(id='not-a-uuid',
                                              foo='bar',
                                              baz='qux')

        assert compare_object.__hash__() != no_id_object.__hash__()
        assert compare_object.__hash__() != different_id_object.__hash__()
        assert compare_object.__hash__() == same_id_object.__hash__()
        assert compare_object.__hash__() != invalid_uuid_object.__hash__()
예제 #8
0
 def test_str(self):
     a = AnalyzeReObject(foo='bar', baz='qux')
     assert str(a) == '{\n  "baz": "qux",\n  "foo": "bar"\n}'
예제 #9
0
 def test_repr(self):
     a = AnalyzeReObject(foo='bar', baz='qux')
     assert (repr(a) == '<AnalyzeReObject at %s> JSON: {\n  '
             '"baz": "qux",\n  "foo": "bar"\n}' % hex(id(a)))
예제 #10
0
 def test_clear(self):
     a = AnalyzeReObject(foo='bar', baz='qux')
     a.clear()
     assert not hasattr(a, 'foo')
     assert not hasattr(a, 'baz')
예제 #11
0
 def test_update(self):
     a = AnalyzeReObject(foo='bar', baz='qux')
     b = AnalyzeReObject(foo='fizz')
     a.update(b)
     assert a.foo == 'fizz'
     assert a.baz == 'qux'
예제 #12
0
 def test_initialize_from_kwargs(self):
     a = AnalyzeReObject(_type='sometype', foo='bar', baz='qux')
     assert a.type == 'sometype'
     assert a.foo == 'bar'
     assert a.baz == 'qux'
 def test_update(self):
     a = AnalyzeReObject(foo='bar', baz='qux')
     b = AnalyzeReObject(foo='fizz')
     a.update(b)
     assert a.foo == 'fizz'
     assert a.baz == 'qux'
 def test_clear(self):
     a = AnalyzeReObject(foo='bar', baz='qux')
     a.clear()
     assert not hasattr(a, 'foo')
     assert not hasattr(a, 'baz')