Example #1
0
    def it_presents_a_complete_user_record_correctly(self):
        user = User.from_api(get_user())
        eq_('id-from-customers-app', user.user_id)
        eq_('*****@*****.**', user.email)
        eq_('Joe Schmoe', user.name)
        eq_('the-app-id', user.app_id)
        eq_(123, user.session_count)
        eq_(1401970114, calendar.timegm(user.created_at.utctimetuple()))
        eq_(1393613864, calendar.timegm(user.remote_created_at.utctimetuple()))
        eq_(1401970114, calendar.timegm(user.updated_at.utctimetuple()))

        Avatar = define_lightweight_class('avatar', 'Avatar')  # noqa
        Company = define_lightweight_class('company', 'Company')  # noqa
        SocialProfile = define_lightweight_class('social_profile', 'SocialProfile')  # noqa
        LocationData = define_lightweight_class('locaion_data', 'LocationData')  # noqa
        self.assertIsInstance(user.avatar.__class__, Avatar.__class__)
        img_url = 'https://graph.facebook.com/1/picture?width=24&height=24'
        eq_(img_url, user.avatar.image_url)

        self.assertIsInstance(user.companies, list)
        eq_(1, len(user.companies))
        self.assertIsInstance(user.companies[0].__class__, Company.__class__)
        eq_('123', user.companies[0].company_id)
        eq_('bbbbbbbbbbbbbbbbbbbbbbbb', user.companies[0].id)
        eq_('the-app-id', user.companies[0].app_id)
        eq_('Company 1', user.companies[0].name)
        eq_(1390936440, calendar.timegm(
            user.companies[0].remote_created_at.utctimetuple()))
        eq_(1401970114, calendar.timegm(
            user.companies[0].created_at.utctimetuple()))
        eq_(1401970114, calendar.timegm(
            user.companies[0].updated_at.utctimetuple()))
        eq_(1401970113, calendar.timegm(
            user.companies[0].last_request_at.utctimetuple()))
        eq_(0, user.companies[0].monthly_spend)
        eq_(0, user.companies[0].session_count)
        eq_(1, user.companies[0].user_count)
        eq_([], user.companies[0].tag_ids)

        self.assertIsInstance(user.custom_attributes, FlatStore)
        eq_('b', user.custom_attributes["a"])
        eq_(2, user.custom_attributes["b"])

        eq_(4, len(user.social_profiles))
        twitter_account = user.social_profiles[0]
        self.assertIsInstance(twitter_account.__class__, SocialProfile.__class__)
        eq_('twitter', twitter_account.name)
        eq_('abc', twitter_account.username)
        eq_('http://twitter.com/abc', twitter_account.url)

        self.assertIsInstance(user.location_data.__class__, LocationData.__class__)
        eq_('Dublin', user.location_data.city_name)
        eq_('EU', user.location_data.continent_code)
        eq_('Ireland', user.location_data.country_name)
        eq_('90', user.location_data.latitude)
        eq_('10', user.location_data.longitude)
        eq_('IRL', user.location_data.country_code)

        ok_(user.unsubscribed_from_emails)
        eq_("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", user.user_agent_data)  # noqa
Example #2
0
    def it_presents_a_complete_user_record_correctly(self):
        user = User.from_api(get_user())
        eq_('id-from-customers-app', user.user_id)
        eq_('*****@*****.**', user.email)
        eq_('Joe Schmoe', user.name)
        eq_('the-app-id', user.app_id)
        eq_(123, user.session_count)
        eq_(1401970114, calendar.timegm(user.created_at.utctimetuple()))
        eq_(1393613864, calendar.timegm(user.remote_created_at.utctimetuple()))
        eq_(1401970114, calendar.timegm(user.updated_at.utctimetuple()))

        Avatar = define_lightweight_class('avatar', 'Avatar')  # noqa
        Company = define_lightweight_class('company', 'Company')  # noqa
        SocialProfile = define_lightweight_class('social_profile', 'SocialProfile')  # noqa
        LocationData = define_lightweight_class('locaion_data', 'LocationData')  # noqa
        self.assertIsInstance(user.avatar.__class__, Avatar.__class__)
        img_url = 'https://graph.facebook.com/1/picture?width=24&height=24'
        eq_(img_url, user.avatar.image_url)

        self.assertIsInstance(user.companies, list)
        eq_(1, len(user.companies))
        self.assertIsInstance(user.companies[0].__class__, Company.__class__)
        eq_('123', user.companies[0].company_id)
        eq_('bbbbbbbbbbbbbbbbbbbbbbbb', user.companies[0].id)
        eq_('the-app-id', user.companies[0].app_id)
        eq_('Company 1', user.companies[0].name)
        eq_(1390936440, calendar.timegm(
            user.companies[0].remote_created_at.utctimetuple()))
        eq_(1401970114, calendar.timegm(
            user.companies[0].created_at.utctimetuple()))
        eq_(1401970114, calendar.timegm(
            user.companies[0].updated_at.utctimetuple()))
        eq_(1401970113, calendar.timegm(
            user.companies[0].last_request_at.utctimetuple()))
        eq_(0, user.companies[0].monthly_spend)
        eq_(0, user.companies[0].session_count)
        eq_(1, user.companies[0].user_count)
        eq_([], user.companies[0].tag_ids)

        self.assertIsInstance(user.custom_attributes, FlatStore)
        eq_('b', user.custom_attributes["a"])
        eq_(2, user.custom_attributes["b"])

        eq_(4, len(user.social_profiles))
        twitter_account = user.social_profiles[0]
        self.assertIsInstance(twitter_account.__class__, SocialProfile.__class__)
        eq_('twitter', twitter_account.name)
        eq_('abc', twitter_account.username)
        eq_('http://twitter.com/abc', twitter_account.url)

        self.assertIsInstance(user.location_data.__class__, LocationData.__class__)
        eq_('Dublin', user.location_data.city_name)
        eq_('EU', user.location_data.continent_code)
        eq_('Ireland', user.location_data.country_name)
        eq_('90', user.location_data.latitude)
        eq_('10', user.location_data.longitude)
        eq_('IRL', user.location_data.country_code)

        ok_(user.unsubscribed_from_emails)
        eq_("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", user.user_agent_data)  # noqa
