Ejemplo n.º 1
0
    def test_delete_group(self):

        user = UserFactory(username='******')

        self.client.force_login(UserFactory(is_superuser=True))

        response = self.client.get('/users/{pk}/delete/'.format(pk=user.pk))

        assert response.status_code == 200

        response = self.client.post('/users/{pk}/delete/'.format(pk=user.pk))

        self.assertRedirects(response, '/users/')

        assert not User.objects.filter(username='******').exists()
Ejemplo n.º 2
0
    def test_generate_api_token(self):

        user = UserFactory()
        user.api_token = 'aaa'
        user.save()

        with mock.patch(
            'django.utils.crypto.get_random_string',
            side_effect=[
                'aaa',
                'aaa',
                'bbb'
            ]
        ):
            token = generate_api_token()

            self.assertEqual(token, 'bbb')
Ejemplo n.º 3
0
    def test_logout(self):

        user = UserFactory()

        self.client.force_login(user)

        response = self.client.get('/logout/')

        self.assertRedirects(response, '/login/')
Ejemplo n.º 4
0
    def test_list_groups_non_superuser(self):

        user = UserFactory(is_superuser=False)

        self.client.force_login(user)

        response = self.client.get('/groups/')

        self.assertEqual(response.status_code, 403)
Ejemplo n.º 5
0
    def test_list_users(self):

        user = UserFactory(is_superuser=True)

        self.client.force_login(user)

        response = self.client.get('/users/')

        assert response.status_code == 200
Ejemplo n.º 6
0
    def test_create_user_non_superuser(self):

        user = UserFactory(is_superuser=False)

        self.client.force_login(user)

        response = self.client.get('/users/create/')

        assert response.status_code == 403
Ejemplo n.º 7
0
    def test_update_user_access_groups(self):

        admin_group = GroupFactory(name='Admin')
        api_group = GroupFactory(name='API')

        user = UserFactory(username='******', email='*****@*****.**')
        user.groups.add(api_group)
        user.save()

        self.client.force_login(UserFactory(is_superuser=True))

        response = self.client.get('/users/{pk}/'.format(pk=user.pk))

        self.assertEqual(response.status_code, 200)

        response = self.client.post(
            '/users/{pk}/access/'.format(pk=user.pk),
            data={'groups': [admin_group.pk, api_group.pk]})

        self.assertRedirects(response, '/users/')
        self.assertEqual(user.groups.count(), 2)
Ejemplo n.º 8
0
    def test_update_user(self):

        user = UserFactory(username='******', email='*****@*****.**')

        self.client.force_login(UserFactory(is_superuser=True))

        response = self.client.get('/users/{pk}/'.format(pk=user.pk))

        self.assertEqual(response.status_code, 200)

        response = self.client.post('/users/{pk}/'.format(pk=user.pk),
                                    data={
                                        'username': user.username,
                                        'email': '*****@*****.**',
                                    })

        self.assertRedirects(response, '/users/')

        user.refresh_from_db()

        self.assertEqual(user.email, '*****@*****.**')
Ejemplo n.º 9
0
    def test_delete_group(self):

        user = UserFactory(is_superuser=True)
        group = GroupFactory(name='Admin')

        self.assertTrue(Group.objects.filter(name='Admin').exists())

        self.client.force_login(user)

        response = self.client.get('/groups/{pk}/delete/'.format(pk=group.pk))

        self.assertEqual(response.status_code, 200)

        response = self.client.post('/groups/{pk}/delete/'.format(pk=group.pk))

        self.assertRedirects(response, '/groups/')

        self.assertFalse(Group.objects.filter(name='Admin').exists())
Ejemplo n.º 10
0
    def test_create_group(self):

        self.assertEqual(Group.objects.count(), 0)

        user = UserFactory(is_superuser=True)

        self.client.force_login(user)

        response = self.client.get('/groups/create/')

        self.assertEqual(response.status_code, 200)

        response = self.client.post('/groups/create/', data={
            'name': 'Admin'
        })

        self.assertRedirects(response, '/groups/')

        self.assertTrue(Group.objects.filter(name='Admin').exists())
Ejemplo n.º 11
0
    def test_create_user(self):

        self.client.force_login(UserFactory(is_superuser=True))

        response = self.client.get('/users/create/')

        self.assertEqual(response.status_code, 200)

        response = self.client.post('/users/create/',
                                    data={
                                        'username': '******',
                                        'email': '*****@*****.**',
                                    })

        self.assertRedirects(response, '/users/')

        user = User.objects.get(username='******')

        assert user.email == '*****@*****.**'
Ejemplo n.º 12
0
    def test_update_group(self):

        user = UserFactory(is_superuser=True)
        group = GroupFactory(name='Admin')

        self.client.force_login(user)

        response = self.client.get('/groups/{pk}/'.format(pk=group.pk))

        self.assertEqual(response.status_code, 200)

        response = self.client.post('/groups/{pk}/'.format(pk=group.pk), data={
            'name': 'API'
        })

        self.assertRedirects(response, '/groups/')

        group.refresh_from_db()

        self.assertEqual(group.name, 'API')
Ejemplo n.º 13
0
    def test_login(self):

        user = UserFactory()
        user.set_password('123123')
        user.save()

        response = self.client.get('/login/')

        self.assertEqual(response.status_code, 200)

        response = self.client.post('/login/', data={
            'username': user.username,
            'password': '******'
        })

        self.assertRedirects(response, '/')
Ejemplo n.º 14
0
    def test_create_component(self):

        self.client.force_login(UserFactory(is_superuser=True))

        response = self.client.get('/components/create/')

        assert response.status_code == 200

        response = self.client.post('/components/create/',
                                    data={
                                        'name': 'Database',
                                        'alias': 'database',
                                        'is_global': False,
                                        'require_schema': False,
                                        'additional_prop': True
                                    })

        self.assertRedirects(response,
                             '/components/database/',
                             target_status_code=302)

        assert Component.objects.filter(alias='database').exists()
Ejemplo n.º 15
0
    def test_update_component(self):

        component = ComponentFactory(name='Database', alias='database')
        development = EnvironmentFactory(name='Development',
                                         alias='development')

        assert Component.objects.filter(alias='database').exists()

        self.client.force_login(UserFactory(is_superuser=True))

        response = self.client.get('/components/database/base/edit/')

        assert response.status_code == 200

        response = self.client.post('/components/database/base/edit/',
                                    data={
                                        'settings':
                                        """
            {
              "host": "localhost",
              "port": 3567,
              "user": "******",
              "password": null
            }
            """
                                    })

        self.assertRedirects(response, '/components/database/base/edit/')

        settings_dict = get_settings(environment=development,
                                     component=component)

        assert settings_dict == {
            'host': 'localhost',
            'port': 3567,
            'user': '******',
            'password': None,
        }