Example #1
0
def test_FirebaseData_repr():
    data = firebase_data.FirebaseData(a=1)
    data_id = id(data)
    data.last_updated_at = datetime.datetime(
        year=2017, month=9, day=2, hour=20, minute=2, second=59
    )
    result = str(data)
    assert result == (
        'FirebaseData('
            'id={}, '
            'last_updated_at=2017-09-02 20:02:59, '
            'data={{\'a\': 1}}'
        ')'.format(data_id)
    )
Example #2
0
    def test_set_none_initally_update_with_dict(self):
        data = firebase_data.FirebaseData(None)
        data.set('/', {'foo': 1})
        result = data.get()

        assert result == {'foo': 1}
Example #3
0
 def test_set_different_type(self):
     data = firebase_data.FirebaseData({'foo': 1})
     data.set('/foo/bar', 2)
     assert data == {'foo': {'bar': 2}}
def firebase_data():
    return data.FirebaseData({})
Example #5
0
 def test_set_existing_child(self):
     data = firebase_data.FirebaseData({'foo': {'bar': 1}})
     data.set('/foo/bar', 2)
     assert data == {'foo': {'bar': 2}}
Example #6
0
 def test_set_root(self):
     data = firebase_data.FirebaseData()
     data.set('/', {'foo': 1})
     assert data == {'foo': 1}
Example #7
0
 def test_single_value(self):
     data = firebase_data.FirebaseData('a')
     assert data == {}
Example #8
0
 def test_dict(self):
     data = firebase_data.FirebaseData({'a': 1})
     assert data == {'a': 1}
Example #9
0
 def test_get_different_type_key(self):
     data = firebase_data.FirebaseData({'foo': 1})
     result = data.get('/foo/bar')
     assert result is None
Example #10
0
 def test_get_missing_key(self):
     data = firebase_data.FirebaseData()
     result = data.get('/foo/bar')
     assert result is None
Example #11
0
 def test_get_root(self):
     data = firebase_data.FirebaseData()
     result = data.get('/')
     assert result == {}
Example #12
0
 def test_unset_missing_child(self):
     data = firebase_data.FirebaseData({'foo': {'bar': 1}})
     data.set('/foo/bar/baz', None)
     assert data == {'foo': {'bar': {}}}
Example #13
0
 def test_unset_root(self):
     data = firebase_data.FirebaseData({'foo': {'bar': 1}})
     data.set('/', None)
     assert data == {}
Example #14
0
 def test_set_different_type_then_set_missing(self):
     data = firebase_data.FirebaseData({'foo': 1})
     data.set('/foo/bar', 2)
     data.set('/foo/bar/baz', {'qux': 1})
     assert data == {'foo': {'bar': {'baz': {'qux': 1}}}}
Example #15
0
 def test_set_missing_then_set_different_type(self):
     data = firebase_data.FirebaseData()
     data.set('/foo', 1)
     data.set('/foo/bar', 2)
     assert data == {'foo': {'bar': 2}}
Example #16
0
    def test_set_none_initally_update_subpath_with_dict_then_get_path(self):
        data = firebase_data.FirebaseData(None)
        data.set('/foo/bar', 1)
        result = data.get('/foo/bar')

        assert result == 1
Example #17
0
 def test_empty(self):
     data = firebase_data.FirebaseData()
     assert data == {}
Example #18
0
 def test_existing_key(self):
     data = firebase_data.FirebaseData({'foo': {'bar': 1}})
     result = data.get('/foo/bar')
     assert result == 1
Example #19
0
 def test_keys(self):
     data = firebase_data.FirebaseData(a=1)
     assert data == {'a': 1}
Example #20
0
    def test_set_on_init(self):
        data = firebase_data.FirebaseData()

        assert isinstance(data.last_updated_at, datetime.datetime)
Example #21
0
 def test_invalid_args(self):
     with pytest.raises(TypeError):
         firebase_data.FirebaseData('a', 'b')
Example #22
0
 def test_updated_after_update(self):
     old_time = datetime.datetime.utcnow()
     data = firebase_data.FirebaseData()
     data.set('foo', 'bar')
     assert data.last_updated_at > old_time
Example #23
0
 def test_set_missing_child(self):
     data = firebase_data.FirebaseData()
     data.set('/foo/bar', 1)
     assert data == {'foo': {'bar': 1}}
Example #24
0
    def test_set_none_initially(self):
        data = firebase_data.FirebaseData(None)
        result = data.get()

        assert result is None
Example #25
0
 def test_set_missing_then_set_existing(self):
     data = firebase_data.FirebaseData()
     data.set('/foo', {'bar': 1})
     data.set('/foo/bar', 2)
     assert data == {'foo': {'bar': 2}}
Example #26
0
    def test_set_str_initially(self):
        data = firebase_data.FirebaseData('hello')
        result = data.get()

        assert result == 'hello'
Example #27
0
    def test_no_default_data(self, livedata, mocker):
        livedata.get_data = mocker.Mock(return_value=data.FirebaseData(None))

        result = livedata.is_stale()

        assert result is False
Example #28
0
    def test_set_none_initally_update_string(self):
        data = firebase_data.FirebaseData(None)
        data.set('/', 'hello')
        result = data.get()

        assert result == 'hello'