Exemplo n.º 1
0
 def test_can_opt_out_a_member2(self):
     member = Member(
         self.member.account, {
             'member_id': 1000,
             'email': u"*****@*****.**",
             'member_status_id': u"a"
         })
     MockAdapter.expected = True
     self.assertFalse(member.has_opted_out())
     result = member.opt_out()
     self.assertIsNone(result)
     self.assertEquals(member.account.adapter.called, 1)
     self.assertEquals(
         member.account.adapter.call,
         ('PUT', '/members/email/optout/[email protected]', {}))
     self.assertTrue(member.has_opted_out())
Exemplo n.º 2
0
 def test_can_opt_out_a_member2(self):
     member = Member(
         self.member.account,
         {
             'member_id':1000,
             'email':u"*****@*****.**",
             'member_status_id':u"a"
         }
     )
     MockAdapter.expected = True
     self.assertFalse(member.has_opted_out())
     result = member.opt_out()
     self.assertIsNone(result)
     self.assertEquals(member.account.adapter.called, 1)
     self.assertEquals(
         member.account.adapter.call,
         ('PUT', '/members/email/optout/[email protected]', {}))
     self.assertTrue(member.has_opted_out())
Exemplo n.º 3
0
 def test_can_ask_if_member_has_opted_out2(self):
     member = Member(
         self.member.account, {
             'member_id': 1000,
             'email': u"*****@*****.**",
             'member_status_id': u"active"
         })
     has_opted_out = member.has_opted_out()
     self.assertIsInstance(has_opted_out, bool)
     self.assertFalse(has_opted_out)
     self.assertEquals(member.account.adapter.called, 0)
Exemplo n.º 4
0
 def test_can_ask_if_member_has_opted_out2(self):
     member = Member(
         self.member.account,
         {
             'member_id':1000,
             'email':u"*****@*****.**",
             'member_status_id':u"active"
         }
     )
     has_opted_out = member.has_opted_out()
     self.assertIsInstance(has_opted_out, bool)
     self.assertFalse(has_opted_out)
     self.assertEquals(member.account.adapter.called, 0)
