示例#1
0
def make_post():
    comments = [make_comment() for _ in range(2)]
    author = make_author()
    return Post(id=fake.random_int(),
                title=fake.catch_phrase(),
                author=author,
                comments=comments)
示例#2
0
    def test_project_wiki_edit_post_with_new_wname_and_content(self):
        # note: forward slashes not allowed in page_name
        page_name = fake.catch_phrase().replace('/', ' ')
        page_content = fake.bs()

        old_wiki_page_count = NodeWikiPage.find().count()
        url = self.project.web_url_for('project_wiki_edit_post',
                                       wname=page_name)
        # User submits to edit form with no content
        res = self.app.post(url, {
            'content': page_content
        },
                            auth=self.user.auth).follow()
        assert_equal(res.status_code, 200)

        new_wiki_page_count = NodeWikiPage.find().count()
        # A new wiki page was created in the db
        assert_equal(new_wiki_page_count, old_wiki_page_count + 1)

        # Node now has the new wiki page associated with it
        self.project.reload()
        new_page = self.project.get_wiki_page(page_name)
        assert_is_not_none(new_page)
        # content was set
        assert_equal(new_page.content, page_content)
示例#3
0
 def test_cannot_update_a_retraction(self):
     registration = RegistrationFactory(creator=self.user, project=self.public_project)
     url = "/{}nodes/{}/".format(API_BASE, registration._id)
     retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator)
     res = self.app.put_json_api(
         url,
         {
             "data": {
                 "id": registration._id,
                 "type": "nodes",
                 "attributes": {
                     "title": fake.catch_phrase(),
                     "description": fake.bs(),
                     "category": "hypothesis",
                     "public": True,
                 },
             }
         },
         auth=self.user.auth,
         expect_errors=True,
     )
     registration.reload()
     assert_equal(res.status_code, 404)
     assert_equal(registration.title, registration.title)
     assert_equal(registration.description, registration.description)
示例#4
0
    def test_cannot_bulk_create_children_on_a_registration(self):
        registration = RegistrationFactory(project=self.project, creator=self.user)
        url = "/{}nodes/{}/children/".format(API_BASE, registration._id)
        res = self.app.post_json_api(
            url,
            {
                "data": [
                    self.child_two,
                    {
                        "type": "nodes",
                        "attributes": {
                            "title": fake.catch_phrase(),
                            "description": fake.bs(),
                            "category": "project",
                            "public": True,
                        },
                    },
                ]
            },
            auth=self.user.auth,
            expect_errors=True,
            bulk=True,
        )
        assert_equal(res.status_code, 404)

        self.project.reload()
        assert_equal(len(self.project.nodes), 0)
示例#5
0
def make_post(with_comments=True, with_author=True):
    comments = [make_comment() for _ in range(2)] if with_comments else []
    author = make_author() if with_author else None
    return Post(id=fake.random_int(),
                title=fake.catch_phrase(),
                author=author,
                comments=comments)
示例#6
0
def make_post():
    comments = [make_comment() for _ in range(2)]
    author = make_author()
    return Post(
        id=fake.random_int(),
        title=fake.catch_phrase(),
        author=author,
        comments=comments)
示例#7
0
def make_post(with_comments=True, with_author=True, with_keywords=True):
    comments = [make_comment() for _ in range(2)] if with_comments else []
    keywords = [make_keyword() for _ in range(3)] if with_keywords else []
    author = make_author() if with_author else None
    return Post(
        id=fake.random_int(),
        title=fake.catch_phrase(),
        author=author,
        author_id=author.id if with_author else None,
        comments=comments,
        keywords=keywords,
    )
 def test_cannot_create_child_on_a_registration(self, app, user, project):
     registration = RegistrationFactory(project=project, creator=user)
     url = '/{}nodes/{}/children/'.format(API_BASE, registration._id)
     res = app.post_json_api(url, {
         'data': {
             'type': 'nodes',
             'attributes': {
                 'title': fake.catch_phrase(),
                 'description': fake.bs(),
                 'category': 'project',
                 'public': True,
             }
         }
     }, auth=user.auth, expect_errors=True)
     assert res.status_code == 404
示例#9
0
 def test_cannot_create_child_on_a_registration(self):
     registration = RegistrationFactory(project=self.project, creator=self.user)
     url = '/{}nodes/{}/children/'.format(API_BASE, registration._id)
     res = self.app.post_json_api(url, {
         'data': {
             'type': 'nodes',
             'attributes': {
                 'title': fake.catch_phrase(),
                 'description': fake.bs(),
                 'category': 'project',
                 'public': True,
             }
         }
     }, auth=self.user.auth, expect_errors=True)
     assert_equal(res.status_code, 404)
