forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_models.py
More file actions
608 lines (528 loc) · 26.5 KB
/
Copy pathtest_models.py
File metadata and controls
608 lines (528 loc) · 26.5 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
"""
This modules contains tests for pulp_python.plugins.models.
"""
from gettext import gettext as _
import hashlib
import tarfile
import unittest
import mock
from pulp_python.common import constants
from pulp_python.plugins import models
# The BAD_MANIFEST is missing the Version field.
BAD_MANIFEST = """Metadata-Version: 1.1
Name: nectar
Summary: Performance tuned network download client library
Home-page: https://github.com/pulp/nectar
Author: Pulp Team
Author-email: pulp-list@redhat.com
License: GPLv2
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Topic :: Software Development :: Libraries :: Python Modules"""
GOOD_MANIFEST = """Metadata-Version: 1.1
Name: nectar
Version: 1.3.1
Summary: Performance tuned network download client library
Home-page: https://github.com/pulp/nectar
Author: Pulp Team
Author-email: pulp-list@redhat.com
License: GPLv2
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Topic :: Software Development :: Libraries :: Python Modules"""
class TestPackage(unittest.TestCase):
"""
This class contains tests for the Package class.
"""
def test_class_attributes(self):
"""
Assert correct class attributes.
"""
self.assertEqual(models.Package.TYPE, constants.PACKAGE_TYPE_ID)
self.assertEqual(
models.Package._ATTRS, ('name', 'version', 'summary', 'home_page', 'author',
'author_email', 'license', 'description', 'platform',
'_filename', '_checksum', '_checksum_type'))
@mock.patch('pulp_python.plugins.models.Package._checksum', return_value='sum')
@mock.patch('pulp_python.plugins.models.Package._compression_type', return_value='.gz')
@mock.patch('pulp_python.plugins.models.tarfile.open')
def test_from_archive_closely_named_metadata(self, tarfile_open, _compression_type, _checksum):
"""
Test from_archive() with files named very similarly to PKG-INFO to test the regex. This also
coincidentally tests behavior when the archive is missing metadata.
"""
tarfile_open.return_value = mock.MagicMock(spec=tarfile.TarFile)
class TarInfo(object):
"""
This class fakes being a TarInfo. It just needs a name.
"""
def __init__(self, name):
self.name = name
members = [TarInfo(name) for name in ['aPKG-INFO', 'PKG-INFO.txt', '/path/to/PKG-INFO.txt'
'/path/to/aPKG-INFO']]
tarfile_open.return_value.getmembers.return_value = members
path = '/some/path.tar.gz'
try:
models.Package.from_archive(path)
self.fail('The above call should have raised a ValueError!')
except ValueError as e:
self.assertTrue(
_('The archive at %s does not contain a PKG-INFO file.') % path in str(e))
tarfile_open.assert_called_once_with(path)
_compression_type.assert_called_once_with(path)
tarfile_open.return_value.close.assert_called_once_with()
@mock.patch('pulp_python.plugins.models.Package._checksum', return_value='sum')
@mock.patch('pulp_python.plugins.models.Package._compression_type', return_value='.gz')
@mock.patch('pulp_python.plugins.models.tarfile.open')
def test_from_archive_empty_metadata(self, tarfile_open, _compression_type, _checksum):
"""
Test from_archive() when the PKG-INFO file is empty.
"""
tarfile_open.return_value = mock.MagicMock(spec=tarfile.TarFile)
class TarInfo(object):
"""
This class fakes being a TarInfo. It just needs a name.
"""
def __init__(self, name):
self.name = name
members = [TarInfo(name) for name in ['package-1.2.3', 'package-1.2.3/PKG-INFO']]
tarfile_open.return_value.getmembers.return_value = members
mock_manifest_file = mock.MagicMock(spec=file)
mock_manifest_file.read.return_value = ''
tarfile_open.return_value.extractfile.return_value = mock_manifest_file
path = '/some/path.tar.gz'
try:
models.Package.from_archive(path)
self.fail('The above call should have raised a ValueError!')
except ValueError as e:
self.assertTrue('The PKG-INFO file is missing required attributes.' in str(e))
tarfile_open.assert_called_once_with(path)
_compression_type.assert_called_once_with(path)
tarfile_open.return_value.extractfile.assert_called_once_with(members[-1])
tarfile_open.return_value.close.assert_called_once_with()
def test_from_archive_file_not_found(self):
"""
Test from_archive() when the given path does not exist.
"""
dne = '/some/path/that/doesnt/exist'
self.assertRaises(IOError, models.Package.from_archive, dne)
@mock.patch('pulp_python.plugins.models.Package._checksum', return_value='sum')
@mock.patch('pulp_python.plugins.models.Package._compression_type', return_value='.gz')
@mock.patch('pulp_python.plugins.models.tarfile.open')
def test_from_archive_good_metadata(self, tarfile_open, _compression_type, _checksum):
"""
Test from_archive() with good metadata, with PKG-INFO at the typical location as would be
done by setup.py sdist.
"""
tarfile_open.return_value = mock.MagicMock(spec=tarfile.TarFile)
class TarInfo(object):
"""
This class fakes being a TarInfo. It just needs a name.
"""
def __init__(self, name):
self.name = name
members = [
TarInfo(name) for name in ['nectar-1.3.1', 'nectar-1.3.1/nectar',
'nectar-1.3.1/nectar/config.py',
'nectar-1.3.1/nectar/downloaders',
'nectar-1.3.1/nectar/downloaders/threaded.py',
'nectar-1.3.1/nectar/downloaders/base.py',
'nectar-1.3.1/nectar/downloaders/__init__.py',
'nectar-1.3.1/nectar/downloaders/local.py',
'nectar-1.3.1/nectar/__init__.py',
'nectar-1.3.1/nectar/exceptions.py',
'nectar-1.3.1/nectar/listener.py',
'nectar-1.3.1/nectar/report.py',
'nectar-1.3.1/nectar/request.py', 'nectar-1.3.1/PKG-INFO']]
tarfile_open.return_value.getmembers.return_value = members
mock_manifest_file = mock.MagicMock(spec=file)
mock_manifest_file.read.return_value = GOOD_MANIFEST
tarfile_open.return_value.extractfile.return_value = mock_manifest_file
path = '/some/path.tar.gz'
package = models.Package.from_archive(path)
self.assertEqual(package.name, 'nectar')
self.assertEqual(package.version, '1.3.1')
self.assertEqual(package.summary, 'Performance tuned network download client library')
self.assertEqual(package.home_page, 'https://github.com/pulp/nectar')
self.assertEqual(package.author, 'Pulp Team')
self.assertEqual(package.author_email, 'pulp-list@redhat.com')
self.assertEqual(package.license, 'GPLv2')
self.assertEqual(package.description, 'UNKNOWN')
self.assertEqual(package.platform, 'UNKNOWN')
self.assertEqual(package._filename, 'nectar-1.3.1.tar.gz')
self.assertEqual(package._checksum, 'sum')
self.assertEqual(package._checksum_type, 'sha512')
self.assertEqual(package._unit, None)
_checksum.assert_called_once_with(path)
tarfile_open.assert_called_once_with(path)
_compression_type.assert_called_once_with(path)
tarfile_open.return_value.extractfile.assert_called_once_with(members[-1])
tarfile_open.return_value.close.assert_called_once_with()
@mock.patch('pulp_python.plugins.models.Package._checksum', return_value='sum')
@mock.patch('pulp_python.plugins.models.Package._compression_type', return_value='.gz')
@mock.patch('pulp_python.plugins.models.tarfile.open')
def test_from_archive_metadata_at_absolute_root(self, tarfile_open, _compression_type,
_checksum):
"""
Test from_archive() with good metadata when the PKG-INFO file is at /.
"""
tarfile_open.return_value = mock.MagicMock(spec=tarfile.TarFile)
class TarInfo(object):
"""
This class fakes being a TarInfo. It just needs a name.
"""
def __init__(self, name):
self.name = name
members = [
TarInfo(name) for name in ['/PKG-INFO', 'nectar-1.3.1', 'nectar-1.3.1/nectar',
'nectar-1.3.1/nectar/config.py',
'nectar-1.3.1/nectar/downloaders',
'nectar-1.3.1/nectar/downloaders/threaded.py',
'nectar-1.3.1/nectar/downloaders/base.py',
'nectar-1.3.1/nectar/downloaders/__init__.py',
'nectar-1.3.1/nectar/downloaders/local.py',
'nectar-1.3.1/nectar/__init__.py',
'nectar-1.3.1/nectar/exceptions.py',
'nectar-1.3.1/nectar/listener.py',
'nectar-1.3.1/nectar/report.py',
'nectar-1.3.1/nectar/request.py']]
tarfile_open.return_value.getmembers.return_value = members
mock_manifest_file = mock.MagicMock(spec=file)
mock_manifest_file.read.return_value = GOOD_MANIFEST
tarfile_open.return_value.extractfile.return_value = mock_manifest_file
path = '/some/path.tar.gz'
package = models.Package.from_archive(path)
self.assertEqual(package.name, 'nectar')
self.assertEqual(package.version, '1.3.1')
self.assertEqual(package.summary, 'Performance tuned network download client library')
self.assertEqual(package.home_page, 'https://github.com/pulp/nectar')
self.assertEqual(package.author, 'Pulp Team')
self.assertEqual(package.author_email, 'pulp-list@redhat.com')
self.assertEqual(package.license, 'GPLv2')
self.assertEqual(package.description, 'UNKNOWN')
self.assertEqual(package.platform, 'UNKNOWN')
self.assertEqual(package._filename, 'nectar-1.3.1.tar.gz')
self.assertEqual(package._checksum, 'sum')
self.assertEqual(package._checksum_type, 'sha512')
self.assertEqual(package._unit, None)
_checksum.assert_called_once_with(path)
tarfile_open.assert_called_once_with(path)
_compression_type.assert_called_once_with(path)
tarfile_open.return_value.extractfile.assert_called_once_with(members[0])
tarfile_open.return_value.close.assert_called_once_with()
@mock.patch('pulp_python.plugins.models.Package._checksum', return_value='sum')
@mock.patch('pulp_python.plugins.models.Package._compression_type', return_value='.gz')
@mock.patch('pulp_python.plugins.models.tarfile.open')
def test_from_archive_metadata_at_root(self, tarfile_open, _compression_type, _checksum):
"""
Test from_archive() when the PKG-INFO file is at the root of the archive.
"""
tarfile_open.return_value = mock.MagicMock(spec=tarfile.TarFile)
class TarInfo(object):
"""
This class fakes being a TarInfo. It just needs a name.
"""
def __init__(self, name):
self.name = name
members = [
TarInfo(name) for name in ['nectar-1.3.1', 'nectar-1.3.1/nectar',
'nectar-1.3.1/nectar/config.py',
'nectar-1.3.1/nectar/downloaders',
'nectar-1.3.1/nectar/downloaders/threaded.py',
'nectar-1.3.1/nectar/downloaders/base.py',
'nectar-1.3.1/nectar/downloaders/__init__.py',
'nectar-1.3.1/nectar/downloaders/local.py',
'nectar-1.3.1/nectar/__init__.py',
'nectar-1.3.1/nectar/exceptions.py',
'nectar-1.3.1/nectar/listener.py',
'nectar-1.3.1/nectar/report.py',
'nectar-1.3.1/nectar/request.py', 'PKG-INFO']]
tarfile_open.return_value.getmembers.return_value = members
mock_manifest_file = mock.MagicMock(spec=file)
mock_manifest_file.read.return_value = GOOD_MANIFEST
tarfile_open.return_value.extractfile.return_value = mock_manifest_file
path = '/some/path.tar.gz'
package = models.Package.from_archive(path)
self.assertEqual(package.name, 'nectar')
self.assertEqual(package.version, '1.3.1')
self.assertEqual(package.summary, 'Performance tuned network download client library')
self.assertEqual(package.home_page, 'https://github.com/pulp/nectar')
self.assertEqual(package.author, 'Pulp Team')
self.assertEqual(package.author_email, 'pulp-list@redhat.com')
self.assertEqual(package.license, 'GPLv2')
self.assertEqual(package.description, 'UNKNOWN')
self.assertEqual(package.platform, 'UNKNOWN')
self.assertEqual(package._filename, 'nectar-1.3.1.tar.gz')
self.assertEqual(package._checksum, 'sum')
self.assertEqual(package._checksum_type, 'sha512')
self.assertEqual(package._unit, None)
_checksum.assert_called_once_with(path)
tarfile_open.assert_called_once_with(path)
_compression_type.assert_called_once_with(path)
tarfile_open.return_value.extractfile.assert_called_once_with(members[-1])
tarfile_open.return_value.close.assert_called_once_with()
@mock.patch('pulp_python.plugins.models.Package._checksum', return_value='sum')
@mock.patch('pulp_python.plugins.models.Package._compression_type', return_value='.gz')
@mock.patch('pulp_python.plugins.models.tarfile.open')
def test_from_archive_missing_required_metadata(self, tarfile_open, _compression_type,
_checksum):
"""
Test from_archive() when the PKG-INFO file is missing required fields.
"""
tarfile_open.return_value = mock.MagicMock(spec=tarfile.TarFile)
class TarInfo(object):
"""
This class fakes being a TarInfo. It just needs a name.
"""
def __init__(self, name):
self.name = name
members = [
TarInfo(name) for name in ['nectar-1.3.1', 'nectar-1.3.1/nectar',
'nectar-1.3.1/nectar/config.py',
'nectar-1.3.1/nectar/downloaders',
'nectar-1.3.1/nectar/downloaders/threaded.py',
'nectar-1.3.1/nectar/downloaders/base.py',
'nectar-1.3.1/nectar/downloaders/__init__.py',
'nectar-1.3.1/nectar/downloaders/local.py',
'nectar-1.3.1/nectar/__init__.py',
'nectar-1.3.1/nectar/exceptions.py',
'nectar-1.3.1/nectar/listener.py',
'nectar-1.3.1/nectar/report.py',
'nectar-1.3.1/nectar/request.py', 'nectar-1.3.1/PKG-INFO']]
tarfile_open.return_value.getmembers.return_value = members
mock_manifest_file = mock.MagicMock(spec=file)
mock_manifest_file.read.return_value = BAD_MANIFEST
tarfile_open.return_value.extractfile.return_value = mock_manifest_file
path = '/some/path.tar.gz'
try:
models.Package.from_archive(path)
self.fail('The above call should have raised a ValueError!')
except ValueError as e:
self.assertTrue(_('The PKG-INFO file is missing required attributes.') in str(e))
tarfile_open.assert_called_once_with(path)
_compression_type.assert_called_once_with(path)
tarfile_open.return_value.extractfile.assert_called_once_with(members[-1])
tarfile_open.return_value.close.assert_called_once_with()
def test_init_unit(self):
"""
Test the init_unit() method.
"""
pulp_unit = mock.MagicMock()
conduit = mock.MagicMock()
conduit.init_unit.return_value = pulp_unit
name = 'nectar'
version = '1.3.1'
summary = 'a summary'
home_page = 'http://github.com/pulp/nectar'
author = 'The Pulp Team'
author_email = 'pulp-list@redhat.com'
license = 'GPLv2'
description = 'a description'
platform = 'Linux'
_filename = 'nectar-1.3.1.tar.gz'
_checksum = 'some_sum'
_checksum_type = 'some-type'
pp = models.Package(name, version, summary, home_page, author, author_email, license,
description, platform, _filename, _checksum, _checksum_type)
pp.init_unit(conduit)
conduit.init_unit.assert_called_once_with(
models.Package.TYPE, {'name': name, 'version': version},
{'summary': summary, 'home_page': home_page, 'author': author,
'author_email': author_email, 'license': license, 'description': description,
'platform': platform, '_filename': _filename, '_checksum': _checksum,
'_checksum_type': _checksum_type},
_filename)
self.assertEqual(pp._unit, pulp_unit)
def test_save_unit(self):
"""
Test the save_unit() method.
"""
conduit = mock.MagicMock()
pp = models.Package(
'name', 'version', 'summary', 'home_page', 'author', 'author_email', 'license',
'description', 'platform', '_filename', '_checksum', '_checksum_type')
pp._unit = mock.MagicMock()
pp.save_unit(conduit)
conduit.save_unit.assert_called_once_with(pp._unit)
def test_storage_path(self):
"""
Test the storage_path property.
"""
pp = models.Package(
'name', 'version', 'summary', 'home_page', 'author', 'author_email', 'license',
'description', 'platform', '_filename', '_checksum', '_checksum_type')
pp._unit = mock.MagicMock()
path = '/some/path.tar.gz'
pp._unit.storage_path.return_value = path
sp = pp.storage_path()
self.assertEqual(sp, path)
@mock.patch('__builtin__.open')
def test__checksum_default_sum(self, mock_open):
"""
Assert that the checksum method works correctly with the default sum.
"""
file_chunks = ['Hello', ' World!', '']
def mock_read(size):
"""
A fake file read() that will return "Hello", " World!" and "" when called three times.
"""
self.assertEqual(size, 32 * 1024 * 1024)
return file_chunks.pop(0)
mock_open.return_value.__enter__.return_value.read.side_effect = mock_read
path = '/some/path'
checksum = models.Package._checksum(path)
mock_open.assert_called_once_with(path)
hasher = hashlib.sha512()
hasher.update('Hello World!')
self.assertEqual(checksum, hasher.hexdigest())
@mock.patch('__builtin__.open')
def test__checksum_md5(self, mock_open):
"""
Assert that the checksum method works correctly with md5.
"""
file_chunks = ['Hello', ' World!', '']
def mock_read(size):
"""
A fake file read() that will return "Hello", " World!" and "" when called three times.
"""
self.assertEqual(size, 32 * 1024 * 1024)
return file_chunks.pop(0)
mock_open.return_value.__enter__.return_value.read.side_effect = mock_read
path = '/some/path'
checksum = models.Package._checksum(path, 'md5')
mock_open.assert_called_once_with(path)
hasher = hashlib.md5()
hasher.update('Hello World!')
self.assertEqual(checksum, hasher.hexdigest())
@mock.patch('pulp_python.plugins.models.open', create=True)
def test__compression_type_empty_file(self, mock_open):
"""
Test that _compression_type() correctly handles empty files.
"""
mock_file = mock.MagicMock(spec=file)
mock_file.__enter__.return_value.read.return_value = ''
mock_open.return_value = mock_file
path = '/some/path/to/hello_world'
compression_type = models.Package._compression_type(path)
# Since "" isn't a magic string, the empty string should have been returned.
self.assertEqual(compression_type, '')
mock_open.assert_called_once_with(path)
@mock.patch('pulp_python.plugins.models.open', create=True)
def test__compression_type_handle_other(self, mock_open):
"""
Test that _compression_type() correctly handles other files.
"""
mock_file = mock.MagicMock(spec=file)
mock_file.__enter__.return_value.read.return_value = 'Hello World!'
mock_open.return_value = mock_file
path = '/some/path/to/hello_world'
compression_type = models.Package._compression_type(path)
# Since "Hello World!" isn't a magic string, the empty string should have been returned.
self.assertEqual(compression_type, '')
mock_open.assert_called_once_with(path)
@mock.patch('pulp_python.plugins.models.open', create=True)
def test__compression_type_match_bz2(self, mock_open):
"""
Test that _compression_type() correctly matches bz2 files.
"""
mock_file = mock.MagicMock(spec=file)
mock_file.__enter__.return_value.read.return_value = '\x42\x5a\x68Hello World!'
mock_open.return_value = mock_file
path = '/some/path/to/hello_world.bz2'
compression_type = models.Package._compression_type(path)
self.assertEqual(compression_type, '.bz2')
mock_open.assert_called_once_with(path)
@mock.patch('pulp_python.plugins.models.open', create=True)
def test__compression_type_match_gz(self, mock_open):
"""
Test that _compression_type() correctly matches gz files.
"""
mock_file = mock.MagicMock(spec=file)
mock_file.__enter__.return_value.read.return_value = '\x1f\x8b\x08Hello World!'
mock_open.return_value = mock_file
path = '/some/path/to/hello_world.gz'
compression_type = models.Package._compression_type(path)
self.assertEqual(compression_type, '.gz')
mock_open.assert_called_once_with(path)
@mock.patch('pulp_python.plugins.models.open', create=True)
def test__compression_type_match_zip(self, mock_open):
"""
Test that _compression_type() correctly matches zip files.
"""
mock_file = mock.MagicMock(spec=file)
mock_file.__enter__.return_value.read.return_value = '\x50\x4b\x03\x04Hello World!'
mock_open.return_value = mock_file
path = '/some/path/to/hello_world.zip'
compression_type = models.Package._compression_type(path)
self.assertEqual(compression_type, '.zip')
mock_open.assert_called_once_with(path)
def test__metadata_label(self):
"""
Test various manipulations of possible metadata attributes with the _metadata_label()
method.
"""
expected_value_map = {'name': 'Name', 'author_email': 'Author-email', 'a': 'A'}
for key, value in expected_value_map.items():
self.assertEqual(models.Package._metadata_label(key), value)
def test___init__(self):
"""
Assert correct behavior with the __init__() method.
"""
name = 'nectar'
version = '1.3.1'
summary = 'a summary'
home_page = 'http://github.com/pulp/nectar'
author = 'The Pulp Team'
author_email = 'pulp-list@redhat.com'
license = 'GPLv2'
description = 'a description'
platform = 'Linux'
_filename = 'nectar-1.3.1.tar.gz'
_checksum = 'abcde'
_checksum_type = 'some_type'
pp = models.Package(name, version, summary, home_page, author, author_email, license,
description, platform, _filename, _checksum, _checksum_type)
self.assertEqual(pp.name, name)
self.assertEqual(pp.version, version)
self.assertEqual(pp.summary, summary)
self.assertEqual(pp.home_page, home_page)
self.assertEqual(pp.author, author)
self.assertEqual(pp.author_email, author_email)
self.assertEqual(pp.license, license)
self.assertEqual(pp.description, description)
self.assertEqual(pp.platform, platform)
self.assertEqual(pp._filename, _filename)
self.assertEqual(pp._checksum, _checksum)
self.assertEqual(pp._checksum_type, _checksum_type)
self.assertEqual(pp._unit, None)
def test___repr__(self):
"""
Assert correct behavior with the __repr__() method.
"""
name = 'nectar'
version = '1.3.1'
summary = 'a summary'
home_page = 'http://github.com/pulp/nectar'
author = 'The Pulp Team'
author_email = 'pulp-list@redhat.com'
license = 'GPLv2'
description = 'a description'
platform = 'Linux'
_filename = 'nectar-1.3.1.tar.gz'
_checksum = 'abcde'
_checksum_type = 'some_type'
pp = models.Package(name, version, summary, home_page, author, author_email, license,
description, platform, _filename, _checksum, _checksum_type)
self.assertEqual(repr(pp), 'Python Package: nectar-1.3.1')