Exemplo n.º 1
0
def collection_factory(**kw):
    data = {
        'type': amo.COLLECTION_NORMAL,
        'application': amo.FIREFOX.id,
        'name': 'Collection %s' % abs(hash(datetime.now())),
        'description': 'Its a collection %s' % abs(hash(datetime.now())),
        'addon_count': random.randint(200, 2000),
        'subscribers': random.randint(1000, 5000),
        'monthly_subscribers': random.randint(100, 500),
        'weekly_subscribers': random.randint(10, 50),
        'upvotes': random.randint(100, 500),
        'downvotes': random.randint(100, 500),
        'listed': True,
    }
    data.update(kw)
    c = Collection(**data)
    if c.slug is None:
        c.slug = data['name'].replace(' ', '-').lower()
    c.rating = (c.upvotes - c.downvotes) * math.log(c.upvotes + c.downvotes)
    c.created = c.modified = datetime(2011, 11, 11, random.randint(0, 23),
                                      random.randint(0, 59))
    c.save()
    return c
Exemplo n.º 2
0
    def test_barometer(self):
        self.client.get('/')
        jingo.load_helpers()
        collection = Collection(upvotes=1,
                                slug='mccrackin',
                                author=UserProfile(username='******'))
        # Mock logged out.
        c = {
            'request': Mock(path='yermom', GET=Mock(urlencode=lambda: '')),
            'user': Mock(),
            'settings': Mock()
        }
        c['request'].user.is_authenticated.return_value = False
        doc = pq(barometer(c, collection))
        assert doc('form')[0].action == '/en-US/firefox/users/login?to=yermom'

        # Mock logged in.
        c['request'].user.votes.filter.return_value = [Mock(vote=1)]
        c['request'].user.is_authenticated.return_value = True
        barometer(c, collection)
        doc = pq(barometer(c, collection))
        assert doc('form')[0].action == (reverse(
            'collections.vote', args=['clouserw', 'mccrackin', 'up']))
Exemplo n.º 3
0
 def test_is_subscribed(self):
     c = Collection(pk=512)
     c.following.create(user=self.user)
     assert c.is_subscribed(self.user)
Exemplo n.º 4
0
 def test_publishable_by(self):
     c = Collection(pk=512, author=self.other)
     CollectionUser(collection=c, user=self.user).save()
     assert c.publishable_by(self.user)