Ejemplo n.º 1
0
    def test_can_list_preference_of_requeting_user(self):
        second_user = User(username="******",
                           email="*****@*****.**",
                           is_superuser=True,
                           is_staff=True)
        second_user.set_password('test')
        second_user.save()

        manager = registry.manager(instance=self.user)
        url = reverse('api:user-list')
        self.client.login(username='******', password="******")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        payload = json.loads(response.content.decode('utf-8'))

        self.assertEqual(len(payload), len(registry.preferences()))

        url = reverse('api:user-list')
        self.client.login(username='******', password="******")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        payload = json.loads(response.content.decode('utf-8'))

        # This should be 7 because each user gets 7 preferences by default.
        self.assertEqual(len(payload), 8)

        for e in payload:
            pref = manager.get_db_pref(section=e['section'], name=e['name'])
            serializer = serializers.UserPreferenceSerializer(pref)
            self.assertEqual(pref.preference.identifier(), e['identifier'])
    def test_can_list_preferences(self):
        manager = registry.manager(instance=self.user)
        url = reverse('api:user-list')
        self.client.login(username='******', password="******")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        payload = json.loads(response.content.decode('utf-8'))

        self.assertEqual(len(payload), len(registry.preferences()))

        for e in payload:
            pref = manager.get_db_pref(section=e['section'], name=e['name'])
            serializer = serializers.UserPreferenceSerializer(pref)
            self.assertEqual(pref.preference.identifier(), e['identifier'])