def test_post_video_with_urls(self): """Test that authenticated user can create videos.""" cat = category(save=True) person = speaker(save=True) tag1 = tag(save=True) tag2 = tag(save=True) lang = language(save=True) data = {'title': 'Creating delicious APIs for Django apps since 2010.', 'category': '/api/v1/category/%d/' % cat.pk, 'speakers': ['/api/v1/speaker/%d/' % person.pk], 'tags': ['/api/v1/tag/%d/' % tag1.pk, '/api/v1/tag/%d/' % tag2.pk], 'language': lang.name, 'state': Video.STATE_LIVE} resp = self.auth_post('/api/v1/video/', json.dumps(data), content_type='application/json') eq_(resp.status_code, 201) # Get the created video resp = self.auth_get(resp['Location'], {'format': 'json'}) eq_(resp.status_code, 200) eq_(json.loads(resp.content)['title'], data['title']) # Verify the data vid = Video.objects.get(title=data['title']) eq_(vid.title, data['title']) eq_(list(vid.speakers.values_list('name', flat=True)), [person.name]) eq_(sorted(vid.tags.values_list('tag', flat=True)), sorted([tag1.tag, tag2.tag])) eq_(vid.language.name, lang.name)
def test_post_video_with_urls(self): """Test that authenticated user can create videos.""" cat = category(save=True) person = speaker(save=True) tag1 = tag(save=True) tag2 = tag(save=True) lang = language(save=True) data = { "title": "Creating delicious APIs for Django apps since 2010.", "category": "/api/v1/category/%d/" % cat.pk, "speakers": ["/api/v1/speaker/%d/" % person.pk], "tags": ["/api/v1/tag/%d/" % tag1.pk, "/api/v1/tag/%d/" % tag2.pk], "language": lang.name, "state": Video.STATE_LIVE, } resp = self.auth_post("/api/v1/video/", json.dumps(data), content_type="application/json") eq_(resp.status_code, 201) # Get the created video resp = self.auth_get(resp["Location"], {"format": "json"}) eq_(resp.status_code, 200) eq_(json.loads(resp.content)["title"], data["title"]) # Verify the data vid = Video.objects.get(title=data["title"]) eq_(vid.title, data["title"]) eq_(list(vid.speakers.values_list("name", flat=True)), [person.name]) eq_(sorted(vid.tags.values_list("tag", flat=True)), sorted([tag1.tag, tag2.tag])) eq_(vid.language.name, lang.name)
def test_videos_by_tag(self): tag1 = tag(tag="boat", save=True) v1 = video(state=Video.STATE_LIVE, title=u"Foo1", save=True) v1.tags = [tag1] v1.save() v2 = video(state=Video.STATE_LIVE, title=u"Foo2", save=True) v2.tags = [tag1] v2.save() video(state=Video.STATE_LIVE, title=u"Foo3", save=True) resp = self.auth_get("/api/v2/video/?tag=boat", content_type="application/json") data = json.loads(resp.content) eq_(len(data["results"]), 2)
def test_videos_by_tag(self): tag1 = tag(tag='boat', save=True) v1 = video(state=Video.STATE_LIVE, title=u'Foo1', save=True) v1.tags = [tag1] v1.save() v2 = video(state=Video.STATE_LIVE, title=u'Foo2', save=True) v2.tags = [tag1] v2.save() video(state=Video.STATE_LIVE, title=u'Foo3', save=True) resp = self.auth_get('/api/v2/video/?tag=boat', content_type='application/json') data = json.loads(smart_text(resp.content)) eq_(len(data['results']), 2)
def test_videos_by_tag(self): tag1 = tag(tag='boat', save=True) v1 = video(state=Video.STATE_LIVE, title=u'Foo1', save=True) v1.tags = [tag1] v1.save() v2 = video(state=Video.STATE_LIVE, title=u'Foo2', save=True) v2.tags = [tag1] v2.save() video(state=Video.STATE_LIVE, title=u'Foo3', save=True) resp = self.auth_get('/api/v1/video/?tag=boat', content_type='application/json') data = json.loads(resp.content) eq_(len(data['objects']), 2)
def test_post_with_tag_url(self): cat = category(save=True) tag1 = tag(save=True) data = {"title": "test1", "category": "/api/v1/category/%d/" % cat.pk, "state": Video.STATE_DRAFT} # Post video using /api/v1/tag/xx. data.update({"tags": ["/api/v1/tag/%d/" % tag1.pk]}) resp = self.auth_post("/api/v1/video/", json.dumps(data), content_type="application/json") eq_(resp.status_code, 201) # Get the created video resp = self.auth_get(resp["Location"], {"format": "json"}) # Verify the tag vid = Video.objects.get(title=data["title"]) eq_(vid.tags.values_list("tag", flat=True)[0], tag1.tag)
def test_get_video_data(self): cat = category(title=u"Foo Title", save=True) vid = video(title=u"Foo Bar", category=cat, state=Video.STATE_LIVE, save=True) t = tag(tag=u"tag", save=True) vid.tags = [t] s = speaker(name=u"Jim", save=True) vid.speakers = [s] resp = self.client.get("/api/v2/video/%d/" % vid.pk, {"format": "json"}) eq_(resp.status_code, 200) content = json.loads(resp.content) eq_(content["title"], vid.title) eq_(content["slug"], "foo-bar") # This should be the category title--not api url eq_(content["category"], cat.title) # This should be the tag--not api url eq_(content["tags"], [t.tag]) # This should be the speaker name--not api url eq_(content["speakers"], [s.name])
def test_get_video_data(self): cat = category(title=u'Foo Title', save=True) vid = video(title=u'Foo Bar', category=cat, state=Video.STATE_LIVE, save=True) t = tag(tag=u'tag', save=True) vid.tags = [t] s = speaker(name=u'Jim', save=True) vid.speakers = [s] resp = self.client.get('/api/v2/video/%d/' % vid.pk, {'format': 'json'}) eq_(resp.status_code, 200) content = json.loads(smart_text(resp.content)) eq_(content['title'], vid.title) eq_(content['slug'], 'foo-bar') # This should be the category title--not api url eq_(content['category'], cat.title) # This should be the tag--not api url eq_(content['tags'], [t.tag]) # This should be the speaker name--not api url eq_(content['speakers'], [s.name])
def test_get_video_data(self): cat = category(title=u'Foo Title', save=True) vid = video(title=u'Foo Bar', category=cat, state=Video.STATE_LIVE, save=True) t = tag(tag=u'tag', save=True) vid.tags = [t] s = speaker(name=u'Jim', save=True) vid.speakers = [s] resp = self.client.get('/api/v1/video/%d/' % vid.pk, {'format': 'json'}) eq_(resp.status_code, 200) content = json.loads(resp.content) eq_(content['title'], vid.title) eq_(content['slug'], 'foo-bar') # This should be the category title--not api url eq_(content['category'], cat.title) # This should be the tag--not api url eq_(content['tags'], [t.tag]) # This should be the speaker name--not api url eq_(content['speakers'], [s.name])
def generate_sampledata(options): conference = category_kind(name=u'Conference', save=True) pycon2011 = category(name=u'PyCon', title=u'Pycon 2011', slug=u'pycon-2011', description=u'PyCon 2011 in Atlanta, GA', kind=conference, url=u'http://us.pycon.org/2011/home/', save=True) pycon2012 = category(name=u'PyCon', title=u'Pycon 2012', slug=u'pycon-2012', description=u'PyCon 2011 in Santa Clara, CA', kind=conference, url=u'http://us.pycon.org/2012/', save=True) jm = speaker(name=u'Jessica McKellar', save=True) al = speaker(name=u'Asheesh Laroia', save=True) jkm = speaker(name=u'Jacob Kaplan-Moss', save=True) tag1 = tag(tag=u'documentation', save=True) tag2 = tag(tag=u'sphinx', save=True) v = video( state=Video.STATE_LIVE, category=pycon2011, title=u'Writing great documentation', summary=u'<p>Writing great documentation</p>' u'<p>Presented by Jacob Kaplan-Moss</p>', description=u'<p>This talk looks at tips, tools, and techniques you can' u'use to produce great technical documentation.</p>', copyright_text=u'Creative Commons Attribution-NonCommercial-ShareAlike 3.0', recorded=date(2011, 3, 11), updated=datetime(2011, 3, 14, 3, 47, 59), source_url=u'http://blip.tv/file/4881071', video_mp4_url=u'http://blip.tv/file/get/Pycon-PyCon2011WritingGreatDocumentation191.mp4', video_ogv_length=158578172, video_ogv_url=u'http://blip.tv/file/get/Pycon-PyCon2011WritingGreatDocumentation312.ogv', thumbnail_url=u'http://a.images.blip.tv/Pycon-PyCon2011WritingGreatDocumentation902.png', save=True) v.speakers.add(jkm) v.tags.add(tag1, tag2) v = video( state=Video.STATE_LIVE, category=pycon2012, title=u'Diversity in practice: How the Boston Python User Group grew to ' u'1700 people and over 15% women', summary=u""" <p>How do you bring more women into programming communities with long-term, measurable results? In this talk we'll analyze our successful effort, the Boston Python Workshop, which brought over 200 women into Boston's Python community this year.</p>""", recorded=date(2012, 3, 11), updated=datetime(2012, 3, 13, 16, 15, 17), source_url=u'https://www.youtube.com/watch?v=QrITN6GZDu4', embed=u''' <object width="425" height="344"> <param name="movie" value="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1"> <param name="allowFullScreen" value="true"> <param name="allowscriptaccess" value="always"> <embed src="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1" allowscriptaccess="always" height="344" width="425" allowfullscreen="true" type="application/x-shockwave-flash"></embed> </object>''', thumbnail_url=u'http://img.youtube.com/vi/QrITN6GZDu4/hqdefault.jpg', save=True) v.speakers.add(jm, al)
def generate_sampledata(options): pycon2011 = category(title=u'Pycon 2011', slug=u'pycon-2011', description=u'PyCon 2011 in Atlanta, GA', url=u'http://us.pycon.org/2011/home/', save=True) pycon2012 = category(title=u'Pycon 2012', slug=u'pycon-2012', description=u'PyCon 2011 in Santa Clara, CA', url=u'http://us.pycon.org/2012/', save=True) sp1 = speaker(name=u'Jessica McKellar', save=True) sp2 = speaker(name=u'Asheesh Laroia', save=True) sp3 = speaker(name=u'Jacob Kaplan-Moss', save=True) tag1 = tag(tag=u'documentation', save=True) tag2 = tag(tag=u'sphinx', save=True) v = video( state=Video.STATE_LIVE, category=pycon2011, title=u'Writing great documentation', summary=dedent("""\ Writing great documentation Presented by Jacob Kaplan-Moss """), description=dedent("""\ This talk looks at tips, tools, and techniques you can use to produce great technical documentation. """), copyright_text=u'CC-SA-NC 3.0', recorded=date(2011, 3, 11), updated=datetime(2011, 3, 14, 3, 47, 59), source_url=u'http://blip.tv/file/4881071', video_mp4_url=( u'http://05d2db1380b6504cc981-8cbed8cf7e3a131cd8f1c3e383d10041' u'.r93.cf2.rackcdn.com/pycon-us-2011/' u'403_writing-great-documentation.mp4'), thumbnail_url=(u'http://a.images.blip.tv/' u'Pycon-PyCon2011WritingGreatDocumentation902.png'), save=True) v.speakers.add(sp3) v.tags.add(tag1, tag2) v = video( state=Video.STATE_LIVE, category=pycon2012, title=dedent("""\ Diversity in practice: How the Boston Python User Group grew to 1700 people and over 15% women """), summary=dedent(u"""\ How do you bring more women into programming communities with long-term, measurable results? In this talk we'll analyze our successful effort, the Boston Python Workshop, which brought over 200 women into Boston's Python community this year. """), recorded=date(2012, 3, 11), updated=datetime(2012, 3, 13, 16, 15, 17), source_url=u'https://www.youtube.com/watch?v=QrITN6GZDu4', embed=dedent("""\ <object width="425" height="344"> <param name="movie" value="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1"> <param name="allowFullScreen" value="true"> <param name="allowscriptaccess" value="always"> <embed src="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1" allowscriptaccess="always" height="344" width="425" allowfullscreen="true" type="application/x-shockwave-flash"></embed> </object> """), thumbnail_url=u'http://img.youtube.com/vi/QrITN6GZDu4/hqdefault.jpg', save=True) v.speakers.add(sp1, sp2) v = video(state=Video.STATE_DRAFT, category=pycon2012, title=u'Draft video', summary=u'This is a draft', recorded=date(2012, 3, 11), updated=datetime(2012, 3, 13, 16, 15, 17), save=True)
def generate_sampledata(options): pycon2011 = category( title=u"Pycon 2011", slug=u"pycon-2011", description=u"PyCon 2011 in Atlanta, GA", url=u"http://us.pycon.org/2011/home/", save=True, ) pycon2012 = category( title=u"Pycon 2012", slug=u"pycon-2012", description=u"PyCon 2011 in Santa Clara, CA", url=u"http://us.pycon.org/2012/", save=True, ) sp1 = speaker(name=u"Jessica McKellar", save=True) sp2 = speaker(name=u"Asheesh Laroia", save=True) sp3 = speaker(name=u"Jacob Kaplan-Moss", save=True) tag1 = tag(tag=u"documentation", save=True) tag2 = tag(tag=u"sphinx", save=True) v = video( state=Video.STATE_LIVE, category=pycon2011, title=u"Writing great documentation", summary=dedent( """\ Writing great documentation Presented by Jacob Kaplan-Moss """ ), description=dedent( """\ This talk looks at tips, tools, and techniques you can use to produce great technical documentation. """ ), copyright_text=u"CC-SA-NC 3.0", recorded=date(2011, 3, 11), updated=datetime(2011, 3, 14, 3, 47, 59), source_url=u"http://blip.tv/file/4881071", video_mp4_url=( u"http://05d2db1380b6504cc981-8cbed8cf7e3a131cd8f1c3e383d10041" u".r93.cf2.rackcdn.com/pycon-us-2011/" u"403_writing-great-documentation.mp4" ), thumbnail_url=(u"http://a.images.blip.tv/" u"Pycon-PyCon2011WritingGreatDocumentation902.png"), save=True, ) v.speakers.add(sp3) v.tags.add(tag1, tag2) v = video( state=Video.STATE_LIVE, category=pycon2012, title=dedent( """\ Diversity in practice: How the Boston Python User Group grew to 1700 people and over 15% women """ ), summary=dedent( u"""\ How do you bring more women into programming communities with long-term, measurable results? In this talk we'll analyze our successful effort, the Boston Python Workshop, which brought over 200 women into Boston's Python community this year. """ ), recorded=date(2012, 3, 11), updated=datetime(2012, 3, 13, 16, 15, 17), source_url=u"https://www.youtube.com/watch?v=QrITN6GZDu4", embed=dedent( """\ <object width="425" height="344"> <param name="movie" value="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1"> <param name="allowFullScreen" value="true"> <param name="allowscriptaccess" value="always"> <embed src="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1" allowscriptaccess="always" height="344" width="425" allowfullscreen="true" type="application/x-shockwave-flash"></embed> </object> """ ), thumbnail_url=u"http://img.youtube.com/vi/QrITN6GZDu4/hqdefault.jpg", save=True, ) v.speakers.add(sp1, sp2) v = video( state=Video.STATE_DRAFT, category=pycon2012, title=u"Draft video", summary=u"This is a draft", recorded=date(2012, 3, 11), updated=datetime(2012, 3, 13, 16, 15, 17), save=True, )
def generate_sampledata(options): pycon2011 = category(title=u'Pycon 2011', slug=u'pycon-2011', description=u'PyCon 2011 in Atlanta, GA', url=u'http://us.pycon.org/2011/home/', save=True) pycon2012 = category(title=u'Pycon 2012', slug=u'pycon-2012', description=u'PyCon 2011 in Santa Clara, CA', url=u'http://us.pycon.org/2012/', save=True) jm = speaker(name=u'Jessica McKellar', save=True) al = speaker(name=u'Asheesh Laroia', save=True) jkm = speaker(name=u'Jacob Kaplan-Moss', save=True) tag1 = tag(tag=u'documentation', save=True) tag2 = tag(tag=u'sphinx', save=True) v = video( state=Video.STATE_LIVE, category=pycon2011, title=u'Writing great documentation', summary=u'<p>Writing great documentation</p>' u'<p>Presented by Jacob Kaplan-Moss</p>', description=u'<p>This talk looks at tips, tools, and techniques you can' u'use to produce great technical documentation.</p>', copyright_text= u'Creative Commons Attribution-NonCommercial-ShareAlike 3.0', recorded=date(2011, 3, 11), updated=datetime(2011, 3, 14, 3, 47, 59), source_url=u'http://blip.tv/file/4881071', video_mp4_url= u'http://blip.tv/file/get/Pycon-PyCon2011WritingGreatDocumentation191.mp4', # noqa video_ogv_length=158578172, video_ogv_url= u'http://blip.tv/file/get/Pycon-PyCon2011WritingGreatDocumentation312.ogv', # noqa thumbnail_url= u'http://a.images.blip.tv/Pycon-PyCon2011WritingGreatDocumentation902.png', # noqa save=True) v.speakers.add(jkm) v.tags.add(tag1, tag2) v = video( state=Video.STATE_LIVE, category=pycon2012, title=u'Diversity in practice: How the Boston Python User Group grew ' u'to 1700 people and over 15% women', summary=u""" <p>How do you bring more women into programming communities with long-term, measurable results? In this talk we'll analyze our successful effort, the Boston Python Workshop, which brought over 200 women into Boston's Python community this year.</p>""", recorded=date(2012, 3, 11), updated=datetime(2012, 3, 13, 16, 15, 17), source_url=u'https://www.youtube.com/watch?v=QrITN6GZDu4', embed=u''' <object width="425" height="344"> <param name="movie" value="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1"> <param name="allowFullScreen" value="true"> <param name="allowscriptaccess" value="always"> <embed src="http://www.youtube.com/v/QrITN6GZDu4&hl=en&fs=1" allowscriptaccess="always" height="344" width="425" allowfullscreen="true" type="application/x-shockwave-flash"></embed> </object>''', # noqa thumbnail_url=u'http://img.youtube.com/vi/QrITN6GZDu4/hqdefault.jpg', save=True) v.speakers.add(jm, al)