def test_no_permissions(self):
        """
        write_concert_info() is to return "Permission not granted"
        if the permissions necessary are not granted
        """

        login(self.client)

        client = create_client('test')
        client.write_access = False
        client.save()
        festival = create_festival('test', create_user())
        festival.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),
                'end':
                timezone.datetime.utcnow() +
                timezone.timedelta(days=2, hours=2)
            })
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Permission not granted',
                         response.content.decode('utf-8'))
    def test_correct_input(self):
        """
        write_concert_info() is to return "OK" if information is successfully added.
        A new concert instance is to be created
        """

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

        festival = create_festival('test', create_user())
        festival.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('OK', response.content.decode('utf-8'))
        self.assertTrue(Concert.objects.filter(artist='test').exists())
    def test_invalid_fields(self):
        """
        write_concert_info() is to return "Incorrect input" if fields are input with wrong data
        """

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

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

        response = self.client.post(
            '/backend/w/conc/', {
                'client':
                'test',
                'festival':
                festival.pk,
                'artist':
                'testtestsetsetsetsetse\
                                         tsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetstsetsetsetset\
                                         testsetsetsetestestsetsetsetstsetsetsetsetsetsetsetsetsetsetsetsetsetstset\
                                         testetsetsetsettestsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsett',
                '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('Incorrect input', response.content.decode('utf-8'))
        self.assertFalse(Concert.objects.filter(festival=festival).exists())
    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_invalid_fields(self):
        """
        write_concert_info() is to return "Incorrect input" if fields are input with wrong data
        """

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

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

        response = self.client.post('/backend/w/conc/',
                                    {'client': 'test',
                                     'festival': festival.pk,
                                     'artist':
                                         'testtestsetsetsetsetse\
                                         tsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetstsetsetsetset\
                                         testsetsetsetestestsetsetsetstsetsetsetsetsetsetsetsetsetsetsetsetsetstset\
                                         testetsetsetsettestsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsetsett',
                                     '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('Incorrect input', response.content.decode('utf-8'))
        self.assertFalse(Concert.objects.filter(festival=festival).exists())
    def test_filter_satisfied_results(self):
        """
        read_multiple_festivals() is to return between 1 and num results, depending on how
        many satisfy the filter
        """

        login(self.client)

        user = create_user()
        create_festival('test', user)
        fest1 = create_festival('testest', user)
        fest1.city = 'testest'
        fest1.prices = '3e 50e 200e'
        fest1.save()
        fest2 = create_festival('testestest', user)
        fest2.prices = '3e 50e 200e'
        fest2.save()
        fest3 = create_festival('testestestest', user)
        fest3.prices = '1000e'
        fest3.save()
        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3,
            'min_price': '20e',
            'max_price': '60e'
        })
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 2)
    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_filter_satisfied_results(self):
        """
        read_multiple_festivals() is to return between 1 and num results, depending on how
        many satisfy the filter
        """

        login(self.client)

        user = create_user()
        create_festival('test', user)
        fest1 = create_festival('testest', user)
        fest1.city = 'testest'
        fest1.prices = '3e 50e 200e'
        fest1.save()
        fest2 = create_festival('testestest', user)
        fest2.prices = '3e 50e 200e'
        fest2.save()
        fest3 = create_festival('testestestest', user)
        fest3.prices = '1000e'
        fest3.save()
        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3,
            'min_price': '20e',
            'max_price': '60e'
        })
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 2)
    def test_records_available_equal_or_more_than_requested(self):
        """
        read_multiple_festivals() is to return the requested number of records in case
        the database has that many records
        """

        login(self.client)

        user = create_user()
        fest1 = create_festival('test', user)
        fest1.save()
        fest2 = create_festival('testest', user)
        fest2.save()
        fest3 = create_festival('testestest', user)
        fest3.save()
        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3
        })
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 3)
        create_festival('testestestest', user)
        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3
        })
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 3)
    def test_no_client_name_provided(self):
        """
        write_concert_info() is to return "Client name not provided"
        if no client name is provided
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post(
            '/backend/w/conc/', {
                'festival':
                festival.pk,
                'artist':
                'test',
                'start':
                timezone.datetime.utcnow() +
                timezone.timedelta(days=2, hours=1),
                'end':
                timezone.datetime.utcnow() +
                timezone.timedelta(days=2, hours=2)
            })
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Client name not provided',
                         response.content.decode('utf-8'))
    def test_correct_input(self):
        """
        write_concert_info() is to return "OK" if information is successfully added.
        A new concert instance is to be created
        """

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

        festival = create_festival('test', create_user())
        festival.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('OK', response.content.decode('utf-8'))
        self.assertTrue(Concert.objects.filter(artist='test').exists())
    def test_no_client_name_provided(self):
        """
        read_festival_concerts() is to return "Client name not provided"
        if no client name is provided
        """
        login(self.client)

        response = self.client.post('/backend/mult/conc/', {'id': 0})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), 'Client name not provided')
    def test_no_client_name_provided(self):
        """
        read_festival_concerts() is to return "Client name not provided"
        if no client name is provided
        """
        login(self.client)

        response = self.client.post('/backend/mult/conc/', {'id': 0})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'),
                         'Client name not provided')
    def test_invalid_festival(self):
        """
        read_festival_concerts() is to return "Invalid Festival ID"
        if festival id is invalid
        """

        login(self.client)

        response = self.client.post('/backend/mult/conc/', {'client': 'test', 'id': 0})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), 'Invalid Festival ID')
    def test_no_client_name_provided(self):
        """
        delete_concert() is to return "Client name not provided"
        if no client name is provided
        """

        login(self.client)

        response = self.client.post('/backend/d/conc/', {'id': 0})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Client name not provided', response.content.decode('utf-8'))
    def test_no_client_name_provided(self):
        """
        update_festival_info() is to return "Client name not provided"
        if no client name is provided
        """

        login(self.client)

        response = self.client.post('/backend/u/fest/', {'id': 3})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Client name not provided', response.content.decode('utf-8'))
    def test_empty_db(self):
        """
        read_multiple_festivals() is to return an empty JSON data document
        if there are no festivals in the database
        """

        login(self.client)

        response = self.client.post('/backend/mult/fest/', {'client': 'test', 'num': 3})
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertTrue(not data)
Beispiel #18
0
    def test_no_client_name_provided(self):
        """
        update_festival_info() is to return "Client name not provided"
        if no client name is provided
        """

        login(self.client)

        response = self.client.post('/backend/u/fest/', {'id': 3})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Client name not provided',
                         response.content.decode('utf-8'))
Beispiel #19
0
    def test_no_concert_found(self):
        """
        read_concert_info() is to return an empty JSON document if no concert satisfies the criteria
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/r/conc/', {'client': 'test', 'artist': 0})
        data = json.loads(response.content.decode('utf-8'))
        self.assertFalse(data)
    def test_no_festival_found(self):
        """
        read_festival_info() is to return "Invalid Festival ID" data document
        if festival is not found
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/r/fest/', {'client': 'test', 'id': festival.pk + 1})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), 'Invalid Festival ID')
    def test_less_records_available_than_requested(self):
        """
        read_multiple_festivals() is to return the amount of available festivals in case
        that number is less than the number requested
        """

        login(self.client)

        fest = create_festival('test', create_user())
        fest.save()
        response = self.client.post('/backend/mult/fest/', {'client': 'test', 'num': 3})
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 1)
    def test_no_permissions(self):
        """
        read_multiple_festivals() should return "Permission not granted"
        if the permissions necessary are not granted
        """

        login(self.client)

        client = create_client('test')
        client.read_access = False
        client.save()
        response = self.client.post('/backend/mult/fest/', {'client': 'test', 'num': 3})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), 'Permission not granted')
    def test_no_permissions(self):
        """
        update_festival_info() should return "Permission not granted"
        if the permissions necessary are not granted
        """

        login(self.client)

        client = create_client('test')
        client.write_access = False
        client.save()
        response = self.client.post('/backend/u/fest/', {'client': 'test', 'id': 3})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Permission not granted', response.content.decode('utf-8'))
Beispiel #24
0
    def test_festival_matches(self):
        """
        vote() is to return the number of voters for the festival if festival is found.
        Festival is to be upvoted before result
        """
        login(self.client)

        client = create_client('test')
        client.vote_access = True
        client.save()
        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/v/', {'client': 'test', 'id': festival.pk})
        self.assertEqual(festival.voters_number(), int(response.content.decode('utf-8')))
    def test_empty_festival(self):
        """
        read_festival_concerts() is to return an empty JSON data document
        if festival is found but empty
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        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.assertTrue(not data)
    def test_no_permissions(self):
        """
        delete_concert() is to return "Permission not granted"
        if the permissions necessary are not granted
        """

        login(self.client)

        client = create_client('test')
        client.delete_access = False
        client.save()
        response = self.client.post('/backend/d/conc/', {'client': 'test', 'id': 0})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Permission not granted', response.content.decode('utf-8'))
