Beispiel #1
0
  def testDoublePut(self):
    toAdd = [8]
    response = self.doJSONPut(
      '/udj/events/2/available_music', json.dumps(toAdd),
      headers={getDjangoUUIDHeader() : "20000000000000000000000000000000"})
    self.assertEqual(response.status_code, 201, response.content)
    self.verifyJSONResponse(response)
    results = json.loads(response.content)
    self.assertEqual(len(results), 1)
    self.assertTrue(8 in results)
    AvailableSong.objects.get(
      song__host_lib_song_id=8, song__owning_user__id=2)

    toAdd = [7, 8]
    response = self.doJSONPut(
      '/udj/events/2/available_music', json.dumps(toAdd),
      headers={getDjangoUUIDHeader() : "20000000000000000000000000000000"})
    self.assertEqual(response.status_code, 201, response.content)
    self.verifyJSONResponse(response)
    results = json.loads(response.content)
    self.assertEqual(len(results), 2)
    self.assertTrue(7 in results)
    self.assertTrue(8 in results)
    AvailableSong.objects.get(
      song__host_lib_song_id=7, song__owning_user__id=2)
    AvailableSong.objects.get(
      song__host_lib_song_id=8, song__owning_user__id=2)
Beispiel #2
0
    def testMultiLibAdd(self):

        lib_id1 = 13
        title1 = "Roulette Dares"
        artist1 = "The Mars Volta"
        album1 = "Deloused in the Comatorium"
        duration1 = 451

        lib_id2 = 14
        title2 = "Goliath"
        artist2 = "The Mars Volta"
        album2 = "The Bedlam in Goliath"
        duration2 = 435

        payload = [
            {"id": lib_id1, "title": title1, "artist": artist1, "album": album1, "duration": duration1},
            {"id": lib_id2, "title": title2, "artist": artist2, "album": album2, "duration": duration2},
        ]

        response = self.doJSONPut(
            "/udj/users/" + self.user_id + "/library/songs",
            json.dumps(payload),
            headers={getDjangoUUIDHeader(): "20000000000000000000000000000000"},
        )

        self.assertEqual(response.status_code, 201, msg=response.content)
        self.verifyJSONResponse(response)
        ids = json.loads(response.content)
        self.verifySongAdded(lib_id1, ids, title1, artist1, album1)
        self.verifySongAdded(lib_id2, ids, title2, artist2, album2)
Beispiel #3
0
 def testLibSongDelete(self):
     response = self.doDelete(
         "/udj/users/" + self.user_id + "/library/10",
         headers={getDjangoUUIDHeader(): "20000000000000000000000000000000"},
     )
     self.assertEqual(response.status_code, 200, msg=response.content)
     deletedEntries = LibraryEntry.objects.filter(host_lib_song_id=10, owning_user__id=2, is_deleted=True)
     self.assertEqual(len(deletedEntries), 1)
Beispiel #4
0
 def testReaddDeleted(self):
   toAdd = [11]
   response = self.doJSONPut(
     '/udj/events/2/available_music', json.dumps(toAdd),
     headers={getDjangoUUIDHeader() : "20000000000000000000000000000000"})
   readdedSong = AvailableSong.objects.get(
     song__host_lib_song_id=11, event__id=2)
   self.assertTrue(readdedSong.state, u'AC')
Beispiel #5
0
def deleteSongFromLibrary(request, user_id, lib_id):
  try:
    uuid = request.META[getDjangoUUIDHeader()]
    toDelete = LibraryEntry.objects.get(
      machine_uuid=uuid,
      host_lib_song_id=lib_id,
      owning_user=user_id)
    toDelete.is_deleted = True
    toDelete.save()
  except ObjectDoesNotExist:
    return HttpResponseNotFound()
  return HttpResponse("Deleted item: " + lib_id)
Beispiel #6
0
def addSongsToLibrary(request, user_id):

  uuid = request.META[getDjangoUUIDHeader()]
  #TODO catch any exception in the json parsing and return a bad request
  songsToAdd = json.loads(request.raw_post_data)

  toReturn = []
  for libEntry in songsToAdd:
    addedSong = addSongToLibrary(libEntry, user_id, uuid)
    toReturn.append(addedSong.host_lib_song_id)

  return getJSONResponse(json.dumps(toReturn), status=201)
Beispiel #7
0
def addToAvailableMusic(request, event_id):
  event = get_object_or_404(Event, pk=event_id)
  uuid = request.META[getDjangoUUIDHeader()]
  toAdd = json.loads(request.raw_post_data)
  added = []
  for song_id in toAdd:
    songToAdd = LibraryEntry.objects.get(
      host_lib_song_id=song_id, owning_user=event.host, machine_uuid=uuid)
    addedSong , created = AvailableSong.objects.get_or_create(
        event=event, song=songToAdd, defaults={'state': u'AC'})
    added.append(song_id)

  return getJSONResponse(json.dumps(added), status=201)
Beispiel #8
0
    def testSingleLibAdd(self):

        lib_id = 13
        title = "Roulette Dares"
        artist = "The Mars Volta"
        album = "Deloused in the Comatorium"
        duration = 451

        payload = [{"id": lib_id, "title": title, "artist": artist, "album": album, "duration": duration}]

        response = self.doJSONPut(
            "/udj/users/" + self.user_id + "/library/songs",
            json.dumps(payload),
            headers={getDjangoUUIDHeader(): "20000000000000000000000000000000"},
        )
        self.assertEqual(response.status_code, 201, msg=response.content)
        self.verifyJSONResponse(response)
        ids = json.loads(response.content)
        self.verifySongAdded(lib_id, ids, title, artist, album)
Beispiel #9
0
    def testDupAdd(self):

        dup_lib_id = 1

        payload = [
            {
                "song": "Never Let You Go",
                "artist": "Third Eye Blind",
                "album": "Blue",
                "id": dup_lib_id,
                "duration": 237,
            }
        ]
        response = self.doJSONPut(
            "/udj/users/" + self.user_id + "/library/songs",
            json.dumps(payload),
            headers={getDjangoUUIDHeader(): "20000000000000000000000000000000"},
        )

        self.assertEqual(response.status_code, 201, msg=response.content)
        self.verifyJSONResponse(response)
        ids = json.loads(response.content)
        self.assertEqual(ids[0], dup_lib_id)
        onlyOneSong = LibraryEntry.objects.get(owning_user__id=2, host_lib_song_id=dup_lib_id)
Beispiel #10
0
 def wrapper(*args, **kwargs):
   request = args[0]
   if not request.META.has_key(getDjangoUUIDHeader()):
     return HttpResponseBadRequest('must specify a machine UUID')
   else:
     return function(*args, **kwargs)