Permalink
Browse files

Remove import code that is replaced by the API

  • Loading branch information...
1 parent 5d5d5b9 commit 8b790f13359bbf6fde2b4acf8d55a7396db2aed8 @squiddy squiddy committed with Apr 20, 2012
Showing with 0 additions and 201 deletions.
  1. +0 −41 apps/videos/management/commands/importvideo.py
  2. +0 −55 apps/videos/models.py
  3. +0 −105 apps/videos/tests/test_models.py
@@ -1,41 +0,0 @@
-# richard -- video index system
-# Copyright (C) 2012 richard contributors. See AUTHORS.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import os
-import json
-from django.core.management.base import BaseCommand, CommandError
-from videos.models import create_videos
-
-
-class Command(BaseCommand):
- args = '<json-file>'
- help = 'Import video from a json file.'
-
-
- def handle(self, *args, **options):
- if not args:
- raise CommandError('Please specify a json file.')
-
- fn = args[0]
-
- fn = os.path.abspath(fn)
- if not os.path.exists(fn):
- raise CommandError('"%s" does not exist' % fn)
-
- f = open(fn, 'r')
- data = json.loads(f.read())
- f.close()
- create_videos(data)
View
@@ -300,58 +300,3 @@ def __unicode__(self):
def __repr__(self):
return '<URL %s>' % self.url
-
-
-def create_speakers(speakers):
- ret = []
-
- for name in speakers:
- name = name.strip()
- s, _ = Speaker.objects.get_or_create(name=name)
- ret.append(s)
- return ret
-
-
-def create_tags(tags):
- ret = []
-
- for tag in tags:
- tag = tag.strip()
- t, _ = Tag.objects.get_or_create(tag=tag)
- ret.append(t)
- return ret
-
-class BadVideoError(Exception):
- pass
-
-
-def create_videos(data):
- created = []
- for mem in data:
- if not 'source_url' in mem:
- raise BadVideoError('missing source_url')
-
- if Video.objects.filter(source_url=mem['source_url']).exists():
- continue
-
- # Fix category
- cat = Category.objects.get(pk=mem['category'])
- mem['category'] = cat
-
- # TODO: convert dates from strings here
-
- # Take out speakers and tags
- speakers = mem.pop('speakers', [])
- tags = mem.pop('tags', [])
-
- v = Video.objects.create(**mem)
-
- # Add speakers and tags
- for s in create_speakers(speakers):
- v.speakers.add(s)
- for t in create_tags(tags):
- v.tags.add(t)
-
- v.save()
- created.append(v)
- return created
@@ -1,105 +0,0 @@
-# richard -- video index system
-# Copyright (C) 2012 richard contributors. See AUTHORS.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-from django.test import TestCase
-from nose.tools import eq_
-from videos.tests import category_kind, category, tag, speaker, video
-from videos.models import create_videos
-
-
-class TestCreatevideo(TestCase):
- def test_create_no_videos(self):
- # Return an empty list if there's nothing to do
- eq_(create_videos([]), [])
-
- def test_create_one_video(self):
- cat = category(name=u'foo', slug=u'foo')
- cat.save()
-
- vid = {
- 'state': 1,
- 'title': u'foo',
- 'summary': u'foo',
- 'source_url': u'http://example.com/',
- 'category': cat.id}
- ret = create_videos([vid])
-
- eq_(ret[0].title, vid['title'])
-
- def test_video_with_speakers(self):
- cat = category(name=u'foo', slug=u'foo')
- cat.save()
-
- speaker_names = [u'Carl Karsten', u'Ryan Verner']
- vid = {
- 'state': 1,
- 'title': u'foo',
- 'summary': u'foo',
- 'source_url': u'http://example.com/',
- 'category': cat.id,
- 'speakers': speaker_names}
- ret = create_videos([vid])
-
- eq_(ret[0].title, vid['title'])
- speakers = ret[0].speakers.all()
- assert speakers[0].name in speaker_names
- assert speakers[1].name in speaker_names
- assert speakers[0].name != speakers[1].name
-
- def test_with_existing_speaker(self):
- carl = speaker(name=u'Carl Karsten')
- carl.save()
- speaker_names = [carl.name, u'Phil']
-
- cat = category(name=u'foo', slug=u'foo')
- cat.save()
-
- vid = {
- 'state': 1,
- 'title': u'foo',
- 'summary': u'foo',
- 'source_url': u'http://example.com/',
- 'category': cat.id,
- 'speakers': speaker_names}
- ret = create_videos([vid])
-
- eq_(ret[0].title, vid['title'])
- speakers = ret[0].speakers.order_by('name')[:]
- eq_(speakers[0].name, carl.name)
- eq_(speakers[0].id, carl.id)
- eq_(speakers[1].name, speaker_names[1])
-
- def test_video_with_tags(self):
- cat = category(name=u'foo', slug=u'foo')
- cat.save()
-
- t1 = tag(tag=u'tag1')
- t1.save()
- tag_names = [t1.tag, u'tag2']
- vid = {
- 'state': 1,
- 'title': u'foo',
- 'summary': u'foo',
- 'source_url': u'http://example.com/',
- 'category': cat.id,
- 'tags': tag_names}
- ret = create_videos([vid])
-
- eq_(ret[0].title, vid['title'])
- tags = ret[0].tags.order_by('tag')
- eq_(tags[0].tag, t1.tag)
- eq_(tags[0].id, t1.id)
- eq_(tags[1].tag, tag_names[1])

0 comments on commit 8b790f1

Please sign in to comment.