Beispiel #27
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'])
    def test_festival_found(self):
        """
        read_festival_info() is to return an JSON data document containing the data
        of the festival found
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/r/fest/', {'client': 'test', 'id': festival.pk})
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertTrue(data)
        self.assertEqual(data['name'], festival.name)
    def test_empty_db(self):
        """
        read_multiple_festivals() is to return an empty JSON data document
        if there are no festivals in the database
        """

        login(self.client)

        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3
        })
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertTrue(not data)
Beispiel #30
0
    def test_missing_fields(self):
        """
        write_festival_info() is to return "Incorrect input" if necessary fields are missing
        """

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

        response = self.client.post('/backend/w/fest/',
                                    {'client': 'test'})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Incorrect input', response.content.decode('utf-8'))
        self.assertFalse(Festival.objects.filter(name='test').exists())
    def test_invalid_festival(self):
        """
        read_festival_concerts() is to return "Invalid Festival ID"
        if festival id is invalid
        """

        login(self.client)

        response = self.client.post('/backend/mult/conc/', {
            'client': 'test',
            'id': 0
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'),
                         'Invalid Festival ID')
    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_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())
Beispiel #34
0
    def test_no_matching_festivals(self):
        """
        vote() is to return "Invalid Festival ID" if festival is not found
        no festivals are to be upvoted
        """

        login(self.client)

        client = create_client('test')
        client.vote_access = True
        client.save()
        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/v/', {'client': 'test', 'id': 15})
        self.assertEqual('Invalid Festival ID', response.content.decode('utf-8'))
        self.assertEqual(0, festival.voters_number())
Beispiel #35
0
    def test_no_matching_festivals(self):
        """
        delete_festival() is to return "Invalid Festival ID" if festival is not found
        No festivals 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()
        festival1 = create_festival('testest', user)
        festival1.save()
        festival2 = create_festival('testestest', user)
        festival2.save()
        response = self.client.post('/backend/d/fest/', {
            'client': 'test',
            'id': 15
        })
        self.assertEqual('Invalid Festival ID',
                         response.content.decode('utf-8'))
        self.assertEqual(3, Festival.objects.all().count())
