예제 #1
0
 def setUp(self):
     """Define the test variables."""
     self.channel_name = "test"
     self.category_name = 'Games'
     self.subcategories_names = ['XBOX One', 'XBOX 360', 'Playstation 4']
     self.channel = Channel(name=self.channel_name)
     self.category = Category(name=self.category_name)
     self.subcategories = [
         Category(name=category_name)
         for category_name in self.subcategories_names
     ]
예제 #2
0
    def test_call_delete(self):
        '''
        Test deleting of a registration of a device from a channel
        '''

        u = User()
        u.username = "******"
        u.first_name = "sample_del"
        u.email = "*****@*****.**"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "DelSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid6'
        sub1.save()

        resp = ask_subscribe_channel(ch1, sub1.device_id)

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user',
                                                  '*****@*****.**',
                                                  'password')
        self.client.login(username='******', password='******')

        response = self.client.delete(
            reverse('browser-get-registration',
                    kwargs={
                        'device_id': sub1.device_id,
                        'channel_name': ch1.name
                    }))

        self.assertEqual(response.status_code, 200)

        channels = SubscriberManager().get_device_subscriptions(sub1.device_id)
        sub_channel = next((x for x in channels if x == ch1.name.lower()),
                           None)

        self.assertIsNone(sub_channel)
예제 #3
0
    def test_call_register_channel(self):
        '''
        Test registration to a channel
        '''

        u = User()
        u.username = "******"
        u.first_name = "sample_post"
        u.email = "*****@*****.**"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "PostSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid5'
        sub1.save()

        resp = ask_subscribe_channel(ch1, sub1.device_id)

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user',
                                                  '*****@*****.**',
                                                  'password')
        self.client.login(username='******', password='******')

        data = {
            'channel': ch1.name,
            'token': sub1.token,
            'browser': 'chrome',
            'device_id': sub1.device_id
        }

        response = self.client.post(reverse('browser-registration'),
                                    json.dumps(data), sub1.token)

        self.assertTrue(response.status_code, 200)
예제 #4
0
파일: views.py 프로젝트: safwanvk/ZabTube
 def post(self, request):
     # pass filled out HTML-Form from View to RegisterForm()
     form = ChannelForm(request.POST)
     if form.is_valid():
         # create a User account
         print(form.cleaned_data['channel_name'])
         channel_name = form.cleaned_data['channel_name']
         user = request.user
         subscribers = 0
         new_channel = Channel(channel_name=channel_name,
                               user=user,
                               subscribers=subscribers)
         new_channel.save()
         return HttpResponseRedirect('/')
     return HttpResponse('This is Register view. POST Request.')
예제 #5
0
 def handle(self, channel_name, categories_filename, *args, **options):
     if not isfile(categories_filename):
         raise CommandError('The specified filename does not exist.')
     try:
         channel = Channel.objects.get(name=channel_name)
         self.stdout.write('Overwriting channel %s...' % channel_name)
         Category.objects.filter(channel=channel).delete()
     except Channel.DoesNotExist:
         self.stdout.write('Creating channel %s...' % channel_name)
         channel = Channel(name=channel_name)
         channel.save()
     categories_paths = []
     created_categories = []
     with open(categories_filename, 'rt', encoding='utf8') as inp:
         # TODO Check the parent category is in the db if its not found in created_categories
         # (may happen if the file is not sorted)
         for line in inp:
             category_path = line.strip().replace('\n', '')
             if category_path != '':
                 categories_paths.append(category_path)
                 last_slash_pos = category_path.rfind('/')
                 parent = None
                 parent_path = ''
                 parent_name = ''
                 if last_slash_pos != -1:
                     parent_path = category_path[:last_slash_pos].strip()
                     parent_last_slash_pos = parent_path.rfind('/')
                     parent_name = parent_path[parent_last_slash_pos +
                                               1:].strip()
                     for created_category in reversed(created_categories):
                         if created_category.name == parent_name:
                             parent = created_category
                             break
                     if not parent:
                         self.stderr.write(
                             'Could not find the parent of category %s (check the file is sorted).'
                             % category_path)
                 category_name = category_path[last_slash_pos + 1:].strip()
                 self.stdout.write('Creating category %s...' %
                                   category_path)
                 category = Category(name=category_name,
                                     channel=channel,
                                     parent=parent)
                 category.save()
                 created_categories.append(category)
     n_categories = len(created_categories)
     self.stdout.write('Channel %s was imported with %i categories.' %
                       (channel_name, n_categories))
예제 #6
0
    def test_call_get(self):
        '''
        Test check if a device is registered to a channel
        '''

        u = User()
        u.username = "******"
        u.first_name = "Sample_un"
        u.email = "*****@*****.**"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "GetSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid4'
        sub1.save()

        resp = ask_subscribe_channel(ch1, 'devid4')

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user',
                                                  '*****@*****.**',
                                                  'password')
        self.client.login(username='******', password='******')

        response = self.client.get(
            reverse('browser-get-registration',
                    kwargs={
                        'device_id': 'devid4',
                        'channel_name': 'GetSub'
                    }))

        self.assertTrue(response.status_code, 200)
예제 #7
0
 def setUp(self):
     """Define the test variables."""
     self.channel = Channel(name='test_channel')
     self.channel.save()
     self.categories_tree = {
         'Games': {
             'XBOX One': ['Console', 'Acessories', 'Games'],
             'XBOX 360': None,
             'Playstation 4': None
         },
         'Books': {
             'National Literature': ['Science Fiction', 'Fiction Fantastic'],
             'Foreign Language': None
         }
     }
     self.categories = []
     self.create_categories_recursive(self.categories_tree)
     self.responses = {
         'list_channels': self.client.get('/channels/'),
         'list_channel_categories': self.client.get('/channels/%s/' % self.channel.uuid),
         'list_category_relcategories': self.client.get('/categories/%s/' % (self.categories[1].uuid))
     }