Ejemplo n.º 1
0
    def test_guest_register(self):
        # Create guest
        response = self.client.get(reverse('home'))
        user = response.context['user']
        token = response.wsgi_request.token
        self.assertTrue(user.is_guest)

        self.client.credentials(
            HTTP_AUTHORIZATION='Token {}'.format(token,)
        )

        data = {
            'password': '******'
        }

        expected_response_keys = {'token', 'is_guest', 'number', 'certificate'}

        response = self.client.post(self.register_url, data)
        filename = "{}.pub".format(response.data['number'],)
        storage = get_storage()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(expected_response_keys,
                         set(response.data.keys()))
        self.assertTrue(storage.exists(filename))
        self.assertEqual(storage.url(filename), response.data['certificate'])
Ejemplo n.º 2
0
    def test_login(self):
        data = self.data.copy()
        data['number'] = self.number
        filename = '{}.pub'.format(self.number,)
        certificate_file = get_storage().path(filename)
        with open(certificate_file, 'rb') as file_data:
            data['certificate'] = file_data
            response = self.client.post(self.login_url, data)

            expected_response_keys = {'token', 'is_guest', 'number'}

            self.assertEqual(response.status_code, status.HTTP_200_OK)
            self.assertEqual(expected_response_keys,
                             set(response.data.keys()))
Ejemplo n.º 3
0
    def test_no_guest_register(self):
        data = {
            'password': '******'
        }

        expected_response_keys = {'token', 'is_guest', 'number', 'certificate'}

        response = self.client.post(self.register_url, data)
        filename = "{}.pub".format(response.data['number'],)
        storage = get_storage()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(expected_response_keys,
                         set(response.data.keys()))
        self.assertTrue(storage.exists(filename))
        self.assertEqual(storage.url(filename), response.data['certificate'])
Ejemplo n.º 4
0
    def test_register(self):
        data = {
            "password": "******",
            "first_name": "Test",
            "last_name": "Testoff",
            "middle_name": "J",
            "phone": "0977678889",
            "email": "*****@*****.**",
        }

        expected_response_keys = {'token', 'is_guest', 'number', 'certificate'}

        response = self.client.post(self.register_url, data)
        filename = "{}.pub".format(response.data['number'],)
        storage = get_storage()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(expected_response_keys,
                         set(response.data.keys()))
        self.assertTrue(storage.exists(filename))
        self.assertEqual(storage.url(filename), response.data['certificate'])