/
test_content.py
45 lines (38 loc) · 1.7 KB
/
test_content.py
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
import os
import tempfile
from django.core.files.storage import default_storage as storage
from django.test import TestCase
from pulpcore.plugin.models import Artifact, Content, ContentArtifact
class ContentCRUDTestCase(TestCase):
artifact01_path = os.path.join(tempfile.gettempdir(), 'artifact01-tmp')
artifact02_path = os.path.join(tempfile.gettempdir(), 'artifact02-tmp')
def setUp(self):
with open(self.artifact01_path, 'w') as f:
f.write('Temp Artifact File 01')
with open(self.artifact02_path, 'w') as f:
f.write('Temp Artifact File 02')
self.artifact01 = Artifact.init_and_validate(self.artifact01_path)
self.artifact01.save()
self.artifact02 = Artifact.init_and_validate(self.artifact02_path)
self.artifact02.save()
def test_create_and_read_content(self):
content = Content.objects.create()
content.save()
artifact_file = storage.open(self.artifact01.file.name)
content_artifact = ContentArtifact.objects.create(
artifact=self.artifact01,
content=content,
relative_path=artifact_file.name)
content_artifact.save()
self.assertTrue(
Content.objects.filter(pk=content.pk).exists()
and ContentArtifact.objects.get(
pk=content_artifact.pk
).content.pk == Content.objects.get(pk=content.pk).pk
)
def test_remove_content(self):
content = Content.objects.create()
content.save()
# Assumes creation is tested by test_create_and_read_content function
Content.objects.filter(pk=content.pk).delete()
self.assertFalse(Content.objects.filter(pk=content.pk).exists())