def test_correct_input(self):
        """
        update_festival_info() is to return a list of the modified fields
        Festival is to be modified
        """

        user = login(self.client)
        client = create_client('test')
        client.write_access = True
        client.save()

        festival = create_festival('test', user)
        festival.save()
        concert = create_concert(festival, 'test')
        concert.save()

        response = self.client.post('/backend/u/conc/',
                                    {'client': 'test',
                                     'id': concert.pk,
                                     'stage': 2,
                                     'artist': 'tset'
                                     })

        self.assertEqual(response.status_code, 200)
        response_string = response.content.decode('utf-8')
        self.assertTrue('artist:tset' in response_string)
        self.assertTrue('stage:2' in response_string)
        self.assertEqual(3, len(response_string.split('\n')))
        self.assertEqual(1, Concert.objects.filter(festival=festival, artist='tset').count())
    def test_invalid_fields(self):
        """
        update_concert_info() is to return "Incorrect input" if fields are input with wrong data
        """

        user = login(self.client)
        client = create_client('test')
        client.write_access = True
        client.save()

        festival = create_festival('test', user)
        festival.save()
        concert = create_concert(festival, 'test')
        concert.save()

        response = self.client.post('/backend/u/conc/',
                                    {'client': 'test',
                                     'id': concert.pk,
                                     'artist':
                                         'testtestsetsetsetsetse\
                                         tsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetstsetsetsetset\
                                         testsetsetsetestestsetsetsetstsetsetsetsetsetsetsetsetsetsetsetsetsetstset\
                                         testetsetsetsettestsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsett'})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Incorrect input', response.content.decode('utf-8'))
        self.assertEqual(1, Concert.objects.filter(festival=festival, artist='test').count())
    def test_duplication(self):
        """
        write_concert_info() is to return "Artist exists" if a concert entry with the same artist
        already exists
        """

        login(self.client)
        client = create_client('test')
        client.write_access = True
        client.save()

        festival = create_festival('test', create_user())
        festival.save()
        concert = create_concert(festival, 'test')
        concert.save()
        response = self.client.post('/backend/w/conc/',
                                    {'client': 'test',
                                     'festival': festival.pk,
                                     'artist': 'test',
                                     'start': (timezone.datetime.utcnow() +
                                               timezone.timedelta(days=2,
                                                                  hours=1)).timestamp(),
                                     'end': (timezone.datetime.utcnow() +
                                             timezone.timedelta(days=2,
                                                                hours=2)).timestamp()})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Artist exists', response.content.decode('utf-8'))
    def test_duplication(self):
        """
        write_concert_info() is to return "Artist exists" if a concert entry with the same artist
        already exists
        """

        login(self.client)
        client = create_client('test')
        client.write_access = True
        client.save()

        festival = create_festival('test', create_user())
        festival.save()
        concert = create_concert(festival, 'test')
        concert.save()
        response = self.client.post(
            '/backend/w/conc/', {
                'client':
                'test',
                'festival':
                festival.pk,
                'artist':
                'test',
                'start': (timezone.datetime.utcnow() +
                          timezone.timedelta(days=2, hours=1)).timestamp(),
                'end': (timezone.datetime.utcnow() +
                        timezone.timedelta(days=2, hours=2)).timestamp()
            })
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Artist exists', response.content.decode('utf-8'))
예제 #5
0
    def test_concert_found(self):
        """
        delete_festival() is to return "OK" if concert is found
        Concert is to be deleted
        """

        user = login(self.client)

        client = create_client('test')
        client.delete_access = True
        client.save()
        festival = create_festival('test', user)
        festival.save()
        concert = create_concert(festival, 'test')
        create_concert(festival, 'testest')
        create_concert(festival, 'testestest')
        response = self.client.post('/backend/d/conc/', {'client': 'test', 'id': concert.pk})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('OK', response.content.decode('utf-8'))
        self.assertEqual(2, Concert.objects.all().count())
    def test_no_matching_concerts(self):
        """
        update_concert_info() is to return "Concert not found" if concert is not found
        No concerts are to be updated
        """

        user = login(self.client)

        client = create_client('test')
        client.write_access = True
        client.save()

        festival = create_festival('test', user)
        festival.save()
        concert1 = create_concert(festival, 'test')
        concert1.save()
        concert2 = create_concert(festival, 'testest')
        concert2.save()
        concert3 = create_concert(festival, 'testestest')
        concert3.save()
        response = self.client.post('/backend/u/conc/', {'client': 'test', 'id': -1})
        self.assertEqual('Concert Not Found', response.content.decode('utf-8'))
예제 #7
0
    def test_concert_found(self):
        """
        read_concert_info() is to return a JSON document containing the concert's information
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        concert = create_concert(festival, 'test')
        concert.save()
        response = self.client.post('/backend/r/conc/', {'client': 'test', 'id': concert.pk})
        data = json.loads(response.content.decode('utf-8'))
        self.assertTrue(data)
        self.assertTrue('test', data['artist'])
예제 #8
0
    def test_not_uploader(self):
        """
        delete_concert() is to return "Permission not granted"
        if the uploader of the festival hosting the concert is different from the logged user
        """
        creating_user = create_user()

        festival = create_festival('test', creating_user)
        festival.save()

        concert = create_concert(festival, 'test')
        concert.save()

        login(self.client)

        client = create_client('test')
        client.delete_access = True
        client.save()
        response = self.client.post('/backend/d/conc/', {'client': 'test', 'id': concert.pk})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Permission not granted', response.content.decode('utf-8'))
    def test_valid_festival(self):
        """
        read_festival_concerts() is to return all concerts in the festival
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        create_concert(festival, 'test')
        create_concert(festival, 'testest')
        create_concert(festival, 'testestest')
        response = self.client.post('/backend/mult/conc/', {'client': 'test', 'id': festival.pk})
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 3)
    def test_not_owner(self):
        """
        update_concert_info() should return "Permission not granted"
        if the current user is different from the owner of the festival hosting the concert
        """
        creating_user = create_user()
        creating_user.save()
        festival = create_festival('test', creating_user)
        festival.save()

        concert = create_concert(festival, 'test')
        concert.save()

        login(self.client)

        client = create_client('test')
        client.delete_access = True
        client.save()

        response = self.client.post('/backend/u/conc/', {'client': 'test', 'id': concert.pk})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Permission not granted', response.content.decode('utf-8'))
    def test_valid_festival(self):
        """
        read_festival_concerts() is to return all concerts in the festival
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        create_concert(festival, 'test')
        create_concert(festival, 'testest')
        create_concert(festival, 'testestest')
        response = self.client.post('/backend/mult/conc/', {
            'client': 'test',
            'id': festival.pk
        })
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 3)
예제 #12
0
    def test_no_concert_found(self):
        """
        delete_concert() is to return "Concert Not Found" if no concert is found
        No concerts are to be deleted
        """

        user = login(self.client)

        client = create_client('test')
        client.delete_access = True
        client.save()
        festival = create_festival('test', user)
        festival.save()
        create_concert(festival, 'test')
        create_concert(festival, 'testest')
        create_concert(festival, 'testestest')
        response = self.client.post('/backend/d/conc/',
                                    {'client': 'test', 'festival': festival.pk + 1, 'artist': 'asdf'})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Concert Not Found', response.content.decode('utf-8'))
        self.assertEqual(3, Concert.objects.all().count())