Example #1
0
 def setUp(self):
     addon = Addon.objects.get(pk=3615)
     self.thread = CommunicationThread(addon=addon)
     user = UserProfile.objects.all()[0]
     self.token = CommunicationThreadToken(thread=self.thread, user=user)
     self.token.modified = datetime.now()
     self.token.use_count = 0
Example #2
0
class TestThreadTokenModel(amo.tests.TestCase):
    fixtures = ['base/addon_3615', 'base/user_999']

    def setUp(self):
        addon = Addon.objects.get(pk=3615)
        self.thread = CommunicationThread(addon=addon)
        user = UserProfile.objects.all()[0]
        self.token = CommunicationThreadToken(thread=self.thread, user=user)
        self.token.modified = datetime.now()
        self.token.use_count = 0

    def test_live_thread_token_is_valid(self):
        """
        Test `is_valid()` when the token is fresh (not expired).
        """
        assert self.token.is_valid()

    def test_expired_thread_token_is_valid(self):
        """
        Test `is_valid()` when the token has expired.
        """
        self.token.modified = self.days_ago(const.THREAD_TOKEN_EXPIRY + 1)
        assert not self.token.is_valid()

    def test_unused_token_is_valid(self):
        """
        Test `is_valid()` when the token is unused.
        """
        assert self.token.is_valid()

    def test_max_used_thread_token_is_valid(self):
        """
        Test `is_valid()` when the token has been fully used.
        """
        self.token.use_count = const.MAX_TOKEN_USE_COUNT
        assert not self.token.is_valid()

    def test_reset_uuid(self):
        """
        Test `reset_uuid()` generates a differ uuid.
        """
        self.thread.save()
        self.token.thread = self.thread
        self.token.save()
        uuid = self.token.uuid
        assert uuid

        self.token.reset_uuid()
        assert self.token.uuid
        assert uuid != self.token.uuid
Example #3
0
class TestThreadTokenModel(amo.tests.TestCase):
    fixtures = ['base/addon_3615', 'base/user_999']

    def setUp(self):
        addon = Addon.objects.get(pk=3615)
        self.thread = CommunicationThread(addon=addon)
        user = UserProfile.objects.all()[0]
        self.token = CommunicationThreadToken(thread=self.thread, user=user)
        self.token.modified = datetime.now()
        self.token.use_count = 0

    def test_live_thread_token_is_valid(self):
        """
        Test `is_valid()` when the token is fresh (not expired).
        """
        assert self.token.is_valid()

    def test_expired_thread_token_is_valid(self):
        """
        Test `is_valid()` when the token has expired.
        """
        self.token.modified = self.days_ago(const.THREAD_TOKEN_EXPIRY + 1)
        assert not self.token.is_valid()

    def test_unused_token_is_valid(self):
        """
        Test `is_valid()` when the token is unused.
        """
        assert self.token.is_valid()

    def test_max_used_thread_token_is_valid(self):
        """
        Test `is_valid()` when the token has been fully used.
        """
        self.token.use_count = const.MAX_TOKEN_USE_COUNT
        assert not self.token.is_valid()

    def test_reset_uuid(self):
        """
        Test `reset_uuid()` generates a differ uuid.
        """
        self.thread.save()
        self.token.thread = self.thread
        self.token.save()
        uuid = self.token.uuid
        assert uuid

        self.token.reset_uuid()
        assert self.token.uuid
        assert uuid != self.token.uuid
Example #4
0
def create_comm_note(app, version, author, body, note_type=comm.NO_ACTION,
                     perms=None):
    """
    Creates a note on an app version's thread.
    Creates a thread if a thread doesn't already exist.
    CC's app's Mozilla contacts to auto-join thread.

    app -- app object.
    version -- app version.
    author -- UserProfile for the note's author.
    body -- string/text for note comment.
    note_type -- integer for note_type (mkt constant), defaults to 0/NO_ACTION
                 (e.g. comm.APPROVAL, comm.REJECTION, comm.NO_ACTION).
    perms -- object of groups to grant permission to, will set flags on Thread.
             (e.g. {'developer': False, 'staff': True}).

    """
    if not waffle.switch_is_active('comm-dashboard'):
        return None, None

    # Dict of {'read_permission_GROUP_TYPE': boolean}.
    # Perm for dev, reviewer, senior_reviewer, moz_contact, staff all True by
    # default.
    perms = perms or {}
    create_perms = dict(('read_permission_%s' % key, has_perm)
                        for key, has_perm in perms.iteritems())

    # Get or create thread w/ custom permissions.
    thread = None
    threads = app.threads.filter(version=version)
    if threads.exists():
        thread = threads[0]
    else:
        # See if user has perms to create thread for this app.
        thread = CommunicationThread(addon=app, version=version,
                                     **create_perms)
        if user_has_perm_thread(thread, author):
            thread.save()
        else:
            raise PermissionDenied

    # Create note.
    note = thread.notes.create(note_type=note_type, body=body, author=author,
                               **create_perms)

    post_create_comm_note(note)

    return thread, note
Example #5
0
 def setUp(self):
     addon = Addon.objects.get(pk=3615)
     self.thread = CommunicationThread(addon=addon)
     user = UserProfile.objects.all()[0]
     self.token = CommunicationThreadToken(thread=self.thread, user=user)
     self.token.modified = datetime.now()
     self.token.use_count = 0