Beispiel #36
0
    def test_invalid_fields(self):
        """
        update_festival_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()

        response = self.client.post(
            '/backend/u/fest/', {
                'client': 'test',
                'id': festival.pk,
                'name': 'test',
                'description': 'test',
                'country':
                'impossiblylongandabsurdnameforacountrythatreallyshouldntexist',
                'city': 'test',
                'address': 'test',
                'genre': 'test',
                'prices': '0e',
                'owner': 'test',
                'official': False
            })
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Incorrect input', response.content.decode('utf-8'))
        festival = Festival.objects.get(pk=festival.pk)
        self.assertEqual('test', festival.country)
Beispiel #37
0
    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()

        response = self.client.post(
            '/backend/u/fest/', {
                'client': 'test',
                'id': festival.pk,
                'city': 'testest',
                'description': 'testestest'
            })

        self.assertEqual(response.status_code, 200)
        response_string = response.content.decode('utf-8')
        self.assertTrue('city:testest\n' in response_string)
        self.assertTrue('description:testestest\n' in response_string)
        self.assertEqual(3, len(response_string.split('\n')))
        festival = Festival.objects.get(pk=festival.pk)
        self.assertEqual('testest', festival.city)
    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_invalid_fields(self):
        """
        update_festival_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()

        response = self.client.post('/backend/u/fest/',
                                    {'client': 'test',
                                     'id': festival.pk,
                                     'name': 'test',
                                     'description': 'test',
                                     'country':
                                         'impossiblylongandabsurdnameforacountrythatreallyshouldntexist',
                                     'city': 'test',
                                     'address': 'test',
                                     'genre': 'test',
                                     'prices': '0e',
                                     'owner': 'test',
                                     'official': False})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Incorrect input', response.content.decode('utf-8'))
        festival = Festival.objects.get(pk=festival.pk)
        self.assertEqual('test', festival.country)
    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()

        response = self.client.post('/backend/u/fest/',
                                    {'client': 'test',
                                     'id': festival.pk,
                                     'city': 'testest',
                                     'description': 'testestest'
                                     })

        self.assertEqual(response.status_code, 200)
        response_string = response.content.decode('utf-8')
        self.assertTrue('city:testest\n' in response_string)
        self.assertTrue('description:testestest\n' in response_string)
        self.assertEqual(3, len(response_string.split('\n')))
        festival = Festival.objects.get(pk=festival.pk)
        self.assertEqual('testest', festival.city)
    def test_empty_festival(self):
        """
        read_festival_concerts() is to return an empty JSON data document
        if festival is found but empty
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        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.assertTrue(not data)
Beispiel #42
0
    def test_no_festival_found(self):
        """
        read_festival_info() is to return "Invalid Festival ID" data document
        if festival is not found
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/r/fest/', {
            'client': 'test',
            'id': festival.pk + 1
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'),
                         'Invalid Festival ID')
    def test_less_records_available_than_requested(self):
        """
        read_multiple_festivals() is to return the amount of available festivals in case
        that number is less than the number requested
        """

        login(self.client)

        fest = create_festival('test', create_user())
        fest.save()
        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3
        })
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 1)
Beispiel #44
0
    def test_festival_matches(self):
        """
        vote() is to return the number of voters for the festival if festival is found.
        Festival is to be upvoted before result
        """
        login(self.client)

        client = create_client('test')
        client.vote_access = True
        client.save()
        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/v/', {
            'client': 'test',
            'id': festival.pk
        })
        self.assertEqual(festival.voters_number(),
                         int(response.content.decode('utf-8')))
