Skip to content

Commit

Permalink
sparkle api
Browse files Browse the repository at this point in the history
  • Loading branch information
yurtaev committed Oct 14, 2014
1 parent 35fb75b commit 5c572db
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 2 deletions.
22 changes: 22 additions & 0 deletions omaha_server/omaha/templates/sparkle/appcast.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% load absolute %}<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>{{ app_name }}</title>
<link>{% absolute 'sparkle_appcast' app_name channel %}</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
{% for version in object_list %}
<item>
<title>{{ version }}</title>
<description><![CDATA[
{% if version.release_notes %}{{ version.release_notes }}}{% endif %}
]]>
</description>
<pubDate>{{ version.created|date:"r" }}</pubDate>
<enclosure url="{{ version.file.url }}"
sparkle:version="{{ version.version }}"
length="{{ version.file.size }}" type="application/octet-stream"/>
</item>
{% endfor %}
</channel>
</rss>
23 changes: 23 additions & 0 deletions omaha_server/omaha/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,26 @@
<data name="untrusted" status="ok"/>
</app>
</response>"""

response_sparkle = """<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>chrome</title>
<link>http://example.com/sparkle/chrome/stable/appcast.xml</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>chrome 13.0.782.112</title>
<description><![CDATA[
]]>
</description>
<pubDate>Tue, 14 Oct 2014 08:28:05 +0000</pubDate>
<enclosure url="http://cache.pack.google.com/edgedl/chrome/install/782.112/chrome.dmg"
sparkle:version="13.0.782.112"
length="23963192" type="application/octet-stream"/>
</item>
</channel>
</rss>"""
30 changes: 30 additions & 0 deletions omaha_server/omaha/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,33 @@ def test_event(self):
self.assertXmlDocument(response.content)
self.assertXmlEquivalentOutputs(response.content,
fixtures.response_event)


class SparkleViewTest(TestCase, XmlTestMixin):
def setUp(self):
self.client = Client()

@freeze_time('2014-10-14 08:28:05')
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
@patch('omaha.models.version_upload_to', lambda o, f: f)
def test_sparkle(self):
app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
platform = PlatformFactory.create(name='mac')
channel = ChannelFactory.create(name='stable')
obj = VersionFactory.create(
app=app,
platform=platform,
channel=channel,
version='13.0.782.112',
file=SimpleUploadedFile('./chrome.dmg', 'b' * 23963192))
obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo='
obj.save()

response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)),
HTTP_HOST='example.com')

self.assertEqual(response.status_code, 200)

self.assertXmlDocument(response.content)
self.assertXmlEquivalentOutputs(response.content,
fixtures.response_sparkle)
26 changes: 25 additions & 1 deletion omaha_server/omaha/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# coding: utf8

from django.views.generic import View
from django.views.generic import View, ListView
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse

from builder import build_response
from models import Version


class UpdateView(View):
Expand All @@ -16,3 +17,26 @@ def dispatch(self, *args, **kwargs):

def post(self, request):
return HttpResponse(build_response(request.body), content_type="text/xml; charset=utf-8")


class SparkleView(ListView):
http_method_names = ['get']
queryset = Version.objects.all()
template_name = 'sparkle/appcast.xml'

def get_queryset(self):
qs = super(SparkleView, self).get_queryset()
return qs.filter(platform__name='mac',
channel__name=self.kwargs.get('channel'),
app__name=self.kwargs.get('app_name'))

def get_context_data(self, **kwargs):
context = super(SparkleView, self).get_context_data(**kwargs)
context['app_name'] = self.kwargs.get('app_name')
context['channel'] = self.kwargs.get('channel')
return context

def render_to_response(self, context, **response_kwargs):
response = super(SparkleView, self).render_to_response(context, **response_kwargs)
response['Content-Type'] = 'text/xml; charset=utf-8'
return response
2 changes: 2 additions & 0 deletions omaha_server/omaha_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
'absolute.context_processors.absolute',
)

SUIT_CONFIG = {
Expand Down Expand Up @@ -53,6 +54,7 @@
'storages',
'django_extensions',
'versionfield',
'absolute',

'omaha',
)
Expand Down
4 changes: 3 additions & 1 deletion omaha_server/omaha_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from django.conf import settings
from django.contrib import admin

from omaha.views import UpdateView
from omaha.views import UpdateView, SparkleView


urlpatterns = patterns('',
url(r'^service/update2$', UpdateView.as_view(), name='update'),
url(r'^sparkle/(?P<app_name>[\w-]+)/(?P<channel>[\w-]+)/appcast.xml$',
SparkleView.as_view(), name='sparkle_appcast'),
url(r'^admin/', include(admin.site.urls)),
)

Expand Down
1 change: 1 addition & 0 deletions omaha_server/requirements-eb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ django-suit==0.2.11
jsonfield==1.0.0
boto==2.33.0
django-storages==1.1.8
django-absolute==0.3
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ django-suit==0.2.11
jsonfield==1.0.0
boto==2.33.0
django-storages==1.1.8
django-absolute==0.3

0 comments on commit 5c572db

Please sign in to comment.