Esempio n. 1
0
    def test_data_copy_paste(self):
        "Test data copy and paste interface"

        url = reverse('copy_object')
        clear_url = reverse('clear_clipboard')
        paste_url = reverse('ajax_paste')
        data = {"clipboard": "data", "uid": self.data.uid}

        request = fake_request(url=url, data=data, user=self.owner)
        response = ajax.copy_object(request=request)

        clear_request = fake_request(url=clear_url, data=data, user=self.owner)
        clear_response = ajax.ajax_clear_clipboard(request=clear_request)

        self.process_response(response=response, stat=200, data={})
        self.process_response(response=clear_response, stat=200, data={})

        # Copy again and paste this time
        request = fake_request(url=url, data=data, user=self.owner)
        response = ajax.copy_object(request=request)

        paste_request = fake_request(url=paste_url, data=data, user=self.owner)
        paste_response = ajax.ajax_paste(request=paste_request)

        self.process_response(response=response, stat=200, data={})
        self.process_response(response=paste_response, stat=200, data={})
Esempio n. 2
0
    def test_snippet_form(self):
        """
        Test function that renders the snippet create/edit form.
        """
        # Populate form with category data
        category_data = {
            'is_category': int(True),
            'type_name': self.snippet_type.name,
            'type_uid': self.snippet_type.uid
        }

        # Populate form with snippet data.
        snippet_data = {
            'is_category': int(False),
            'snippet_uid': self.snippet.uid,
            'snippet': self.snippet.command,
            'help_text': self.snippet.help_text
        }

        url = reverse('snippet_form')

        # Test rendering category form
        request = fake_request(url=url, data=category_data, user=self.owner)
        json_response = ajax.snippet_form(request)
        self.process_response(json_response)

        # Test rendering snippet form
        request = fake_request(url=url, data=snippet_data, user=self.owner)
        json_response = ajax.snippet_form(request)

        self.process_response(json_response)
Esempio n. 3
0
    def test_api(self):
        """Test post creation with POST request"""

        url = reverse("api_stats_on_day", kwargs=dict(day=0))

        request = fake_request(url=url, data={}, user=self.owner)

        response = api.daily_stats_on_day(request=request, day=0)

        #print(response, response.content)
        self.assertEqual(response.status_code, 404)

        date = datetime.datetime.now() - datetime.timedelta(days=1)
        stats = api.compute_stats(date)
        #print(date, stats)

        url = reverse("api_stats_on_date",
                      kwargs=dict(year=2020, month=10, day=1))

        request = fake_request(url=url, data={}, user=self.owner)

        response = api.daily_stats_on_date(request=request,
                                           year=2020,
                                           month=10,
                                           day=1)
        self.assertEqual(response.status_code, 200)
Esempio n. 4
0
    def test_job_file_copy(self):
        "Test the job file copying interface"

        data = {settings.CLIPBOARD_NAME: const.COPIED_FILES, 'path': self.job.get_data_dir()}
        copy_url = reverse("job_file_copy", kwargs=dict(uid=self.job.uid, path=self.job.get_data_dir()))
        copy_request = fake_request(url=copy_url, data=data, user=self.owner)
        copy_response = views.job_file_copy(request=copy_request, uid=self.job.uid, path=self.job.get_data_dir())
        self.process_response(copy_response, data={})

        paste_url = reverse("file_paste", kwargs=dict(uid=self.project.uid))
        paste_request = fake_request(url=paste_url, data=data, user=self.owner)
        paste_response = views.file_paste(request=paste_request, uid=self.project.uid)
        self.process_response(paste_response, data={})
Esempio n. 5
0
    def test_create_view(self):
        "Test project create view with POST request"

        path = os.path.join(TEST_DIR, "data", "image.png")
        image_stream = open(path, "rb")

        # Create fake request
        data = {
            'name': 'My project',
            'uid': 'example',
            "summary": "summary",
            "rank": 100,
            'text': 'tested',
            "privacy": models.Project.PRIVATE,
            "image": image_stream,
            "label": "foo"
        }

        request = fake_request(url=reverse('project_create'),
                               data=data,
                               user=self.owner)
        response = views.project_create(request)

        image_stream.close()

        self.process_response(response=response, data=data, save=True)
Esempio n. 6
0
    def test_data_upload(self):
        "Test Data upload POST request"

        data = {
            'file': open(__file__, 'r'),
            'summary': 'summary',
            "text": "tested",
        }

        url = reverse('data_upload', kwargs=dict(uid=self.project.uid))

        # Create a new user and give them upload access
        user = models.User.objects.create_user(username="******",
                                               email="*****@*****.**")
        user.set_password("tested")
        user.save()
        access = models.Access(access=models.Access.WRITE_ACCESS,
                               user=user,
                               project=self.project)
        access.save()

        request = fake_request(url=url, data=data, user=user)
        response = views.data_upload(request=request, uid=self.project.uid)

        self.process_response(response=response, data=data, save=True)