Exemplo n.º 5
0
class MemberTest(unittest.TestCase):
    def setUp(self):
        Account.default_adapter = MockAdapter
        self.member = Member(
            Account(account_id="100", public_key="xxx", private_key="yyy"), {
                'member_id':
                1000,
                'email':
                u"*****@*****.**",
                'status':
                u"opt-out",
                'member_status_id':
                u"o",
                'change_type':
                u"u",
                'last_modified_at':
                datetime.now().strftime(SERIALIZED_DATETIME_FORMAT),
                'member_since':
                datetime.now().strftime(SERIALIZED_DATETIME_FORMAT),
                'deleted_at':
                None
            })
        self.member.account.fields._dict = {
            2000: {
                'shortcut_name': u"first_name"
            },
            2001: {
                'shortcut_name': u"last_name"
            }
        }

    def test_can_parse_special_fields_correctly(self):
        self.assertIsInstance(self.member['last_modified_at'], datetime)
        self.assertIsInstance(self.member['member_since'], datetime)
        self.assertIsNone(self.member.get('deleted_at'))

    def test_can_represent_a_member(self):
        self.assertEquals(u"<Member" + repr(self.member._dict) + u">",
                          repr(self.member))

    def test_can_set_valid_field_value_with_dictionary_access(self):
        self.member['first_name'] = u"Emma"
        self.assertEquals(u"Emma", self.member['first_name'])

    def test_group_collection_can_be_accessed(self):
        self.assertIsInstance(self.member.groups, MemberGroupCollection)

    def test_mailing_collection_can_be_accessed(self):
        self.assertIsInstance(self.member.mailings, MemberMailingCollection)

    def test_can_get_opt_out_detail_for_member(self):
        MockAdapter.expected = []
        detail = self.member.get_opt_out_detail()
        self.assertIsInstance(detail, list)
        self.assertEquals(self.member.account.adapter.called, 1)

    def test_can_get_opt_out_detail_for_member2(self):
        MockAdapter.expected = []
        member = Member(self.member.account)
        with self.assertRaises(ex.NoMemberIdError):
            member.get_opt_out_detail()
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_get_opt_out_detail_for_member3(self):
        MockAdapter.expected = []
        self.member['member_status_id'] = MemberStatus.Active
        self.member.get_opt_out_detail()
        self.assertEquals(self.member.account.adapter.called, 0)

    def test_can_ask_if_member_has_opted_out(self):
        has_opted_out = self.member.has_opted_out()
        self.assertIsInstance(has_opted_out, bool)
        self.assertTrue(has_opted_out)
        self.assertEquals(self.member.account.adapter.called, 0)

    def test_can_ask_if_member_has_opted_out2(self):
        member = Member(
            self.member.account, {
                'member_id': 1000,
                'email': u"*****@*****.**",
                'member_status_id': u"active"
            })
        has_opted_out = member.has_opted_out()
        self.assertIsInstance(has_opted_out, bool)
        self.assertFalse(has_opted_out)
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_ask_if_member_has_opted_out3(self):
        member = Member(self.member.account)
        with self.assertRaises(ex.NoMemberStatusError):
            member.has_opted_out()
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_opt_out_a_member(self):
        member = Member(self.member.account)
        with self.assertRaises(ex.NoMemberEmailError):
            member.opt_out()
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_opt_out_a_member2(self):
        member = Member(
            self.member.account, {
                'member_id': 1000,
                'email': u"*****@*****.**",
                'member_status_id': u"a"
            })
        MockAdapter.expected = True
        self.assertFalse(member.has_opted_out())
        result = member.opt_out()
        self.assertIsNone(result)
        self.assertEquals(member.account.adapter.called, 1)
        self.assertEquals(
            member.account.adapter.call,
            ('PUT', '/members/email/optout/[email protected]', {}))
        self.assertTrue(member.has_opted_out())

    def test_can_save_a_member(self):
        mbr = Member(self.member.account, {'email': u"*****@*****.**"})
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }
        result = mbr.save()
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
                          ('POST', '/members/add', {
                              'email': u"*****@*****.**"
                          }))
        self.assertEquals(1024, mbr['member_id'])
        self.assertEquals(MemberStatus.Active, mbr['member_status_id'])

    def test_can_save_a_member2(self):
        mbr = Member(self.member.account, {
            'email': u"*****@*****.**",
            'first_name': u"Emma"
        })
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }
        result = mbr.save()
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call, ('POST', '/members/add', {
            'email': u"*****@*****.**",
            'fields': {
                'first_name': u"Emma"
            }
        }))
        self.assertEquals(1024, mbr['member_id'])
        self.assertEquals(MemberStatus.Active, mbr['member_status_id'])

    def test_can_save_a_member3(self):
        mbr = Member(self.member.account, {
            'email': u"*****@*****.**",
            'first_name': u"Emma"
        })
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }
        result = mbr.save(signup_form_id=u"http://example.com/signup")
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
                          ('POST', '/members/add', {
                              'email': u"*****@*****.**",
                              'fields': {
                                  'first_name': u"Emma"
                              },
                              'signup_form_id': u"http://example.com/signup"
                          }))
        self.assertEquals(1024, mbr['member_id'])
        self.assertEquals(MemberStatus.Active, mbr['member_status_id'])

    def test_can_save_a_member4(self):
        mbr = Member(
            self.member.account, {
                'member_id': 200,
                'email': u"*****@*****.**",
                'first_name': u"Emma",
                'member_status_id': MemberStatus.Active
            })
        MockAdapter.expected = False

        with self.assertRaises(ex.MemberUpdateError):
            mbr.save()
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
                          ('PUT', '/members/200', {
                              'member_id': 200,
                              'email': u"*****@*****.**",
                              'fields': {
                                  'first_name': u"Emma"
                              },
                              'status_to': mbr['member_status_id']
                          }))

    def test_can_save_a_member5(self):
        mbr = Member(
            self.member.account, {
                'member_id': 200,
                'email': u"*****@*****.**",
                'fields': {
                    'first_name': u"Emma"
                },
                'member_status_id': MemberStatus.Active
            })
        MockAdapter.expected = True
        result = mbr.save()
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
                          ('PUT', '/members/200', {
                              'member_id': 200,
                              'email': u"*****@*****.**",
                              'fields': {
                                  'first_name': u"Emma"
                              },
                              'status_to': mbr['member_status_id']
                          }))

    def test_can_save_a_member6(self):
        mbr = Member(self.member.account, {
            'email': u"*****@*****.**",
            'fields': {
                'first_name': u"Emma"
            }
        })
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }

        result = mbr.save(group_ids=[1025])

        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call, ('POST', '/members/add', {
            'email': u"*****@*****.**",
            'fields': {
                'first_name': u"Emma"
            },
            'group_ids': [1025]
        }))

    def test_can_delete_a_member(self):
        mbr = Member(self.member.account, {'email': u"*****@*****.**"})

        with self.assertRaises(ex.NoMemberIdError):
            mbr.delete()
        self.assertEquals(self.member.account.adapter.called, 0)
        self.assertFalse(self.member.is_deleted())

    def test_can_delete_a_member2(self):
        MockAdapter.expected = None
        mbr = Member(
            self.member.account, {
                'member_id': 200,
                'email': u"*****@*****.**",
                'deleted_at':
                datetime.now().strftime(SERIALIZED_DATETIME_FORMAT)
            })

        result = mbr.delete()

        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 0)
        self.assertTrue(mbr.is_deleted())

    def test_can_delete_a_member3(self):
        MockAdapter.expected = True
        mbr = Member(self.member.account, {
            'member_id': 200,
            'email': u"*****@*****.**",
            'deleted_at': None
        })

        result = mbr.delete()

        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
                          ('DELETE', '/members/200', {}))
        self.assertTrue(mbr.is_deleted())
