~launchpad-pqm/launchpad/devel

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
# Copyright 2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Tests for PersonTransferJobs."""

__metaclass__ = type

from lp.testing.layers import LaunchpadZopelessLayer
from lp.registry.enum import PersonTransferJobType
from lp.registry.model.persontransferjob import (
    PersonTransferJob,
    PersonTransferJobDerived,
    )
from lp.testing import TestCaseWithFactory


class PersonTransferJobTestCase(TestCaseWithFactory):
    """Test case for basic PersonTransferJob class."""

    layer = LaunchpadZopelessLayer

    def test_instantiate(self):
        # PersonTransferJob.__init__() instantiates a
        # PersonTransferJob instance.
        person = self.factory.makePerson()
        team = self.factory.makeTeam()

        metadata = ('some', 'arbitrary', 'metadata')
        person_transfer_job = PersonTransferJob(
            person,
            team,
            PersonTransferJobType.MEMBERSHIP_NOTIFICATION,
            metadata)

        self.assertEqual(person, person_transfer_job.minor_person)
        self.assertEqual(team, person_transfer_job.major_person)
        self.assertEqual(
            PersonTransferJobType.MEMBERSHIP_NOTIFICATION,
            person_transfer_job.job_type)

        # When we actually access the PersonTransferJob's metadata it
        # gets unserialized from JSON, so the representation returned by
        # person_transfer_job.metadata will be different from what we
        # originally passed in.
        metadata_expected = [u'some', u'arbitrary', u'metadata']
        self.assertEqual(metadata_expected, person_transfer_job.metadata)


class PersonTransferJobDerivedTestCase(TestCaseWithFactory):
    """Test case for the PersonTransferJobDerived class."""

    layer = LaunchpadZopelessLayer

    def test_create_explodes(self):
        # PersonTransferJobDerived.create() will blow up because it
        # needs to be subclassed to work properly.
        person = self.factory.makePerson()
        team = self.factory.makeTeam()
        metadata = {'foo': 'bar'}
        self.assertRaises(
            AttributeError,
            PersonTransferJobDerived.create, person, team, metadata)