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_update(self): with responses.RequestsMock() as rsps: rsps.add(responses.PUT, "{}/api/2/project/txlib/".format(self.hostname), status=400) rsps.add(responses.GET, "{}/api/2/project/txlib/?details".format(self.hostname), json={"anyone_submit": False}, match_querystring=True, status=200) rsps.add(responses.PUT, "{}/api/2/project/txlib/".format(self.hostname), json={"anyone_submit": True}, status=200) rsps.add(responses.GET, "{}/api/2/project/txlib/?details".format(self.hostname), json={"anyone_submit": True}, match_querystring=True, status=200) rsps.add(responses.DELETE, "{}/api/2/project/txlib/".format(self.hostname), status=200) h = HttpRequest(self.hostname, auth=self.auth) # Using a non-existent attribute for projects data = json.dumps(dict(name='New name', anyone_submitt=True)) path = '/api/2/project/txlib/' with pytest.raises(RequestError): h.put(path, data) # make sure the field has the default value p = h.get(path + '?details') assert p['anyone_submit'] is False # 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') assert p['anyone_submit'] is True # delete the project h.delete(path)