[2acc11]: script.module.brightcove / tests / test_core.py  Maximize  Restore  History

Download this file

126 lines (95 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from unittest import TestCase
from brightcove.core import APIObjectMeta, Field, DateTimeField, ListField, get_item
from operator import attrgetter
from datetime import datetime
class TestFunctions(TestCase):
def setUp(self):
class Bar(object):
def __init__(self, bar=None, baz=None):
self.bar = bar
self.baz = baz
self.Bar = Bar
def test_get_item_dict(self):
kwargs = {u'bar': 'bar', u'baz': 'baz'}
item = get_item(kwargs, self.Bar)
self.assertEqual(item.bar, 'bar')
self.assertEqual(item.baz, 'baz')
#def test_get_item_list(self):
#args = [('bar', 'baz')]
#item = get_item(args, self.Bar)
#self.assertEqual(item.bar, 'bar')
#self.assertEqual(item.baz, 'baz')
class TestField(TestCase):
def setUp(self):
self.field = Field('help')
def test_init(self):
self.assertEqual(self.field.help, 'help')
def test_to_python(self):
self.assertEqual(self.field.to_python('alpha'), 'alpha')
self.assertEqual(self.field.to_python(True), True)
self.assertEqual(self.field.to_python(42), 42)
def test_from_python(self):
self.assertEqual(self.field.from_python('alpha'), 'alpha')
self.assertEqual(self.field.from_python(True), True)
self.assertEqual(self.field.from_python(42), 42)
class TestDateTimeField(TestCase):
def test_to_python(self):
ts = '1320283529000'
isoformat = '2011-11-02T21:25:29'
dtf = DateTimeField()
dt = dtf.to_python(ts)
self.assertEqual(dt.isoformat(), isoformat)
def test_from_python(self):
ts = 1320283529
long_ts = '1320283529000'
dt = datetime.fromtimestamp(ts)
dtf = DateTimeField()
self.assertEqual(dtf.from_python(dt), long_ts)
class TestListField(TestCase):
def setUp(self):
class A(object):
def __init__(self, value):
self.value = value
def __eq__(self, other):
return self.value == other.value
def from_python(self):
return self.value
self.A = A
self.lf = ListField(self.A, help='help')
def test_init(self):
self.assertEqual(self.lf.item_cls, self.A)
self.assertEqual(self.lf.help, 'help')
def test_to_python(self):
before = ['alpha', 'bravo', 'charlie']
after = self.lf.to_python(before)
self.assertEqual([self.A('alpha'), self.A('bravo'), self.A('charlie')], after)
def test_from_python(self):
before = [self.A('alpha'), self.A('bravo')]
after = ['alpha', 'bravo']
self.assertEqual(self.lf.from_python(before), after)
class TestAPIObjectMeta(TestCase):
def setUp(self):
class Bar(object):
__metaclass__ = APIObjectMeta
_fields = ['alpha', 'bravo', 'charlie']
self.Bar = Bar
def test_cls_creation(self):
class Foo(object):
__metaclass__ = APIObjectMeta
_fields = ['bar', 'baz']
self.assertEqual(Foo.bar, None)
self.assertEqual(Foo.baz, None)
self.assertEqual(Foo._meta.keys(), ['bar', 'baz'])
self.assertEqual(isinstance(Foo._meta['bar'], Field), True)
self.assertEqual(isinstance(Foo._meta['baz'], Field), True)
self.assertRaises(AttributeError, attrgetter('_fields'), Foo)
def test_cls_constructor(self):
bar = self.Bar(alpha='alpha', bravo='bravo', charlie='charlie')
self.assertEqual(bar.alpha, 'alpha')
self.assertEqual(bar.bravo, 'bravo')
self.assertEqual(bar.charlie, 'charlie')
def test_nonspecified_args(self):
bar = self.Bar(delta='delta')
self.assertEqual(bar.delta, 'delta')
def test_non_kwargs(self):
self.assertRaises(TypeError, attrgetter('Bar'), self, 'alpha')

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks