class TestSoftwareCenterAgentAPI(TestCaseWithFactory):

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestSoftwareCenterAgentAPI, self).setUp()
        self.private_root = getUtility(IPrivateApplication)
        self.sca_api = SoftwareCenterAgentAPI(
            context=self.private_root.softwarecenteragent,
            request=LaunchpadTestRequest())

    def test_provides_interface(self):
        # The view interface is provided.
        self.assertProvides(self.sca_api, ISoftwareCenterAgentAPI)

    def test_getOrCreateSoftwareCenterCustomer(self):
        # The method returns the username of the person, and sets the
        # correct creation rational/comment.
        user_name = self.sca_api.getOrCreateSoftwareCenterCustomer(
            u'openid-ident', '*****@*****.**', 'Joe Blogs')

        self.assertEqual('alice', user_name)
        person = getUtility(IPersonSet).getByName(user_name)
        self.assertEqual(
            'openid-ident', removeSecurityProxy(
                person.account).openid_identifiers.any().identifier)
        self.assertEqual(
            PersonCreationRationale.SOFTWARE_CENTER_PURCHASE,
            person.creation_rationale)
        self.assertEqual(
            "when purchasing an application via Software Center.",
            person.creation_comment)
class TestSoftwareCenterAgentAPI(TestCaseWithFactory):

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestSoftwareCenterAgentAPI, self).setUp()
        self.private_root = getUtility(IPrivateApplication)
        self.sca_api = SoftwareCenterAgentAPI(
            context=self.private_root.softwarecenteragent,
            request=LaunchpadTestRequest())

    def test_provides_interface(self):
        # The view interface is provided.
        self.assertProvides(self.sca_api, ISoftwareCenterAgentAPI)

    def test_getOrCreateSoftwareCenterCustomer(self):
        # The method returns the username of the person, and sets the
        # correct creation rational/comment.
        user_name = self.sca_api.getOrCreateSoftwareCenterCustomer(
            u'openid-ident', '*****@*****.**', 'Joe Blogs')

        self.assertEqual('alice', user_name)
        person = getUtility(IPersonSet).getByName(user_name)
        self.assertEqual(
            'openid-ident',
            removeSecurityProxy(
                person.account).openid_identifiers.any().identifier)
        self.assertEqual(PersonCreationRationale.SOFTWARE_CENTER_PURCHASE,
                         person.creation_rationale)
        self.assertEqual("when purchasing an application via Software Center.",
                         person.creation_comment)
 def setUp(self):
     super(TestSoftwareCenterAgentAPI, self).setUp()
     self.private_root = getUtility(IPrivateApplication)
     self.sca_api = SoftwareCenterAgentAPI(
         context=self.private_root.softwarecenteragent,
         request=LaunchpadTestRequest())
 def setUp(self):
     super(TestSoftwareCenterAgentAPI, self).setUp()
     self.private_root = getUtility(IPrivateApplication)
     self.sca_api = SoftwareCenterAgentAPI(
         context=self.private_root.softwarecenteragent,
         request=LaunchpadTestRequest())