def save_ratings_db(user, ratings, kind, overwrite=False): #films = u";;".join([ u"::".join([unicode(x) if x else "" for x in record]) for record in ratings]) films = json.dumps(ratings) print films ratings = ImportRatings(movies=films, user=user, overwrite=overwrite, kind=kind) ratings.save()
def test_import_errors( self ): mail.outbox = [] # importratings broken json string ir = ImportRatings( user=self.u1, kind=ImportRatings.IMDB, movies = "{[#ups we have problem" ) ir.save() # 1 .. 2 .. 3 .. attempt ir = ImportRatings.objects.get( pk=ir.pk ) self.assertEqual( ir.attempts, 3 ) self.assertEqual( ir.import_status, ImportRatings.STATUS_IMPORT_FAILED ) self.assertFalse( ir.import_error_message is None ) self.assertFalse( ir.is_imported ) self.assertEqual( len( mail.outbox ), 1 ) # after manually fix ir.movies = '[{"title": "Wristcutters: A Love Story", "year": 2006, "score": 7, "imdb_id": "0477139"}]' ir.attempts = 0 ir.import_error_message = None ir.import_status = ImportRatings.STATUS_UNKNOWN ir.save() ir = ImportRatings.objects.get( pk=ir.pk ) self.assertEqual( ir.attempts, 1 ) self.assertEqual( ir.import_status, ImportRatings.STATUS_UNKNOWN ) self.assertTrue( ir.import_error_message is None ) self.assertTrue( ir.is_imported ) self.assertEqual( len( mail.outbox ), 2 )
def save_ratings_db(user, ratings, kind, overwrite=False): films = json.dumps(ratings) ratings = ImportRatings(movies=films, user=user, overwrite=overwrite, kind=kind) ratings.save()