def test_model_guest_creation(api_client, admin_user, model_name): model_data = setup_model(model_name, admin_user) response = api_client.post('/collab/{}/'.format(model_name), data=model_data, HTTP_ACCEPT="application/json") assert_response(response, status.HTTP_401_UNAUTHORIZED)
def test_model_list(admin_api_client, admin_user, model_name): # setup objects obj = create_model(model_name, admin_user) obj.save() response = admin_api_client.get('/collab/{}/'.format(model_name), HTTP_ACCEPT="application/json") assert_response(response, status.HTTP_200_OK, [obj])
def test_task_resource_empty(resource, limit, admin_client, admin_user): task = create_model('tasks', admin_user) task.save() data = {'limit': limit} if limit else {} response = admin_client.get('/collab/tasks/{}/{}/'.format( task.id, resource), data=data, content_type="application/json") assert_response(response, status.HTTP_200_OK, [])
def test_full_hierarchy(admin_api_client, admin_user): dependency = create_model('dependencies', admin_user) dependency.save() dependant_instance_id = dependency.dependent.instance.id response = admin_api_client.get('/collab/annotations/full_hierarchy/', data={'instance': dependant_instance_id}, HTTP_ACCEPT='application/json') expected_response = [dependency.dependency, dependency.dependent] assert_response(response, status.HTTP_200_OK, expected_response)
def test_model_creation(admin_api_client, admin_user, model_name): model_data = setup_model(model_name, admin_user) response = admin_api_client.post('/collab/{}/'.format(model_name), data=model_data, HTTP_ACCEPT='application/json') assert_response(response, status.HTTP_201_CREATED) projects_created = [response.data] response = admin_api_client.get('/collab/{}/'.format(model_name), HTTP_ACCEPT="application/json") assert_eq(response.data, projects_created)
def test_file_fileversion(admin_client, admin_user): fv_obj = create_model('file_versions', admin_user) fv_obj.save() url = '/collab/files/{}/file_version/{}/'.format(fv_obj.file_id, fv_obj.md5hash) response = admin_client.get(url, content_type="application/json") assert_response(response, status.HTTP_404_NOT_FOUND) fv_obj.complete = True fv_obj.save() response = admin_client.get(url, content_type="application/json") assert_response(response, status.HTTP_200_OK, fv_obj)
def test_template(admin_client): response = admin_client.get('/accounts/profile/') assert_response(response, status.HTTP_200_OK) assert 'id' in response.data assert 'username' in response.data assert 'email' in response.data assert 'is_authenticated' in response.data assert response.data['is_authenticated'] is True assert 'is_active' in response.data assert response.data['is_active'] is True assert 'is_staff' in response.data assert response.data['is_staff'] is True assert 'is_superuser' in response.data assert response.data['is_superuser'] is True
def test_file_fileversion(admin_client, admin_user): file_obj = create_model('files', admin_user) file_obj.save() file_version = rand_hash(32) url = '/collab/files/{}/file_version/{}/'.format(file_obj.id, file_version) response = admin_client.post(url, content_type="application/json") obj = {'newly_created': True, 'md5hash': file_version, 'file': file_obj.id} assert_response(response, status.HTTP_201_CREATED, obj) response = admin_client.get(url, content_type="application/json") obj = { 'newly_created': False, 'md5hash': file_version, 'file': file_obj.id } assert_response(response, status.HTTP_200_OK, obj)
def test_model_creation(admin_api_client, admin_user, model_name): model_data = setup_model(model_name, admin_user) response = admin_api_client.post('/collab/{}/'.format(model_name), data=model_data, HTTP_ACCEPT='application/json') # Manually handle matches, where API does not allow creation or # modification of objects, as they're read only if model_name == "matches": assert_response(response, status.HTTP_405_METHOD_NOT_ALLOWED) return assert_response(response, status.HTTP_201_CREATED) projects_created = [response.data] response = admin_api_client.get('/collab/{}/'.format(model_name), HTTP_ACCEPT="application/json") assert_eq(response.data, projects_created)
def test_matchers(admin_client): response = admin_client.get('/collab/matches/matchers/', content_type="application/json") assert_response(response, status.HTTP_200_OK, matchers.matchers_list)
def test_model_guest_list_empty(api_client, model_name): response = api_client.get('/collab/{}/'.format(model_name), HTTP_ACCEPT='application/json') assert_response(response, status.HTTP_401_UNAUTHORIZED)
def test_model_list_empty(admin_api_client, model_name): response = admin_api_client.get('/collab/{}/'.format(model_name), HTTP_ACCEPT='application/json') assert_response(response, status.HTTP_200_OK, [])
def test_strategies(admin_client): response = admin_client.get('/collab/matches/strategies/', content_type="application/json") assert_response(response, status.HTTP_200_OK, strategies.strategies_list)