コード例 #1
0
ファイル: tests.py プロジェクト: ivanzorya/api_migration
class UpdateMigrationWorkLoadTestCase(SetUpTestCase, APITestCase):
    def setUp(self):
        super().setUp()
        self.client = RequestsClient()

    def test_update_migration(self):
        response_migration = self.client.get(
            'http://testserver/api/v1/migrations/1/',
            headers={'Authorization': f'Bearer {self.token}'})
        self.assertEqual(response_migration.status_code, 200)
        data = {'selected_mount_points': 1}
        query = QueryDict('', mutable=True)
        query.update(data)
        response_update_migration = self.client.patch(
            'http://testserver/api/v1/migrations/1/',
            query,
            headers={'Authorization': f'Bearer {self.token}'})
        self.assertEqual(response_update_migration.status_code, 200)
        self.assertIn(bytes(self.mount_point_name_2, encoding='UTF-8'),
                      response_update_migration.content)

    def test_update_work_load(self):
        ip = uuid.uuid4().hex
        data = {'ip': ip}
        query = QueryDict('', mutable=True)
        query.update(data)
        response_update_work_load_error = self.client.patch(
            'http://testserver/api/v1/work_loads/1/',
            query,
            headers={'Authorization': f'Bearer {self.token}'})
        self.assertEqual(response_update_work_load_error.status_code, 400)
        self.assertIn(bytes('''Can't change''', encoding='UTF-8'),
                      response_update_work_load_error.content)
        data = {'credentials': 2}
        query = QueryDict('', mutable=True)
        query.update(data)
        response_update_work_load = self.client.patch(
            'http://testserver/api/v1/work_loads/1/',
            query,
            headers={'Authorization': f'Bearer {self.token}'})
        self.assertEqual(response_update_work_load.status_code, 200)
        self.assertIn(bytes(self.domain_2, encoding='UTF-8'),
                      response_update_work_load.content)
        response_work_load = self.client.get(
            'http://testserver/api/v1/work_loads/1/',
            headers={'Authorization': f'Bearer {self.token}'})
        self.assertIn(bytes(self.ip, encoding='UTF-8'),
                      response_work_load.content)
コード例 #2
0
class ApiTestCase(AdminLoggedOutTestCase):
    """
    We take the more complicated way here, and implement the API tests
    with Python requests. This ensures that we are getting as close as possible
    to 'real' API clients, e.g. from JavaScript.

    CRSF token and JWT are transported as cookie by default, in Django.
    The HTTP verb methods allow to override this and add according headers
    with the information. This is intended to support testing JavaScript AJAX calls,
    with seem to have trouble accessing the cookies sometimes. Ask @Kat-Hi.
    """
    def setUp(self):
        super().setUp()
        self.client = RequestsClient()
        self.jwt = None
        self.csrf = None

    def get(self, relative_url, headers={}):
        if self.jwt:
            headers["Authorization"] = "Bearer " + self.jwt
        return self.client.get('http://testserver' + relative_url,
                               headers=headers)

    def patch(self, relative_url, data, headers={}):
        if self.jwt:
            headers["Authorization"] = "Bearer " + self.jwt
        if self.csrf:
            headers['X-CSRFToken'] = self.csrf
        return self.client.patch('http://testserver' + relative_url,
                                 json=data,
                                 headers=headers)

    def post(self, relative_url, data=None, headers={}):
        if self.jwt:
            headers["Authorization"] = "Bearer " + self.jwt
        if self.csrf:
            headers['X-CSRFToken'] = self.csrf
        return self.client.post('http://testserver' + relative_url,
                                json=data,
                                headers=headers)

    def options(self, relative_url, headers={}):
        return self.client.options('http://testserver' + relative_url)

    def api_login(self):
        response = self.post(f'/api/{API_VERSION}/login/', {
            'username': admin_data['username'],
            'password': admin_clear_password
        })
        self.assertEqual(response.status_code, 200)
        data = response.json()
        self.assertIn('access_token', data)
        self.jwt = data['access_token']
コード例 #3
0
class TestUserAPIs(APITestCase):
    def setUp(self):
        self.client = RequestsClient()
        self.user1 = User.objects.create(username='******',
                                         first_name="Test",
                                         last_name='User',
                                         email='*****@*****.**',
                                         is_room_manager=True)
        self.user1.set_password('test_password')
        self.user1.save()
        self.token1 = Token.objects.create(user=self.user1)

    # Call login user with incomplete input
    def test_user_login_incomplete_input(self):
        response = self.client.post('http://*****:*****@example.com',
                "is_customer": True
            })
        self.assertEquals(response.status_code, 400)
        self.assertIn('username', response.json())

        self.assertEquals(response.status_code, 400)

    # Call user signup without is_customer and is_room_manager
    def test_user_signup_without_role(self):
        response = self.client.post(
            'http://*****:*****@example.com'
            })
        self.assertEquals(response.status_code, 400)
        self.assertIn('either customer or room manager',
                      response.json()['non_field_errors'][0])

    # Call user signup
    def test_user_signup(self):
        response = self.client.post(
            'http://*****:*****@example.com',
                "is_customer": True
            })
        self.assertEquals(response.status_code, 201)

    # Call user profile get without authentication
    def test_user_profile_get_without_auth(self):
        response = self.client.get('http://localhost:8000/api/profile')
        self.assertEquals(response.status_code, 401)

    # Call user profile get
    def test_user_profile_get(self):
        response = self.client.get(
            'http://localhost:8000/api/profile',
            headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 200)

    # Call user profile update without authentication
    def test_user_profile_update_without_auth(self):
        response = self.client.patch('http://localhost:8000/api/profile',
                                     {"username": "******"})
        self.assertEquals(response.status_code, 401)

    # Call user profile update to update is_customer or is_room_manager
    def test_user_profile_update_role(self):
        response = self.client.patch(
            'http://localhost:8000/api/profile', {
                "is_room_manager": False,
                "is_customer": True
            },
            headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 200)
        # Verify that is_customer and is_role_manager fields are not updated
        self.assertEquals(response.json()['is_customer'],
                          self.user1.is_customer)

    # Call user profile update
    def test_user_profile_update(self):
        response = self.client.patch(
            'http://localhost:8000/api/profile',
            {"username": "******"},
            headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 200)
        self.assertEquals(response.json()['username'], 'changedUsername')
コード例 #4
0
 def patch(self, relative_url, data, headers=None):
     client = RequestsClient()
     return client.patch('http://testserver' + relative_url,
                         json=data,
                         headers=self._all_headers(headers))
コード例 #5
0
class TestNFUpdate(TestCase):
    def setUp(self):
        self.client = APIClient()
        self.rc = RequestsClient()
        self.upd_data = {
            "vnfInstanceName": "vnf new name",
            "vnfInstanceDescription": "new description"
        }

    def tearDown(self):
        pass

    def test_update_vnf_not_exist(self):
        response = self.client.patch("/api/vnflcm/v1/vnf_instances/1111",
                                     data=self.upd_data,
                                     format='json')
        self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)

    def test_update_vnf_etag_not_match(self):
        instanceid = "19"
        NfInstModel(nfinstid=instanceid,
                    nf_name='VNF1',
                    nf_desc="VNF DESC",
                    vnfdid="1",
                    netype="XGW",
                    vendor="ZTE",
                    vnfSoftwareVersion="V1",
                    version="V1",
                    package_id="2",
                    status='INSTANTIATED').save()
        response = self.rc.patch(
            "http://*****:*****@mock.patch.object(UpdateVnf, 'run')
    def test_update_vnf_etag_match(self, mock_run):
        instanceid = "18"
        NfInstModel(nfinstid=instanceid,
                    nf_name='VNF1',
                    nf_desc="VNF DESC",
                    vnfdid="1",
                    netype="XGW",
                    vendor="ZTE",
                    vnfSoftwareVersion="V1",
                    version="V1",
                    package_id="2",
                    status='INSTANTIATED').save()
        resp = self.client.get("/api/vnflcm/v1/vnf_instances/18",
                               format='json')
        etag = resp["ETag"]
        response = self.rc.patch(
            "http://*****:*****@mock.patch.object(restcall, 'call_req')
    def test_update_vnf_success(self, mock_call_req):
        instanceid = "12"
        NfInstModel(nfinstid=instanceid,
                    nf_name='VNF1',
                    nf_desc="VNF DESC",
                    vnfdid="1",
                    netype="XGW",
                    vendor="ZTE",
                    vnfSoftwareVersion="V1",
                    version="V1",
                    package_id="2",
                    status='INSTANTIATED').save()
        mock_call_req.return_value = [0, {}, status.HTTP_202_ACCEPTED]
        job_id = JobUtil.create_job('NF', 'UPDATETEST', instanceid)
        UpdateVnf(self.upd_data, instanceid, job_id).run()
        name = NfInstModel.objects.filter(nfinstid=instanceid).get().nf_name
        NfInstModel.objects.filter(nfinstid=instanceid).delete()
        self.assertEqual("vnf new name", name)
コード例 #6
0
class TestRooms(APITestCase):

    def setUp(self):
        self.client = RequestsClient()

        # Create 2 customer and 2 room manager users
        self.user1 = User.objects.create(username='******', password='******',
                                         is_room_manager=True)
        self.user2 = User.objects.create(username='******', password='******',
                                         is_customer=True)
        self.user3 = User.objects.create(username='******', password='******',
                                         is_customer=True)
        self.user4 = User.objects.create(username='******', password='******',
                                         is_customer=True)

        # Generate tokens for the users
        self.token1 = Token.objects.create(user=self.user1)
        self.token2 = Token.objects.create(user=self.user2)
        self.token3 = Token.objects.create(user=self.user3)
        self.token4 = Token.objects.create(user=self.user4)

        # Create room objects
        Room.objects.create(name="Sample Room1", num_days_in_adv=2, owner=self.user1)
        Room.objects.create(name="Sample Room2", num_days_in_adv=7, owner=self.user3)

    # Call create room without authentication
    def test_rooms_create_as_customer(self):
        response = self.client.post('http://localhost:8000/api/rooms', {"name": "SampleRoom", "num_days_in_adv": 3})
        self.assertEquals(response.status_code, 401 or 403)
        self.assertEquals(Room.objects.all().count(), 2)

    # Call create as customer user
    def test_rooms_create_without_auth(self):
        response = self.client.post('http://localhost:8000/api/rooms', {"name": "SampleRoom", "num_days_in_adv": 3},
                                    headers={"Authorization": "token " + str(self.token2)})
        self.assertEquals(response.status_code, 403)
        self.assertEquals(Room.objects.all().count(), 2)

    # Call create room with incomplete input fields
    def test_rooms_create_incomplete_input(self):
        response = self.client.post('http://localhost:8000/api/rooms', {"name": "SampleRoom"},
                                    headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 400)
        self.assertEquals(Room.objects.all().count(), 2)

    # Call create room with right all fields and authentication
    def test_rooms_create(self):
        response = self.client.post('http://localhost:8000/api/rooms', {"name": "SampleRoom", "num_days_in_adv": 3},
                                    headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 201)
        self.assertEquals(Room.objects.all().count(), 3)

    # Call get rooms without authentication
    def test_rooms_get_without_auth(self):
        response = self.client.get('http://localhost:8000/api/rooms')
        self.assertEquals(response.status_code, 401)

    # Call get rooms as customer
    def test_rooms_get_as_customer(self):
        response = self.client.get('http://localhost:8000/api/rooms',
                                   headers={"Authorization": "token " + str(self.token2)})
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.json()), 2)

    # Call get rooms as room manager
    def test_rooms_get_as_room_manager(self):
        response = self.client.get('http://localhost:8000/api/rooms',
                                   headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.json()), 1)  # Gets only the room he owns

    # Call retrieve specific room without authentication
    def test_rooms_retrieve_without_auth(self):
        response = self.client.get('http://localhost:8000/api/rooms/1')
        self.assertEquals(response.status_code, 401)

    # Call retrieve specific room as customer
    def test_rooms_retrieve_as_customer(self):
        response = self.client.get('http://localhost:8000/api/rooms/1',
                                   headers={"Authorization": "token " + str(self.token2)})
        self.assertEquals(response.status_code, 403)

    # Call retrieve specific room as other room manager (not the owner)
    def test_rooms_retrieve_as_not_owner(self):
        response = self.client.get('http://localhost:8000/api/rooms/1',
                                   headers={"Authorization": "token " + str(self.token3)})
        self.assertEquals(response.status_code, 403)

    # Call retrieve specific room as the owner
    def test_rooms_retrieve_as_owner(self):
        response = self.client.get('http://localhost:8000/api/rooms/1',
                                   headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 200)

    # Call update (patch) specific room without authentication
    def test_rooms_update_without_auth(self):
        response = self.client.patch('http://localhost:8000/api/rooms/1',
                                     {"name": "Other Room"})
        self.assertEquals(response.status_code, 401)

    # Call update (patch) specific room as customer
    def test_rooms_update_as_customer(self):
        response = self.client.patch('http://localhost:8000/api/rooms/1',
                                     {"name": "Other Room"},
                                     headers={"Authorization": "token " + str(self.token2)})
        self.assertEquals(response.status_code, 403)

    # Call update (patch) specific room as other room manager (not the owner)
    def test_rooms_update_as_not_owner(self):
        response = self.client.patch('http://localhost:8000/api/rooms/1',
                                     {"name": "Other Room"},
                                     headers={"Authorization": "token " + str(self.token3)})
        self.assertEquals(response.status_code, 403)

    # Call update (patch) specific room as the owner
    def test_rooms_update_as_owner(self):
        response = self.client.patch('http://localhost:8000/api/rooms/1',
                                     {"name": "Other Room"},
                                     headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 200)

    # Call delete specific room without authentication
    def test_rooms_delete_without_auth(self):
        response = self.client.delete('http://localhost:8000/api/rooms/1')
        self.assertEquals(response.status_code, 401)
        self.assertEquals(Room.objects.all().count(), 2)

    # Call delete specific room as customer
    def test_rooms_delete_as_customer(self):
        response = self.client.delete('http://localhost:8000/api/rooms/1',
                                      headers={"Authorization": "token " + str(self.token2)})
        self.assertEquals(response.status_code, 403)
        self.assertEquals(Room.objects.all().count(), 2)

    # Call delete specific room as other room manager (not the owner)
    def test_rooms_delete_as_not_owner(self):
        response = self.client.delete('http://localhost:8000/api/rooms/1',
                                      headers={"Authorization": "token " + str(self.token3)})
        self.assertEquals(response.status_code, 403)
        self.assertEquals(Room.objects.all().count(), 2)

    # Call delete specific room as the owner
    def test_rooms_delete_as_owner(self):
        response = self.client.delete('http://localhost:8000/api/rooms/1',
                                      headers={"Authorization": "token " + str(self.token1)})
        self.assertEquals(response.status_code, 204)
        self.assertEquals(Room.objects.all().count(), 1)
コード例 #7
0
ファイル: tests.py プロジェクト: andrefpf/desafioleve
class ExampleTest(TestCase):

    def setUp(self):
        self.client = RequestsClient()

    def test_example(self):
        INPUT_USERS = [ 
            {
                'name' : 'João da Silva', 
                'cpf' : '12345678900', 
                'birthday' : '1980-08-05',
            },
            {
                'name' : 'Luke Skywalker', 
                'cpf' : '12345678901', 
                'birthday' : '1975-05-10',
            },
        ]

        INPUT_SALARIES = [
            {
                'date' : '2020-12-17',
                'cpf' : '12345678900',
                'salary' : '2000.00',
                'discount' : '2.00',
            },

            {
                'date' : '2020-12-17',
                'cpf' : '12345678900',
                'salary' : '5000.00',
                'discount' : '4.00',
            },

            {
                'date' : '2020-12-17',
                'cpf' : '12345678901',
                'salary' : '500.00',
                'discount' : '4.00',
            },

            {
                'date' : '2020-12-17',
                'cpf' : '12345678901',
                'salary' : '300.00',
                'discount' : '8.00',
            },

            {
                'date' : '2020-12-17',
                'cpf' : '12345678901',
                'salary' : '45678.00',
                'discount' : '22.71',
            },
        ]

        EXPECTED_USERS_OUTPUT = [
            {   
                'pk' : 1,
                'name' : 'João da Silva Sauro', 
                'cpf' : '12345678900', 
                'birthday' : '1980-08-05',
                'average_salary' : 3000.00,
                'average_discounts' : 3.00,
                'bigger_salary' : 4000,
                'smaller_salary' : 2000,
            },
            {
                'pk' : 2,
                'name' : 'Luke Skywalker', 
                'cpf' : '12345678901', 
                'birthday' : '1975-05-10',
                'average_salary' : 400.00,
                'average_discounts' : 6.00,
                'bigger_salary' : 500,
                'smaller_salary' : 300,
            },
        ]

        EXPECTED_SALARIES_OUTPUT = [
            {
                'pk' : 1,
                'date' : '2020-12-17',
                'cpf' : '12345678900',
                'salary' : '2000.00',
                'discount' : '2.00',
            },

            {
                'pk' : 2,
                'date' : '2020-12-17',
                'cpf' : '12345678900',
                'salary' : '4000.00',
                'discount' : '4.00',
            },

            {   
                'pk' : 3,
                'date' : '2020-12-17',
                'cpf' : '12345678901',
                'salary' : '500.00',
                'discount' : '4.00',
            },

            {
                'pk' : 4,
                'date' : '2020-12-17',
                'cpf' : '12345678901',
                'salary' : '300.00',
                'discount' : '8.00',
            },
        ]

        EXPECTED_GLOBAL_OUTPUT = {
            'average_salary' : 1700.00,
            'average_discount' : 4.50,
            'bigger_salary' : 4000.00,
            'smaller_salary' : 300,
        }

        URL = 'http://testserver/'


        for data in INPUT_USERS:
            self.client.post(URL + 'users/', data)

        for data in INPUT_SALARIES:
            self.client.post(URL + 'salaries/', data)

        self.client.patch(URL + 'users/1/', {'name':'João da Silva Sauro'})
        self.client.patch(URL + 'salaries/2/', {'salary' : '4000.00'})
        self.client.delete(URL + 'salaries/5/')

        response = self.client.get(URL + 'users/')
        assert response.json() == EXPECTED_USERS_OUTPUT

        response = self.client.get(URL + 'salaries/')
        assert response.json() == EXPECTED_SALARIES_OUTPUT

        response = self.client.get(URL + 'global/')
        assert response.json() == EXPECTED_GLOBAL_OUTPUT
コード例 #8
0
ファイル: tests.py プロジェクト: andrefpf/desafioleve
class CRUDTests(TestCase):
    def setUp(self):
        self.client = RequestsClient()
    
    def test_user(self):
        INPUT_DATA = [ 
            {
                'name':'André Fernandes', 
                'cpf':'12345678902', 
                'birthday':'2000-01-01'
            },
            {
                'name':'João da Silva', 
                'cpf':'12345678900', 
                'birthday':'1980-08-05'
            },
            {
                'name':'Luke Skywalker', 
                'cpf':'12345678901', 
                'birthday':'1975-05-10',
            },
        ]

        PATCH_DATA = {'name':'João da Silva Sauro'}
        
        PUT_DATA = {
            'name':'Lucas Andarilho do Céu', 
            'cpf':'12345678910', 
            'birthday':'1976-06-11',
        }

        EXPECTED_OUTPUT = [
            {
                'pk':1,
                'name':'João da Silva Sauro',
                'cpf':'12345678900',
                'birthday':'1980-08-05',
                'average_salary':0,
                'average_discounts':0,
                'bigger_salary':0,
                'smaller_salary':0,
            },
            {
                'pk':2,
                'name':'Lucas Andarilho do Céu',
                'cpf':'12345678910',
                'birthday':'1976-06-11',
                'average_salary':0,
                'average_discounts':0,
                'bigger_salary':0,
                'smaller_salary':0,
            },
        ]

        URL = 'http://testserver/'

        for i, data in enumerate(INPUT_DATA):
            self.client.post(URL + f'users/{i}/', data)

        self.client.patch(URL + 'users/1/', PATCH_DATA)
        self.client.put(URL + 'users/2/', PUT_DATA)
        self.client.delete(URL + 'users/0/')

        response = self.client.get(URL + 'users/1/')
        assert response.json() == EXPECTED_OUTPUT[0]

        response = self.client.get(URL + 'users/2/')
        assert response.json() == EXPECTED_OUTPUT[1]

        response = self.client.post(URL + 'users/1/', INPUT_DATA[0])
        assert response.status_code == 409

        response = self.client.get(URL + 'users/0/')
        assert response.status_code == 404

    def test_salary(self):
        INPUT_DATA = [
            {
                'date' : '2020-12-17',
                'cpf' : '12345678900',
                'salary' : '2000.00',
                'discount' : '2.00',
            },
            {
                'date' : '2019-11-01',
                'cpf' : '12345678908',
                'salary' : '509.00',
                'discount' : '4.00',
            },
            {
                'date' : '2020-12-17',
                'cpf' : '98765432100',
                'salary' : '98000.00',
                'discount' : '1.00',
            },
        ]

        PATCH_DATA = {'date':'2020-09-16'}
        
        PUT_DATA = {
            'date' : '2012-11-01',
            'cpf' : '12345678988',
            'salary' : '220.00',
            'discount' : '3.00',
        }

        EXPECTED_OUTPUT = [
            {
                'pk' : 0,
                'date' : '2020-09-16',
                'cpf' : '12345678900',
                'salary' : '2000.00',
                'discount' : '2.00',
            },
            {   
                'pk' : 2,
                'date' : '2012-11-01',
                'cpf' : '12345678988',
                'salary' : '220.00',
                'discount' : '3.00',
            },
        ]

        URL = 'http://testserver/'

        for i, data in enumerate(INPUT_DATA):
            self.client.post(URL + f'salaries/{i}/', data)

        self.client.patch(URL + 'salaries/0/', PATCH_DATA)
        self.client.put(URL + 'salaries/2/', PUT_DATA)
        self.client.delete(URL + 'salaries/1/')

        response = self.client.get(URL + 'salaries/0/')
        assert response.json() == EXPECTED_OUTPUT[0]

        response = self.client.get(URL + 'salaries/2/')
        assert response.json() == EXPECTED_OUTPUT[1]

        response = self.client.post(URL + 'salaries/0/', INPUT_DATA[0])
        assert response.status_code == 409

        response = self.client.get(URL + 'salaries/1/')
        assert response.status_code == 404