Esempio n. 7
0
    def test_drag_and_drop(self):
        """
        Test AJAX function used to drag and drop.
        """

        # Create comment to self.parent
        comment1 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=self.post)
        # Create another post with parent being above comment
        comment2 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=comment1)
        comment3 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=comment2)

        # Move comment3 to comment1
        data = {'parent': comment1.uid, 'uid': comment3.uid}
        url = reverse('drag_and_drop')
        request = fake_request(url=url, data=data, user=self.owner)
        json_response = ajax.drag_and_drop(request)
        self.process_response(json_response)
    def test_bin_view(self):
        "Test recycle bin view"

        url = reverse('recycle_bin')
        request = fake_request(url=url, data={}, method="GET", user=self.user)
        response = views.recycle_bin(request=request)
        self.assertEqual(response.status_code, 200, "Can not load recyle bin")
Esempio n. 9
0
    def test_comment_traversal(self):
        """Test comment rendering pages"""

        # Create a couple of comments to traverse

        comment = models.Post.objects.create(title="Test",
                                             author=self.owner,
                                             content="Test",
                                             type=models.Post.COMMENT,
                                             root=self.post,
                                             parent=self.post)
        comment2 = models.Post.objects.create(title="Test",
                                              author=self.owner,
                                              content="Test",
                                              type=models.Post.COMMENT,
                                              root=self.post,
                                              parent=comment)

        url = reverse("post_view", kwargs=dict(uid=self.post.uid))

        request = fake_request(url=url, data={}, user=self.owner)

        response = views.post_view(request=request, uid=self.post.uid)

        self.assertTrue(response.status_code == 200,
                        'Error rendering comments')
Esempio n. 10
0
    def test_job_rerun(self):
        "Test Job rerun"
        url = reverse('job_delete', kwargs=dict(uid=self.job.uid))

        request = fake_request(url=url, data={}, user=self.owner)

        response = views.job_rerun(request=request, uid=self.job.uid)
        self.process_response(response=response, data={})
Esempio n. 11
0
    def preform_votes(self, post, user):
        for vtype in ["upvote", "bookmark", "accept"]:

            data = {"vote_type": vtype, "post_uid": post.uid}
            request = fake_request(url=reverse('vote'), data=data, user=user)
            response = ajax.ajax_vote(request)
            self.assertEqual(response.status_code, 200,
                             f"Could not preform vote:{vtype}.")
    def test_create_view(self):
        "Test project create view with POST request"

        request = fake_request(url=reverse('project_create'),
                               data={},
                               user=self.owner)
        response = views.project_create(request)

        self.process_response(response=response, data={}, save=True)
Esempio n. 13
0
    def test_import_file(self):
        "Test import files tab view"
        url = reverse('file_list', kwargs=dict(path=' '))

        request = fake_request(url=url, data={}, user=self.owner)

        response = views.import_files(request, path=' ')

        self.assertEqual(response.status_code, 200, f"Error with file listing in import tab.")
Esempio n. 14
0
    def test_data_file_copy_paste(self):
        "Test the data file copying interface"
        url = reverse("data_file_copy", kwargs=dict(uid=self.data.uid, path=self.data.get_data_dir()))
        data = {settings.CLIPBOARD_NAME: const.COPIED_FILES, 'path':self.data.get_data_dir()}
        request = fake_request(url=url, data=data, user=self.owner)

        response = views.data_file_copy(request=request, uid=self.data.uid, path=self.data.get_data_dir())

        self.process_response(response, data={})
    def test_profile(self):
        "Test profile with a logged in user with GET Request"
        data = {}
        url = reverse("user_profile", kwargs=dict(uid=self.user.profile.uid))

        request = fake_request(url=url, data=data, user=self.user, method="GET")

        response = views.user_profile(request=request, uid=self.user.profile.uid)
        self.assertEqual(response.status_code, 200, "Can not load user profile")
    def test_site_admin(self):
        "Test site admin page"

        url = reverse("site_admin")
        request = fake_request(url=url, data={}, method="GET", user=self.user)

        response = views.site_admin(request=request)
        # admin page specific to biostar-engine.
        self.assertEqual(response.status_code, 200, "Can not load admin page")
Esempio n. 17
0
    def test_data_delete(self):
        "Test the data delete"

        url = reverse('data_delete', kwargs=dict(uid=self.data.uid))

        request = fake_request(url=url, data={}, user=self.owner)

        response = views.data_delete(request=request, uid=self.data.uid)

        self.process_response(response=response, data={})
Esempio n. 18
0
    def test_notify(self):
        "Test the notification toggling"

        url = reverse("toggle_notify")

        request = fake_request(url=url, data={}, user=self.user)

        response = views.toggle_notify(request=request)

        self.assertEqual(response.status_code, 302)
