~jderose/dmedia/transfer-manager

« back to all changes in this revision

Viewing changes to dmedia/backends/tests/test_s3.py

  • Committer: Jason Gerard DeRose
  • Date: 2011-04-23 07:29:32 UTC
  • Revision ID: jderose@novacut.com-20110423072932-gprwph1riuv2cf43
Added some more commen elements to TransferBackend, cleaned up S3Backend a bit and added tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Authors:
 
2
#   Jason Gerard DeRose <jderose@novacut.com>
 
3
#
 
4
# dmedia: distributed media library
 
5
# Copyright (C) 2011 Jason Gerard DeRose <jderose@novacut.com>
 
6
#
 
7
# This file is part of `dmedia`.
 
8
#
 
9
# `dmedia` is free software: you can redistribute it and/or modify it under the
 
10
# terms of the GNU Affero General Public License as published by the Free
 
11
# Software Foundation, either version 3 of the License, or (at your option) any
 
12
# later version.
 
13
#
 
14
# `dmedia` is distributed in the hope that it will be useful, but WITHOUT ANY
 
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 
16
# A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 
17
# details.
 
18
#
 
19
# You should have received a copy of the GNU Affero General Public License along
 
20
# with `dmedia`.  If not, see <http://www.gnu.org/licenses/>.
 
21
 
 
22
"""
 
23
Unit tests for the `dmedia.backends.s3` module.
 
24
"""
 
25
 
 
26
from unittest import TestCase
 
27
 
 
28
from dmedia.backends import s3
 
29
 
 
30
 
 
31
class TestS3Backend(TestCase):
 
32
    klass = s3.S3Backend
 
33
 
 
34
    def test_init(self):
 
35
        inst = self.klass({'_id': 'foo', 'bucket': 'bar'})
 
36
        self.assertEqual(inst.bucketname, 'bar')
 
37
        self.assertEqual(inst._bucket, None)
 
38
 
 
39
    def test_repr(self):
 
40
        inst = self.klass({'_id': 'foo', 'bucket': 'bar'})
 
41
        self.assertEqual(repr(inst), "S3Backend('foo')")
 
42
 
 
43
    def test_key(self):
 
44
        # Test with include_ext = False
 
45
        inst = self.klass({'_id': 'foo', 'bucket': 'bar'})
 
46
        self.assertEqual(
 
47
            inst.key('ZR765XWSF6S7JQHLUI4GCG5BHGPE252O'),
 
48
            'ZR765XWSF6S7JQHLUI4GCG5BHGPE252O'
 
49
        )
 
50
        self.assertEqual(
 
51
            inst.key('ZR765XWSF6S7JQHLUI4GCG5BHGPE252O', ext=None),
 
52
            'ZR765XWSF6S7JQHLUI4GCG5BHGPE252O'
 
53
        )
 
54
        self.assertEqual(
 
55
            inst.key('ZR765XWSF6S7JQHLUI4GCG5BHGPE252O', ext='mov'),
 
56
            'ZR765XWSF6S7JQHLUI4GCG5BHGPE252O'
 
57
        )
 
58
 
 
59
        # Test with include_ext = True
 
60
        inst = self.klass({'_id': 'foo', 'bucket': 'bar', 'include_ext': True})
 
61
        self.assertEqual(
 
62
            inst.key('ZR765XWSF6S7JQHLUI4GCG5BHGPE252O'),
 
63
            'ZR765XWSF6S7JQHLUI4GCG5BHGPE252O'
 
64
        )
 
65
        self.assertEqual(
 
66
            inst.key('ZR765XWSF6S7JQHLUI4GCG5BHGPE252O', ext=None),
 
67
            'ZR765XWSF6S7JQHLUI4GCG5BHGPE252O'
 
68
        )
 
69
        self.assertEqual(
 
70
            inst.key('ZR765XWSF6S7JQHLUI4GCG5BHGPE252O', ext='mov'),
 
71
            'ZR765XWSF6S7JQHLUI4GCG5BHGPE252O.mov'
 
72
        )
 
73
 
 
74
    def test_bucket(self):
 
75
        inst = self.klass({'_id': 'foo', 'bucket': 'bar'})
 
76
        inst._bucket = 'whatever'
 
77
        self.assertEqual(inst.bucket, 'whatever')