Merge lp:~james-w/vostok/add-sourcepackagerelease-model into lp:vostok

Proposed by James Westby
Status: Rejected
Rejected by: James Westby
Proposed branch: lp:~james-w/vostok/add-sourcepackagerelease-model
Merge into: lp:vostok
Prerequisite: lp:~james-w/vostok/add-series-model
Diff against target: 117 lines (+73/-0)
3 files modified
vostok/archives/factory.py (+14/-0)
vostok/archives/models.py (+25/-0)
vostok/archives/tests.py (+34/-0)
To merge this branch: bzr merge lp:~james-w/vostok/add-sourcepackagerelease-model
Reviewer Review Type Date Requested Status
Registry Administrators Pending
Review via email: mp+26750@code.launchpad.net

Commit message

Add a SourcePackageRelease model class.

Description of the change

Then the bare minimum of a SourcePackageRelease class.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

58 + # TODO: uploader, signer

This makes me go, "hm, yes, how are we going to represent people?"

We should certainly validate the format of the package name and version number.

Is there some way to get django to generate a schema that has a default of now for date_uploaded?

+# XXX: how much should we .save() the models?

This is a fun issue too: if you're not careful you can create objects that violate database constraints because they are never flushed to the database. OTOH, you don't want to hit the database because that slows the tests down. I don't think there's a happy answer here, although maybe it's less of an issue in vostok compared Launchpad because we're using an automatically generated schema with less exotic constraints.

The code looks inoffensive enough, it just prompts some more questions :-)

Revision history for this message
James Westby (james-w) wrote :

On Fri, 04 Jun 2010 04:57:22 -0000, Michael Hudson <email address hidden> wrote:
> 58 + # TODO: uploader, signer
>
> This makes me go, "hm, yes, how are we going to represent people?"

Django has a built-in, apparently extensible, Person model. It has the
nasty separation between first/last name, but perhaps we could ignore that.

> We should certainly validate the format of the package name and version number.

Yes, unfortunately "validators" which are the new way to do this are
only in Django 1.2, which isn't in lucid. I'll look around for addons or
similar that were used before to do something similar.

> Is there some way to get django to generate a schema that has a default of now for date_uploaded?

Yes, it's an option when creating the field. It's not a default though,
it's apparently not something you can set if you use the option, so I
went with the easier way to test.

> +# XXX: how much should we .save() the models?
>
> This is a fun issue too: if you're not careful you can create objects that violate database constraints because they are never flushed to the database. OTOH, you don't want to hit the database because that slows the tests down. I don't think there's a happy answer here, although maybe it's less of an issue in vostok compared Launchpad because we're using an automatically generated schema with less exotic constraints.

Yes, plus we can currently test with an in-memory sqlite. Doing .save()
is cheap it appears, as a commit is never done. As noted earlier though,
it doesn't look like django uses database constraints for many things,
such as max length.

I'm happy to have the factory save and rewrite the tests that check for
IntegrityErrors to skip the factory.

We could even make it configurable on the factory so that we can
experiment easily later with turning it off.

> The code looks inoffensive enough, it just prompts some more questions :-)

Yep, pretty much what I was looking for from the review :-)

Thanks,

James

28. By James Westby

Merge add-series-model in to add-sourcepackagerelease-model.

29. By James Westby

Merged add-series-model into add-sourcepackagerelease-model.

30. By James Westby

Have the factory save SourcePackageReleases as they are created.

31. By James Westby

Add __unicode__ to SourcePackageRelease.

Unmerged revisions

31. By James Westby

Add __unicode__ to SourcePackageRelease.

30. By James Westby

Have the factory save SourcePackageReleases as they are created.

29. By James Westby

Merged add-series-model into add-sourcepackagerelease-model.

28. By James Westby

Merge add-series-model in to add-sourcepackagerelease-model.

27. By James Westby

Add date_uploaded.

26. By James Westby

Add version to SourcePackageRelease.

25. By James Westby

Add source_name to SourcePackageRelease.

24. By James Westby

Merged add-series-model into add-sourcepackagerelease-model.

23. By James Westby

Add SourcePackageRelease skeleton.

22. By James Westby

