#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Dissemin: open access policy enforcement tool
# Copyright (C) 2014 Antonin Delpeuch
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
from __future__ import unicode_literals

# import unittest
# from mock import Mock

from papers.models import Paper
from deposit.tests import ProtocolTest
from deposit.osf.protocol import OSFProtocol
from deposit.forms import FormWithAbstract
from deposit.osf.forms import OSFForm
# lorem_ipsum contains a sample abstract you can reuse in your test case

class OSFProtocolTest(ProtocolTest):
    @classmethod
    def setUpClass(self):
        # if ''
        super(OSFProtocolTest, self).setUpClass()

        # Fill here the details of your test repository
        self.repo.username = ''
        self.repo.password = ''
        self.repo.endpoint = ''

        # Now we set up the protocol for the tests
        self.proto = OSFProtocol(self.repo)

        # Fill here the details of the metadata form
        # for your repository
        data = {'onbehalfof': ''}
        self.form = self.proto.get_bound_form(data)
        self.form.is_valid() # this validates our sample data

    def test_get_form_initial_data(self):
        paper = Paper.create_by_doi('10.1007/978-3-662-47666-6_5')
        record = paper.oairecords[0]
        record_value = "Supercalifragilisticexpialidocious."
        record.description = record_value
        record.save()

        self.proto.init_deposit(paper, self.user)
        data = self.proto.get_form_initial_data()
        self.assertIsInstance(data, dict)
        self.assertEqual(data.get('abstract'), record_value)

    def test_create_tags(self):
        tags = "Un, Deux, Trois"
        form = OSFForm({"paper_id": 42,
                        "license": "58fd62fcda3e2400012ca5d3",
                        "abstract": "Supercalifragilisticexpialidocious.",
                        "tags": tags})

        self.assertEqual(form['tags'], tags)


@@ -2598,16 +2598,151 @@
  tags%7D)%0A
+        form.is_valid()%0A        print(form.errors)%0A        self.assertTrue(form.is_valid())%0A        data = self.proto.create_tags(form)
 %0A       

Work on test_create_tags() -- 01