Example #3
0
 def it_presents_created_at_and_last_impression_at_as_datetime(self):
     now = datetime.utcnow()
     now_ts = calendar.timegm(now.utctimetuple())
     user = User.from_api(
         {'created_at': now_ts, 'last_impression_at': now_ts})
     self.assertIsInstance(user.created_at, datetime)
     eq_(now.strftime('%c'), user.created_at.strftime('%c'))
     self.assertIsInstance(user.last_impression_at, datetime)
     eq_(now.strftime('%c'), user.last_impression_at.strftime('%c'))
Example #4
0
 def it_presents_created_at_and_last_impression_at_as_datetime(self):
     now = datetime.utcnow()
     now_ts = calendar.timegm(now.utctimetuple())
     user = User.from_api(
         {'created_at': now_ts, 'last_impression_at': now_ts})
     self.assertIsInstance(user.created_at, datetime)
     eq_(now.strftime('%c'), user.created_at.strftime('%c'))
     self.assertIsInstance(user.last_impression_at, datetime)
     eq_(now.strftime('%c'), user.last_impression_at.strftime('%c'))
Example #5
0
    def it_can_convert(self):  # noqa
        lead = Lead.from_api({'user_id': 'contact_id'})
        user = User.from_api({'id': 'user_id'})

        with patch.object(Client, 'post', returns=get_user()) as mock_method:  # noqa
            self.client.leads.convert(lead, user)
            mock_method.assert_called_once_with(
                '/contacts/convert',
                {
                    'contact': {'user_id': lead.user_id},
                    'user': {'id': user.id}
                })
Example #6
0
    def it_rejects_nested_data_structures_in_custom_attributes(self):
        user = User()
        with assert_raises(ValueError):
            user.custom_attributes["thing"] = [1]

        with assert_raises(ValueError):
            user.custom_attributes["thing"] = {1: 2}

        with assert_raises(ValueError):
            user.custom_attributes = {1: {2: 3}}

        user = User.from_api(get_user())
        with assert_raises(ValueError):
            user.custom_attributes["thing"] = [1]
Example #7
0
    def it_rejects_nested_data_structures_in_custom_attributes(self):
        user = User()
        with assert_raises(ValueError):
            user.custom_attributes["thing"] = [1]

        with assert_raises(ValueError):
            user.custom_attributes["thing"] = {1: 2}

        with assert_raises(ValueError):
            user.custom_attributes = {1: {2: 3}}

        user = User.from_api(get_user())
        with assert_raises(ValueError):
            user.custom_attributes["thing"] = [1]
Example #8
0
    def it_can_convert(self):  # noqa
        lead = Lead.from_api({'user_id': 'contact_id'})
        user = User.from_api({'id': 'user_id'})

        with patch.object(Client, 'post',
                          returns=get_user()) as mock_method:  # noqa
            self.client.leads.convert(lead, user)
            mock_method.assert_called_once_with('/contacts/convert', {
                'contact': {
                    'user_id': lead.user_id
                },
                'user': {
                    'id': user.id
                }
            })
Example #9
0
 def it_will_allow_extra_attributes_in_response_from_api(self):
     user = User.from_api({'new_param': 'some value'})
     eq_('some value', user.new_param)
Example #10
0
 def it_will_allow_extra_attributes_in_response_from_api(self):
     user = User.from_api({'new_param': 'some value'})
     eq_('some value', user.new_param)