Add status to Series.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'vostok/archives/factory.py'
2--- vostok/archives/factory.py 2010-06-04 23:01:22 +0000
3+++ vostok/archives/factory.py 2010-06-04 23:01:22 +0000
4@@ -1,6 +1,8 @@
5 """Factory for creating model objects with defaults."""
6
7
8+import datetime
9+
10 from vostok.archives import models
11
12
13@@ -43,3 +45,15 @@
14 return models.Series.objects.create(
15 distribution=distribution, short_name=short_name,
16 display_name=display_name, status=status)
17+
18+ def make_sourcepackagerelease(self, source_name=None, version=None,
19+ date_uploaded=None):
20+ if source_name is None:
21+ source_name = self.make_unique_string("sourcepackage")
22+ if version is None:
23+ version = "1"
24+ if date_uploaded is None:
25+ date_uploaded = datetime.datetime.utcnow()
26+ return models.SourcePackageRelease.objects.create(
27+ source_name=source_name, version=version,
28+ date_uploaded=date_uploaded)
29
30=== modified file 'vostok/archives/models.py'
31--- vostok/archives/models.py 2010-06-04 23:01:22 +0000
32+++ vostok/archives/models.py 2010-06-04 23:01:22 +0000
33@@ -52,3 +52,28 @@
34
35 def __unicode__(self):
36 return u"%s %s" % (self.distribution, self.short_name)
37+
38+
39+class SourcePackageRelease(models.Model):
40+ """A particular version of a source package as seen by the software.
41+
42+ These are not unique wrt name and version, nor do they correspond to
43+ a particular series, and they may not even be published.
44+
45+ They are instead the model containing the files for a particular upload
46+ which we can then link to other models as needed, and finally publish
47+ somewhere (possibly multiple places) if needed.
48+
49+ :ivar source_name: the name of the source package.
50+ :ivar version: the version of the source package.
51+ """
52+
53+ # TODO: does SlugField match package name requirements?
54+ source_name = models.SlugField(blank=False)
55+ # TODO: make version match required characters in a version number
56+ version = models.CharField(max_length=50, blank=False)
57+ date_uploaded = models.DateTimeField()
58+ # TODO: uploader, signer
59+
60+ def __unicode__(self):
61+ return u"%s %s" % (self.source_name, self.version)
62
63=== modified file 'vostok/archives/tests.py'
64--- vostok/archives/tests.py 2010-06-04 23:01:22 +0000
65+++ vostok/archives/tests.py 2010-06-04 23:01:22 +0000
66@@ -2,6 +2,9 @@
67 Tests for the models.
68 """
69
70+
71+import datetime
72+
73 from django.db import IntegrityError
74
75 from vostok.archives import models
76@@ -32,6 +35,9 @@
77 self.assertNotEqual(string2, string3)
78
79
80+# XXX: how much should we .save() the models?
81+
82+
83 class TestDistribution(TestCaseWithFactory):
84 """Tests for models.Distribution."""
85
86@@ -107,3 +113,31 @@
87 def test_has_status(self):
88 series = self.factory.make_series(status='Active')
89 self.assertEqual('Active', series.status)
90+
91+
92+class TestSourcePackageRelease(TestCaseWithFactory):
93+ """Tests for models.SourcePackageRelease."""
94+
95+ def test_create(self):
96+ sourcepackagerelease = models.SourcePackageRelease()
97+
98+ def test_has_source_package_name(self):
99+ sourcepackagerelease = self.factory.make_sourcepackagerelease(
100+ source_name="bzr")
101+ self.assertEquals("bzr", sourcepackagerelease.source_name)
102+
103+ def test_has_version(self):
104+ sourcepackagerelease = self.factory.make_sourcepackagerelease(
105+ version="2.1-1")
106+ self.assertEquals("2.1-1", sourcepackagerelease.version)
107+
108+ def test_unicode(self):
109+ sourcepackagerelease = self.factory.make_sourcepackagerelease(
110+ source_name="bzr", version="2.1-1")
111+ self.assertEquals(u"bzr 2.1-1", unicode(sourcepackagerelease))
112+
113+ def test_has_date_uploaded(self):
114+ now = datetime.datetime.utcnow()
115+ sourcepackagerelease = self.factory.make_sourcepackagerelease(
116+ date_uploaded=now)
117+ self.assertEquals(now, sourcepackagerelease.date_uploaded)

Subscribers

People subscribed via source and target branches

to all changes: