def test_script(self): h = HttpRequest(self.hostname, auth=self.auth) # get a project that does not exist self.assertRaises(NotFoundError, h.get, '/api/2/txlib/') # create a project data = json.dumps(dict(slug='txlib', name='Txlib project')) path = '/api/2/projects/' h.post(path, data=data) # creating the same project results in an error raised. self.assertRaises(ConflictError, h.post, path, data=data) # Using a non-existent attribute for projects data = json.dumps(dict(name='New name', anyone_submitt=True)) path = '/api/2/project/txlib/' self.assertRaises(RequestError, h.put, path, data) # make sure the field has the default value p = h.get(path + '?details') self.assertFalse(p['anyone_submit']) # update the details of the project data = json.dumps(dict(name='New name', anyone_submit=True)) h.put(path, data) # make sure the change has been saved p = h.get(path + '?details') self.assertTrue(p['anyone_submit']) # delete the project h.delete(path)
def test_create(self): with responses.RequestsMock() as rsps: h = HttpRequest(self.hostname, auth=self.auth) # create a project path = '/api/2/projects/' rsps.add(responses.POST, "{}/api/2/projects/".format(self.hostname), status=201) rsps.add(responses.POST, "{}/api/2/projects/".format(self.hostname), status=409) data = json.dumps(dict(slug='txlib', name='Txlib project')) h.post(path, data=data) with pytest.raises(ConflictError): h.post(path, data=data)