1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
# coding: utf8
#
# Copyright (C) 2013 Enrico Zini <enrico@debian.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import debiancontributors as dc
from datetime import date
import unittest
import json
class TestSubmission(unittest.TestCase):
def testIdentifier(self):
i = dc.Identifier("login", "enrico")
self.assertEquals(i.type, "login")
self.assertEquals(i.id, "enrico")
self.assertIsNone(i.desc)
i = dc.Identifier("login", "enrico", "Enrico Zini")
self.assertEquals(i.type, "login")
self.assertEquals(i.id, "enrico")
self.assertEquals(i.desc, "Enrico Zini")
def testMinimalData(self):
s = dc.Submission("test")
s.add_contribution_data(dc.Identifier("login", "enrico"), "upload")
js = s.to_json(indent=1)
res = json.loads(js)
self.assertEquals(res, [{
"id": [ { "type": "login", "id": "enrico" } ],
"contributions": [ { "type": "upload" } ],
}])
def testFullData(self):
s = dc.Submission("test")
s.add_contribution_data(dc.Identifier("login", "enrico"), "upload",
begin=date(2013, 5, 1), end=date(2013, 11, 30),
url="http://www.example.com")
js = s.to_json(indent=1)
res = json.loads(js)
self.assertEquals(res, [{
"id": [ { "type": "login", "id": "enrico" } ],
"contributions": [ { "type": "upload",
"begin": "2013-05-01", "end": "2013-11-30",
"url": "http://www.example.com" } ],
}])
def test_auth_token(self):
s = dc.Submission("test")
self.assertIsNone(s.auth_token)
s.set_auth_token("foo")
self.assertEquals(s.auth_token, "foo")
s.set_auth_token("@" + __file__)
self.assertRegexpMatches(s.auth_token, "def test_auth_token\(")
s = dc.Submission("test", auth_token="foo")
self.assertEquals(s.auth_token, "foo")
s = dc.Submission("test", auth_token="@" + __file__)
self.assertRegexpMatches(s.auth_token, "def test_auth_token\(")
if __name__ == '__main__':
unittest.main()
|