Ejemplo n.º 1
0
    def test_file_grab_previous_version(self):
        # GIVEN
        # ======
        # Create a new folder
        test_folder = FolderRepo.create_folder(self.user.id, 'folder1')
        self.assertIsNotNone(test_folder)
        # Create a new file
        test_file = FileRepo.create_file(self.user.id, test_folder['id'],
                                         'test.txt', 'Hello World')

        # WHEN
        # ====
        # Publish multiple new versions of the file
        f1 = FileRepo.publish_new_version(self.user.id, test_file['id'],
                                          'Bye World1')
        f2 = FileRepo.publish_new_version(self.user.id, test_file['id'],
                                          'Bye World2')
        f3 = FileRepo.publish_new_version(self.user.id, test_file['id'],
                                          'Bye World3')

        # THEN
        # ====
        # Make sure specific versions can be grabbed
        db_file = FileRepo.get_file_by_version(self.user.id, test_file['id'],
                                               f1['version'])
        self.assertEqual(db_file['content_text'], f1['content_text'])
        self.assertEqual(db_file['version'], f1['version'])
        db_file = FileRepo.get_file_by_version(self.user.id, test_file['id'],
                                               f2['version'])
        self.assertEqual(db_file['content_text'], f2['content_text'])
        self.assertEqual(db_file['version'], f2['version'])
        db_file = FileRepo.get_file_by_version(self.user.id, test_file['id'],
                                               f3['version'])
        self.assertEqual(db_file['content_text'], f3['content_text'])
        self.assertEqual(db_file['version'], f3['version'])
Ejemplo n.º 2
0
def file_edit(request, file_id):
    context = {}
    current_user = request.user

    # TODO: Do this consistently across all of the views
    if not current_user:
        return render('login')

    # Save the file changes and get the updated file's information
    if request.method == "POST":
        new_content = request.POST.get('content')
        file_info = FileRepo.publish_new_version(
            current_user.id, file_id, new_content)
        err_cond = "File publish failed"
    # Get the file the user requested for edit
    else:
        file_info = FileRepo.get_file(current_user.id, file_id)
        err_cond = "File does not exist"

    # No file information to present...deal with the error
    if not file_info:
        context['error'] = err_cond
    # File contents for user to proceed with editing
    else:
        context['id'] = file_info['id']
        context['name'] = file_info['name']
        context['content'] = file_info['content_text']

    return render(request, 'app/file_edit.html', context)
Ejemplo n.º 3
0
    def test_file_history_multiple_versions(self):
        # Login
        self.client.login(username=self.username, password=self.password)
        user_id = self.client.session['_auth_user_id']

        # Create a folder
        new_folder = FolderRepo.create_folder(user_id, 'TestFolder')

        # Place a new file in the above folder
        new_file = FileRepo.create_file(user_id, new_folder['id'],
                                        'TestFile.txt', 'Hello World')
        # Publish a new version of the file we just created
        new_file_ver = FileRepo.publish_new_version(user_id, new_file['id'],
                                                    "Bye World")

        # Navigate to the file history page
        fh_page = self.client.get('/app/file/{}/history/'.format(
            new_file['id']))

        # Validate file history page contents
        self.assertEqual(fh_page.status_code, 200)
        self.assertIn(b'History', fh_page.content)
        self.assertIn(
            bytes(new_file['creation_time'].strftime("%I:%M%p on %B %d, %Y"),
                  'utf-8'), fh_page.content)
        self.assertIn(
            bytes(
                new_file_ver['creation_time'].strftime("%I:%M%p on %B %d, %Y"),
                'utf-8'), fh_page.content)
        self.assertIn(b'[Current Version]', fh_page.content)

        # Logout
        self.client.logout()
Ejemplo n.º 4
0
    def test_file_publish_new_version(self):
        # GIVEN
        # ======
        # Create a new folder
        test_folder = FolderRepo.create_folder(self.user.id, 'folder1')
        self.assertIsNotNone(test_folder)
        # Create a new file
        test_file = FileRepo.create_file(self.user.id, test_folder['id'],
                                         'test.txt', 'Hello World')

        # WHEN
        # ====
        # Publish a new version of the file
        updated_file = FileRepo.publish_new_version(self.user.id,
                                                    test_file['id'],
                                                    'Bye World')

        # THEN
        # ====
        # Make sure the updated file looks good
        self.assertEqual(updated_file['id'], test_file['id'])
        self.assertEqual(updated_file['name'], test_file['name'])
        self.assertEqual(updated_file['content_text'], 'Bye World')
        self.assertGreater(updated_file['version'], test_file['version'])
        # Pull the file and make sure it look database contents look good
        db_file = FileRepo.get_file(self.user.id, test_file['id'])
        # File should be the same as updated_file
        self.assertDictEqual(db_file, updated_file)
Ejemplo n.º 5
0
    def test_file_publish_multiple_new_versions(self):
        # GIVEN
        # ======
        # Create a new folder
        test_folder = FolderRepo.create_folder(self.user.id, 'folder1')
        self.assertIsNotNone(test_folder)
        # Create a new file
        test_file = FileRepo.create_file(self.user.id, test_folder['id'],
                                         'test.txt', 'Hello World')

        # WHEN
        # ====
        # Publish multiple new versions of the file
        FileRepo.publish_new_version(self.user.id, test_file['id'],
                                     'Bye World1')
        FileRepo.publish_new_version(self.user.id, test_file['id'],
                                     'Bye World2')
        FileRepo.publish_new_version(self.user.id, test_file['id'],
                                     'Bye World3')

        # THEN
        # ====
        # Make sure the updated file looks good
        db_file = FileRepo.get_file(self.user.id, test_file['id'])
        self.assertEqual(db_file['id'], test_file['id'])
        self.assertEqual(db_file['name'], test_file['name'])
        self.assertEqual(db_file['content_text'], 'Bye World3')
        self.assertEqual(db_file['version'], 3)