예제 #1
0
    def setUp(self):
        OsfTestCase.setUp(self)

        self.user = AuthUserFactory()
        self.me = AuthUserFactory()
        self.project = ProjectFactory(creator=self.me,
                                      is_public=True,
                                      title=fake.bs())
        self.component = NodeFactory(creator=self.me,
                                     project=self.project,
                                     is_public=True,
                                     title=fake.bs())
    def test_node_child_filtering(self, app, user):
        project = ProjectFactory(creator=user)

        title_one, title_two = fake.bs(), fake.bs()
        component = NodeFactory(title=title_one, parent=project)
        component_two = NodeFactory(title=title_two, parent=project)

        url = '/{}nodes/{}/children/?filter[title]={}'.format(
            API_BASE, project._id, title_one)
        res = app.get(url, auth=user.auth)

        ids = [node['id'] for node in res.json['data']]

        assert component._id in ids
        assert component_two._id not in ids
예제 #3
0
    def test_node_child_filtering(self):
        user = AuthUserFactory()
        project = ProjectFactory(creator=user)

        title1, title2 = fake.bs(), fake.bs()
        component = NodeFactory(title=title1, parent=project)
        component2 = NodeFactory(title=title2, parent=project)

        url = "/{}nodes/{}/children/?filter[title]={}".format(API_BASE, project._id, title1)
        res = self.app.get(url, auth=user.auth)

        ids = [node["id"] for node in res.json["data"]]

        assert_in(component._id, ids)
        assert_not_in(component2._id, ids)
예제 #4
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)
예제 #5
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)
예제 #6
0
    def test_send_with_sendgrid_success(self):
        mock_client = mock.MagicMock()
        mock_client.send.return_value = 200, 'success'
        from_addr, to_addr = fake_email(), fake_email()
        category1, category2 = fake.word(), fake.word()
        subject = fake.bs()
        message = fake.text()
        ret = _send_with_sendgrid(
            from_addr=from_addr,
            to_addr=to_addr,
            subject=subject,
            message=message,
            mimetype='html',
            client=mock_client,
            categories=(category1, category2)
        )
        assert_true(ret)

        assert_equal(mock_client.send.call_count, 1)
        # First call's argument should be a Mail object with
        # the correct configuration
        first_call_arg = mock_client.send.call_args[0][0]
        assert_is_instance(first_call_arg, sendgrid.Mail)
        assert_equal(first_call_arg.from_email, from_addr)
        assert_equal(first_call_arg.to[0], to_addr)
        assert_equal(first_call_arg.subject, subject)
        assert_in(message, first_call_arg.html)
        # Categories are set
        assert_equal(first_call_arg.smtpapi.data['category'], (category1, category2))
예제 #7
0
    def test_send_with_sendgrid_success(self):
        mock_client = mock.MagicMock()
        mock_client.send.return_value = 200, 'success'
        from_addr, to_addr = fake.email(), fake.email()
        category1, category2 = fake.word(), fake.word()
        subject = fake.bs()
        message = fake.text()
        ret = _send_with_sendgrid(from_addr=from_addr,
                                  to_addr=to_addr,
                                  subject=subject,
                                  message=message,
                                  mimetype='txt',
                                  client=mock_client,
                                  categories=(category1, category2))
        assert_true(ret)

        assert_equal(mock_client.send.call_count, 1)
        # First call's argument should be a Mail object with
        # the correct configuration
        first_call_arg = mock_client.send.call_args[0][0]
        assert_is_instance(first_call_arg, sendgrid.Mail)
        assert_equal(first_call_arg.from_email, from_addr)
        assert_equal(first_call_arg.to[0], to_addr)
        assert_equal(first_call_arg.subject, subject)
        assert_equal(first_call_arg.text, message)
        # Categories are set
        assert_equal(first_call_arg.smtpapi.data['category'],
                     (category1, category2))
    def test_node_child_filtering(self):
        user = AuthUserFactory()
        project = ProjectFactory(creator=user)

        title1, title2 = fake.bs(), fake.bs()
        component = NodeFactory(title=title1, parent=project)
        component2 = NodeFactory(title=title2, parent=project)

        url = '/{}nodes/{}/children/?filter[title]={}'.format(
            API_BASE, project._id, title1)
        res = self.app.get(url, auth=user.auth)

        ids = [node['id'] for node in res.json['data']]

        assert_in(component._id, ids)
        assert_not_in(component2._id, ids)
예제 #9
0
    def setUp(self):
        OsfTestCase.setUp(self)

        self.user = AuthUserFactory()
        self.me = AuthUserFactory()
        self.project = ProjectFactory(creator=self.me, is_public=True, title=fake.bs())
        self.component = NodeFactory(creator=self.me, project=self.project, is_public=True, title=fake.bs())
예제 #10
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)
예제 #11
0
    def test_node_child_filtering(self, app, user):
        project = ProjectFactory(creator=user)

        title_one, title_two = fake.bs(), fake.bs()
        component = NodeFactory(title=title_one, parent=project)
        component_two = NodeFactory(title=title_two, parent=project)

        url = '/{}nodes/{}/children/?filter[title]={}'.format(
            API_BASE,
            project._id,
            title_one
        )
        res = app.get(url, auth=user.auth)

        ids = [node['id'] for node in res.json['data']]

        assert component._id in ids
        assert component_two._id not in ids
예제 #12
0
 def test_send_with_sendgrid_failure_returns_false(self):
     mock_client = mock.MagicMock()
     mock_client.send.return_value = 400, 'failed'
     from_addr, to_addr = fake_email(), fake_email()
     subject = fake.bs()
     message = fake.text()
     ret = _send_with_sendgrid(from_addr=from_addr,
                               to_addr=to_addr,
                               subject=subject,
                               message=message,
                               client=mock_client)
     assert_false(ret)
예제 #13
0
 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
예제 #14
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)
예제 #15
0
 def test_send_with_sendgrid_failure_returns_false(self):
     mock_client = mock.MagicMock()
     mock_client.send.return_value = 400, 'failed'
     from_addr, to_addr = fake_email(), fake_email()
     subject = fake.bs()
     message = fake.text()
     ret = _send_with_sendgrid(
         from_addr=from_addr,
         to_addr=to_addr,
         subject=subject,
         message=message,
         mimetype='html',
         client=mock_client
     )
     assert_false(ret)
    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
 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)
예제 #18
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)
예제 #19
0
    def test_project_wiki_edit_post_with_new_wname_and_content(self):
        page_name, page_content = fake.catch_phrase(), 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)
예제 #20
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)
예제 #21
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)
예제 #23
0
def make_comment():
    return Comment(id=fake.random_int(), body=fake.bs())
예제 #24
0
def make_comment(with_author=True):
    author = make_author() if with_author else None
    return Comment(id=fake.random_int(), body=fake.bs(), author=author)
예제 #25
0
def make_comment():
    return Comment(id=fake.random_int(), body=fake.bs())