示例#10
0
    def test_project_wiki_edit_post_with_new_wname_and_no_content(self):
        page_name = fake.catch_phrase()

        old_wiki_page_count = NodeWikiPage.find().count()
        url = self.project.web_url_for('project_wiki_edit_post', wname=page_name)
        # User submits to edit form with no content
        res = self.app.post(url, {'content': ''}, auth=self.user.auth).follow()
        assert_equal(res.status_code, 200)

        new_wiki_page_count = NodeWikiPage.find().count()
        # A new wiki page was created in the db
        assert_equal(new_wiki_page_count, old_wiki_page_count + 1)

        # Node now has the new wiki page associated with it
        self.project.reload()
        new_page = self.project.get_wiki_page(page_name)
        assert_is_not_none(new_page)
示例#11
0
    def test_cannot_bulk_create_children_on_a_registration(self):
        registration = RegistrationFactory(project=self.project, creator=self.user)
        url = '/{}nodes/{}/children/'.format(API_BASE, registration._id)
        res = self.app.post_json_api(url, {
            'data': [self.child_two, {
                'type': 'nodes',
                'attributes': {
                    'title': fake.catch_phrase(),
                    'description': fake.bs(),
                    'category': 'project',
                    'public': True,
                }
            }]
        }, auth=self.user.auth, expect_errors=True, bulk=True)
        assert_equal(res.status_code, 404)

        self.project.reload()
        assert_equal(len(self.project.nodes), 0)
 def test_cannot_update_a_withdrawn_registration(self):
     url = '/{}registrations/{}/'.format(API_BASE, self.registration._id)
     res = self.app.put_json_api(url, {
         'data': {
             'id': self.registration._id,
             'type': 'nodes',
             'attributes': {
                 'title': fake.catch_phrase(),
                 'description': fake.bs(),
                 'category': 'hypothesis',
                 'public': True
             }
         }
     }, auth=self.user.auth, expect_errors=True)
     self.registration.reload()
     assert_equal(res.status_code, 405)
     assert_equal(self.registration.title, self.registration.title)
     assert_equal(self.registration.description, self.registration.description)
    def test_cannot_bulk_create_children_on_a_registration(self, app, user, project, child_two):
        registration = RegistrationFactory(project=project, creator=user)
        url = '/{}nodes/{}/children/'.format(API_BASE, registration._id)
        res = app.post_json_api(url, {
            'data': [child_two, {
                'type': 'nodes',
                'attributes': {
                    'title': fake.catch_phrase(),
                    'description': fake.bs(),
                    'category': 'project',
                    'public': True,
                }
            }]
        }, auth=user.auth, expect_errors=True, bulk=True)
        assert res.status_code == 404

        project.reload()
        assert len(project.nodes) == 0
示例#14
0
 def test_cannot_update_a_retraction(self):
     registration = RegistrationFactory(creator=self.user, project=self.public_project)
     url = '/{}nodes/{}/'.format(API_BASE, registration._id)
     retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator)
     res = self.app.put_json_api(url, {
         'data': {
             'id': registration._id,
             'type': 'nodes',
             'attributes': {
                 'title': fake.catch_phrase(),
                 'description': fake.bs(),
                 'category': 'hypothesis',
                 'public': True
             }
         }
     }, auth=self.user.auth, expect_errors=True)
     registration.reload()
     assert_equal(res.status_code, 404)
     assert_equal(registration.title, registration.title)
     assert_equal(registration.description, registration.description)
示例#15
0
 def test_cannot_update_a_retraction(self):
     registration = RegistrationFactory(creator=self.user, project=self.public_project)
     url = '/{}nodes/{}/'.format(API_BASE, registration._id)
     retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator)
     res = self.app.put_json_api(url, {
         'data': {
             'id': registration._id,
             'type': 'nodes',
             'attributes': {
                 'title': fake.catch_phrase(),
                 'description': fake.bs(),
                 'category': 'hypothesis',
                 'public': True
             }
         }
     }, auth=self.user.auth, expect_errors=True)
     registration.reload()
     assert_equal(res.status_code, 404)
     assert_equal(registration.title, registration.title)
     assert_equal(registration.description, registration.description)
 def test_cannot_update_a_withdrawn_registration(self):
     url = '/{}registrations/{}/'.format(API_BASE, self.registration._id)
     res = self.app.put_json_api(url, {
         'data': {
             'id': self.registration._id,
             'type': 'nodes',
             'attributes': {
                 'title': fake.catch_phrase(),
                 'description': fake.bs(),
                 'category': 'hypothesis',
                 'public': True
             }
         }
     },
                                 auth=self.user.auth,
                                 expect_errors=True)
     self.registration.reload()
     assert_equal(res.status_code, 405)
     assert_equal(self.registration.title, self.registration.title)
     assert_equal(self.registration.description,
                  self.registration.description)