コード例 #9
0
ファイル: test_certs.py プロジェクト: roleyfoley/chambers-app
def test_integration_workflow(mock_post_message, mock_post_document):
    """
    Primitive but correct integration test, which creates certificate, uploads
    some dumb documents and marks it as "lodged".
    Doesn't check error-handling code branches (incorrect input, auth and so on),
    just displays that the workflow works fine in general.
    More specific unit tests are expected to test error handling and complicated cases
    (like document removed from the certificate and the certificate is not ready for
    lodging anymore).
    """
    mock_post_document.return_value = {
        "multihash": "QmNTWr4pXQcFd49PwgLBAPGjaedLkLXQU1c2EqfKV3K8RJ"
    }

    u1 = UserFactory()
    org = OrgFactory()

    c = RequestsClient()
    c.auth = HTTPBasicAuth(u1.username, 'password')

    message_body = {
        "org":
        str(org.pk),
        "dst_country":
        "CN",
        "exporter_info":
        "value",
        "producer_info":
        "value 02",
        "importer_info":
        "value 03",
        "goods_descr":
        "value of the goods description, which may be quite long or contain newlines",
    }

    mock_post_message.return_value = message_body.copy()

    # create some certificate
    resp = c.post('http://testserver/api/certificate/v0/certificate/',
                  data=message_body)
    assert resp.status_code == 201
    assert 'id' in resp.json()
    cert_id = resp.json().get('id')

    cert = Certificate.objects.get(org=org, pk=cert_id)

    assert cert.dst_country == 'CN'

    # upload some file
    cert.refresh_from_db()

    assert cert.status == cert.STATUS_DRAFT

    for file_type in (CertificateDocument.TYPE_INFORMATION_FORM,
                      CertificateDocument.TYPE_EVIDENCE_OF_ORIGIN):
        factory = APIRequestFactory()
        data = {'type': file_type, 'file': open('pytest.ini')}
        content = encode_multipart('BoUnDaRyStRiNg', data)
        content_type = 'multipart/form-data; boundary=BoUnDaRyStRiNg'
        request = factory.post(
            f'http://testserver/api/certificate/v0/certificate/{cert_id}/document/',
            content,
            content_type=content_type)
        request.user = u1
        resp = DocumentUploadView.as_view()(request, pk=cert.pk)

        print(resp)
        assert resp.status_code == 201

    cert.refresh_from_db()
    assert cert.status == cert.STATUS_COMPLETE

    # mark as lodged

    resp = c.patch(
        f'http://testserver/api/certificate/v0/certificate/{cert_id}/status/',
        data={"status": "lodged"})
    assert resp.status_code == 200

    cert.refresh_from_db()
    assert cert.status == cert.STATUS_SENT