Beispiel #45
0
    def test_no_permissions(self):
        """
        update_festival_info() should return "Permission not granted"
        if the permissions necessary are not granted
        """

        login(self.client)

        client = create_client('test')
        client.write_access = False
        client.save()
        response = self.client.post('/backend/u/fest/', {
            'client': 'test',
            'id': 3
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Permission not granted',
                         response.content.decode('utf-8'))
    def test_filter_does_not_satisfy_any_results(self):
        """
        read_multiple_festivals() is to return empty JSON data document in case no records
        satisfy the filter
        """

        login(self.client)

        create_festival('test', create_user())
        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3,
            'name': 'test',
            'country': 'test',
            'city': 'asdf'
        })
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(data), 0)
Beispiel #47
0
    def test_no_client_name_provided(self):
        """
        write_festival_info() is to return "Client name not provided"
        if no client name is provided
        """

        login(self.client)

        response = self.client.post('/backend/w/fest/', {'name': 'test',
                                                         'description': 'test',
                                                         'country': 'test',
                                                         'city': 'test',
                                                         'address': 'test',
                                                         'genre': 'test',
                                                         'prices': '0e',
                                                         'official': False})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Client name not provided', response.content.decode('utf-8'))
    def test_no_permissions(self):
        """
        read_multiple_festivals() should return "Permission not granted"
        if the permissions necessary are not granted
        """

        login(self.client)

        client = create_client('test')
        client.read_access = False
        client.save()
        response = self.client.post('/backend/mult/fest/', {
            'client': 'test',
            'num': 3
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'),
                         'Permission not granted')
Beispiel #49
0
    def test_duplication(self):
        """
        write_festival_info() is to return "Name exists" if a festival entry with the same name
        already exists
        """

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

        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/w/fest/',
                                    {'client': 'test',
                                     'name': 'test'})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Name exists', response.content.decode('utf-8'))
Beispiel #50
0
    def test_festival_found(self):
        """
        read_festival_info() is to return an JSON data document containing the data
        of the festival found
        """

        login(self.client)

        festival = create_festival('test', create_user())
        festival.save()
        response = self.client.post('/backend/r/fest/', {
            'client': 'test',
            'id': festival.pk
        })
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content.decode('utf-8'))
        self.assertTrue(data)
        self.assertEqual(data['name'], festival.name)
    def test_not_owner(self):
        """
        update_festival_info() should return "Permission not granted"
        if the current user is different from the festival owner
        """
        creating_user = create_user()
        creating_user.save()
        festival = create_festival('test', creating_user)
        festival.save()

        login(self.client)

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

        response = self.client.post('/backend/u/fest/', {'client': 'test', 'id': 3})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('Permission not granted', response.content.decode('utf-8'))