Ejemplo n.º 1
0
    def test_list_filtering(self):
        """ Users should be able to filter by the experiment_id and key fields. """
        url = reverse('api_experiments:v0:data-list')
        user = UserFactory()
        self.client.login(username=user.username,
                          password=UserFactory._DEFAULT_PASSWORD)  # lint-amnesty, pylint: disable=protected-access

        experiment_id = 1
        ExperimentDataFactory()
        ExperimentDataFactory(user=user)
        data = ExperimentDataFactory.create_batch(3,
                                                  user=user,
                                                  experiment_id=experiment_id)

        qs = six.moves.urllib.parse.urlencode({'experiment_id': experiment_id})
        response = self.client.get(f'{url}?{qs}')
        assert response.status_code == 200
        assert response.data['results'] == ExperimentDataSerializer(
            data, many=True).data

        datum = data[0]
        qs = six.moves.urllib.parse.urlencode({'key': datum.key})
        response = self.client.get(f'{url}?{qs}')
        assert response.status_code == 200
        assert response.data['results'] == ExperimentDataSerializer(
            [datum], many=True).data

        qs = six.moves.urllib.parse.urlencode({
            'experiment_id': experiment_id,
            'key': datum.key
        })
        response = self.client.get(f'{url}?{qs}')
        assert response.status_code == 200
        assert response.data['results'] == ExperimentDataSerializer(
            [datum], many=True).data
Ejemplo n.º 2
0
    def test_list_filtering(self):
        """ Users should be able to filter by the experiment_id and key fields. """
        url = reverse('api_experiments:v0:data-list')
        user = UserFactory()
        self.client.login(username=user.username,
                          password=UserFactory._DEFAULT_PASSWORD)

        experiment_id = 1
        ExperimentDataFactory()
        ExperimentDataFactory(user=user)
        data = ExperimentDataFactory.create_batch(3,
                                                  user=user,
                                                  experiment_id=experiment_id)

        qs = six.moves.urllib.parse.urlencode({'experiment_id': experiment_id})
        response = self.client.get('{url}?{qs}'.format(url=url, qs=qs))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['results'],
                         ExperimentDataSerializer(data, many=True).data)

        datum = data[0]
        qs = six.moves.urllib.parse.urlencode({'key': datum.key})
        response = self.client.get('{url}?{qs}'.format(url=url, qs=qs))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['results'],
                         ExperimentDataSerializer([datum], many=True).data)

        qs = six.moves.urllib.parse.urlencode({
            'experiment_id': experiment_id,
            'key': datum.key
        })
        response = self.client.get('{url}?{qs}'.format(url=url, qs=qs))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['results'],
                         ExperimentDataSerializer([datum], many=True).data)
Ejemplo n.º 3
0
    def test_list_permissions(self):
        """ Users should only be able to list their own data. """
        url = reverse('api_experiments:v0:data-list')
        user = UserFactory()

        response = self.client.get(url)
        assert response.status_code == 401

        ExperimentDataFactory()
        datum = ExperimentDataFactory(user=user)
        self.client.login(username=user.username, password=UserFactory._DEFAULT_PASSWORD)  # lint-amnesty, pylint: disable=protected-access

        response = self.client.get(url)
        assert response.status_code == 200
        assert response.data['results'] == ExperimentDataSerializer([datum], many=True).data
Ejemplo n.º 4
0
    def test_list_permissions(self):
        """ Users should only be able to list their own data. """
        url = reverse('api_experiments:v0:data-list')
        user = UserFactory()

        response = self.client.get(url)
        self.assertEqual(response.status_code, 401)

        ExperimentDataFactory()
        datum = ExperimentDataFactory(user=user)
        self.client.login(username=user.username,
                          password=UserFactory._DEFAULT_PASSWORD)

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['results'],
                         ExperimentDataSerializer([datum], many=True).data)