Exemplo n.º 6
0
 def test_can_ask_if_member_has_opted_out3(self):
     member = Member(self.member.account)
     with self.assertRaises(ex.NoMemberStatusError):
         member.has_opted_out()
     self.assertEquals(member.account.adapter.called, 0)
Exemplo n.º 7
0
 def test_can_ask_if_member_has_opted_out3(self):
     member = Member(self.member.account)
     with self.assertRaises(ex.NoMemberStatusError):
         member.has_opted_out()
     self.assertEquals(member.account.adapter.called, 0)
Exemplo n.º 8
0
class MemberTest(unittest.TestCase):
    def setUp(self):
        Account.default_adapter = MockAdapter
        self.member = Member(
            Account(account_id="100", public_key="xxx", private_key="yyy"),
            {
                'member_id':1000,
                'email':u"*****@*****.**",
                'status':u"opt-out",
                'member_status_id':u"o",
                'change_type':u"u",
                'last_modified_at': datetime.now().strftime(SERIALIZED_DATETIME_FORMAT),
                'member_since': datetime.now().strftime(SERIALIZED_DATETIME_FORMAT),
                'deleted_at': None
            }
        )
        self.member.account.fields._dict = {
            2000: {'shortcut_name': u"first_name"},
            2001: {'shortcut_name': u"last_name"}
        }

    def test_can_parse_special_fields_correctly(self):
        self.assertIsInstance(self.member['last_modified_at'], datetime)
        self.assertIsInstance(self.member['member_since'], datetime)
        self.assertIsNone(self.member.get('deleted_at'))

    def test_can_represent_a_member(self):
        self.assertEquals(
            u"<Member" + repr(self.member._dict) + u">",
            repr(self.member))

    def test_can_set_valid_field_value_with_dictionary_access(self):
        self.member['first_name'] = u"Emma"
        self.assertEquals(u"Emma", self.member['first_name'])

    def test_group_collection_can_be_accessed(self):
        self.assertIsInstance(self.member.groups, MemberGroupCollection)

    def test_mailing_collection_can_be_accessed(self):
        self.assertIsInstance(self.member.mailings, MemberMailingCollection)

    def test_can_get_opt_out_detail_for_member(self):
        MockAdapter.expected = []
        detail = self.member.get_opt_out_detail()
        self.assertIsInstance(detail, list)
        self.assertEquals(self.member.account.adapter.called, 1)

    def test_can_get_opt_out_detail_for_member2(self):
        MockAdapter.expected = []
        member = Member(self.member.account)
        with self.assertRaises(ex.NoMemberIdError):
            member.get_opt_out_detail()
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_get_opt_out_detail_for_member3(self):
        MockAdapter.expected = []
        self.member['member_status_id'] = MemberStatus.Active
        self.member.get_opt_out_detail()
        self.assertEquals(self.member.account.adapter.called, 0)

    def test_can_ask_if_member_has_opted_out(self):
        has_opted_out = self.member.has_opted_out()
        self.assertIsInstance(has_opted_out, bool)
        self.assertTrue(has_opted_out)
        self.assertEquals(self.member.account.adapter.called, 0)

    def test_can_ask_if_member_has_opted_out2(self):
        member = Member(
            self.member.account,
            {
                'member_id':1000,
                'email':u"*****@*****.**",
                'member_status_id':u"active"
            }
        )
        has_opted_out = member.has_opted_out()
        self.assertIsInstance(has_opted_out, bool)
        self.assertFalse(has_opted_out)
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_ask_if_member_has_opted_out3(self):
        member = Member(self.member.account)
        with self.assertRaises(ex.NoMemberStatusError):
            member.has_opted_out()
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_opt_out_a_member(self):
        member = Member(self.member.account)
        with self.assertRaises(ex.NoMemberEmailError):
            member.opt_out()
        self.assertEquals(member.account.adapter.called, 0)

    def test_can_opt_out_a_member2(self):
        member = Member(
            self.member.account,
            {
                'member_id':1000,
                'email':u"*****@*****.**",
                'member_status_id':u"a"
            }
        )
        MockAdapter.expected = True
        self.assertFalse(member.has_opted_out())
        result = member.opt_out()
        self.assertIsNone(result)
        self.assertEquals(member.account.adapter.called, 1)
        self.assertEquals(
            member.account.adapter.call,
            ('PUT', '/members/email/optout/[email protected]', {}))
        self.assertTrue(member.has_opted_out())

    def test_can_save_a_member(self):
        mbr = Member(self.member.account, {'email':u"*****@*****.**"})
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }
        result = mbr.save()
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(
            mbr.account.adapter.call,
            ('POST', '/members/add', {'email':u"*****@*****.**"}))
        self.assertEquals(1024, mbr['member_id'])
        self.assertEquals(MemberStatus.Active, mbr['member_status_id'])

    def test_can_save_a_member2(self):
        mbr = Member(
            self.member.account,
            {'email':u"*****@*****.**",
             'first_name':u"Emma"})
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }
        result = mbr.save()
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(
            mbr.account.adapter.call,
            ('POST', '/members/add', {'email':u"*****@*****.**",
                                      'fields': {'first_name': u"Emma"}}))
        self.assertEquals(1024, mbr['member_id'])
        self.assertEquals(MemberStatus.Active, mbr['member_status_id'])

    def test_can_save_a_member3(self):
        mbr = Member(
            self.member.account,
            {'email':u"*****@*****.**",
             'first_name':u"Emma"})
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }
        result = mbr.save(signup_form_id=u"http://example.com/signup")
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(
            mbr.account.adapter.call,
            ('POST', '/members/add', {
                'email':u"*****@*****.**",
                'fields': {'first_name': u"Emma"},
                'signup_form_id': u"http://example.com/signup"}
            ))
        self.assertEquals(1024, mbr['member_id'])
        self.assertEquals(MemberStatus.Active, mbr['member_status_id'])

    def test_can_save_a_member4(self):
        mbr = Member(
            self.member.account,
            {
                'member_id': 200,
                'email':u"*****@*****.**",
                'first_name':u"Emma",
                'member_status_id': MemberStatus.Active
            })
        MockAdapter.expected = False

        with self.assertRaises(ex.MemberUpdateError):
            mbr.save()
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
            (
                'PUT',
                '/members/200',
                {
                    'member_id': 200,
                    'email':u"*****@*****.**",
                    'fields': {'first_name': u"Emma"},
                    'status_to': mbr['member_status_id']
                }
            ))

    def test_can_save_a_member5(self):
        mbr = Member(
            self.member.account,
            {
                'member_id': 200,
                'email':u"*****@*****.**",
                'fields': {'first_name':u"Emma"},
                'member_status_id': MemberStatus.Active
            })
        MockAdapter.expected = True
        result = mbr.save()
        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
            (
                'PUT',
                '/members/200',
                {
                    'member_id': 200,
                    'email':u"*****@*****.**",
                    'fields': {'first_name': u"Emma"},
                    'status_to': mbr['member_status_id']
                }
            ))

    def test_can_save_a_member6(self):
        mbr = Member(
            self.member.account,
            {
                'email':u"*****@*****.**",
                'fields': {'first_name':u"Emma"}
            })
        MockAdapter.expected = {
            'status': u"a",
            'added': True,
            'member_id': 1024
        }

        result = mbr.save(group_ids=[1025])

        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(mbr.account.adapter.call,
            (
                'POST',
                '/members/add',
                {
                    'email':u"*****@*****.**",
                    'fields': {'first_name': u"Emma"},
                    'group_ids': [1025]
                }
            ))

    def test_can_delete_a_member(self):
        mbr = Member(self.member.account, {'email':u"*****@*****.**"})

        with self.assertRaises(ex.NoMemberIdError):
            mbr.delete()
        self.assertEquals(self.member.account.adapter.called, 0)
        self.assertFalse(self.member.is_deleted())

    def test_can_delete_a_member2(self):
        MockAdapter.expected = None
        mbr = Member(
            self.member.account,
            {
                'member_id': 200,
                'email':u"*****@*****.**",
                'deleted_at': datetime.now().strftime(SERIALIZED_DATETIME_FORMAT)
            })

        result = mbr.delete()

        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 0)
        self.assertTrue(mbr.is_deleted())

    def test_can_delete_a_member3(self):
        MockAdapter.expected = True
        mbr = Member(
            self.member.account,
            {
                'member_id': 200,
                'email':u"*****@*****.**",
                'deleted_at': None
            })

        result = mbr.delete()

        self.assertIsNone(result)
        self.assertEquals(mbr.account.adapter.called, 1)
        self.assertEquals(
            mbr.account.adapter.call,
            ('DELETE', '/members/200', {}))
        self.assertTrue(mbr.is_deleted())