Esempio n. 19
0
    def test_recipe_delete(self):
        "Test reset delete"

        url = reverse('recipe_delete', kwargs=dict(uid=self.recipe.uid))

        request = fake_request(url=url, data={}, user=self.owner)

        response = views.recipe_delete(request=request, uid=self.recipe.uid)

        self.process_response(response=response, data={})
Esempio n. 20
0
    def test_recipe_copy(self):
        "Test recipe copy interface"

        url = reverse('recipe_copy', kwargs=dict(uid=self.recipe.uid))

        request = fake_request(url=url, data={}, user=self.owner)

        response = views.recipe_copy(request=request, uid=self.recipe.uid)

        self.process_response(response=response, data={})
Esempio n. 21
0
    def test_publish(self):
        """ Test herald publish """

        # Create fake request
        request = fake_request(url=reverse('herald_publish'), data={}, method='GET', user=self.staff_user)
        response = herald.herald_publish(request=request)

        self.assertNotEqual(response.url, reverse('herald_list'), "could not publish ")

        pass
Esempio n. 22
0
    def test_job_edit(self):
        "Test job edit with POST request"

        data = {'name': 'tested', 'text': "tested"}
        url = reverse('job_edit', kwargs=dict(uid=self.job.uid))

        request = fake_request(url=url, data=data, user=self.owner)

        response = views.job_edit(request=request, uid=self.job.uid)
        self.process_response(response=response, data=data, save=True)
Esempio n. 23
0
    def test_recipe_create(self):
        "Test recipe create with POST request"
        data = {"name": "tested", "summary": "summary", "text": "text", "rank": 100,
                "uid": "tested", 'json_text':'{}', 'template':'# Code here'}
        url = reverse('recipe_edit', kwargs=dict(uid=self.project.uid))

        request = fake_request(url=url, data=data, user=self.owner)

        response = views.recipe_create(request=request, uid=self.project.uid)
        self.process_response(response=response, data=data, save=True)
    def test_disable(self):
        """
        Test project disabling function
        """

        url = reverse('email_disable', kwargs=dict(uid=self.owner.pk))

        request = fake_request(url=url, data={}, user=self.owner)
        json_response = ajax.email_disable(request, uid=self.owner.pk)
        self.process_response(json_response)
Esempio n. 25
0
    def test_recipe_code_download(self):
        "Test recipe code download "

        url = reverse("recipe_download", kwargs=dict(uid=self.recipe.uid))
        request = fake_request(url=url, data={}, user=self.owner)
        response = views.recipe_code_download(request=request, uid=self.recipe.uid)

        self.assertTrue(response.content.decode() == self.recipe.template,
                        f"Error downloading code. Expected: {self.recipe.template} "
                        f"received: {response.content.decode()}")
    def test_recipe_code_download(self):
        "Test recipe code download "

        url = self.recipe.download_url()
        request = fake_request(url=url, data={}, user=self.owner)
        response = views.recipe_code_download(request=request, uid=self.recipe.uid, fname="recipe.sh")

        self.assertTrue(response.content.decode() == self.recipe.template,
                        f"Error downloading code. Expected: {self.recipe.template} "
                        f"received: {response.content.decode()}")
Esempio n. 27
0
    def test_submit(self):
        """Test herald submissions"""

        # Create fake request
        data = {'url': "https://google.com", 'text': 'This is a test link'}

        request = fake_request(url=reverse('herald_list'), data=data, user=self.owner)
        response = herald.herald_list(request=request)

        self.assertEqual(response.status_code, 302, f"Could not redirect :\nresponse:{response}")
Esempio n. 28
0
    def test_digest(self):
        """
        Test AJAX function that toggles users digest options
        """

        data = {'pref': 'daily'}

        url = reverse('ajax_digest')
        request = fake_request(url=url, data=data, user=self.owner)
        json_response = ajax.ajax_digest(request)
        self.process_response(json_response)
Esempio n. 29
0
    def test_duplicate_post(self):
        "Test duplicate post moderation"

        data = {"dupe": "google.com"}

        url = reverse('post_moderate', kwargs=dict(uid=self.post.uid))
        request = fake_request(url=url, data=data, user=self.owner)
        response = views.post_moderate(request=request, uid=self.post.uid)
        self.process_response(response)

        pass
Esempio n. 30
0
    def test_post_answer(self):
        """
        Test submitting answer through the post view
        """
        url = reverse("post_view", kwargs=dict(uid=self.post.uid))

        # Get form data
        data = dict(content="testing answer", parent_uid=self.post.uid)
        request = fake_request(url=url, data=data, user=self.owner)
        response = views.post_view(request=request, uid=self.post.uid)
        return