Ejemplo n.º 1
0
    def test_can_set_a_snippets_password(self):
        account = AccountFactory()
        app = ApplicationFactory()
        access_token, _ = generate_tokens(app, account)
        snippet = SnippetFactory(owner=account)
        headers = {
            'HTTP_AUTHORIZATION': f'Bearer {access_token.token}'
        }
        payload = {
            'password1': 'p@ssw0rd!',
            'password2': 'p@ssw0rd!',
        }

        response = self.client.post(reverse('snippets:snippet-set-password', args=[snippet.key]), json.dumps(payload),
                                    **headers,
                                    content_type='application/json')
        snippet.refresh_from_db()

        self.assertTrue(snippet.password)

        response = self.client.get(reverse('snippets:snippet-detail', args=[snippet.key]))
        self.assertEquals(status.HTTP_403_FORBIDDEN, response.status_code)

        response = self.client.get(reverse('snippets:snippet-detail', args=[snippet.key]), **headers)
        self.assertEquals(status.HTTP_200_OK, response.status_code)
Ejemplo n.º 2
0
    def test_it_can_have_a_password(self):
        account = AccountFactory()
        self.snippet.owner = account
        self.snippet.save()

        self.snippet.set_password('p@ssw0rd!')
        snippet = Snippet.objects.get(pk=self.snippet.key)

        self.assertIsNotNone(snippet.password)
        self.assertNotEquals('p@ssw0rd!', snippet.password)
Ejemplo n.º 3
0
    def test_it_can_have_an_owner(self):
        self.assertTrue(hasattr(self.snippet, 'owner'))
        self.assertIsNone(self.snippet.owner)

        account = AccountFactory()
        self.snippet.owner = account
        self.snippet.save()

        snippet = Snippet.objects.get(pk=self.snippet.key)
        self.assertEquals(snippet.owner, account)
Ejemplo n.º 4
0
    def test_a_private_snippet_can_be_accessed_if_the_correct_password_is_given(self):
        snippet = SnippetFactory(owner=AccountFactory())
        snippet.set_password('p@ssw0rd!')
        snippet.save()

        headers = {
            'HTTP_AUTHORIZATION': 'Password p@ssw0rd!'
        }

        response = self.client.get(reverse('snippets:snippet-detail', args=[snippet.key]), **headers)

        self.assertEquals(status.HTTP_200_OK, response.status_code)
Ejemplo n.º 5
0
    def test_creating_a_snippet_while_logged_in_will_assign_the_user_as_the_snippets_owner(self):
        app = ApplicationFactory()
        account = AccountFactory()
        account.set_password('p@ssw0rd!')
        account.save()
        access_token, _ = generate_tokens(app, account)
        headers = {
            'HTTP_AUTHORIZATION': 'Bearer ' + access_token.token
        }
        payload = {
            'title': 'My First C Program',
            'code': '#include <stdio.h>\nint main(){\nreturn 0;\n}',
            'language': 'c',
            'has_line_numbers': True,
        }

        response = self.client.post(reverse('snippets:snippet-list'), payload, **headers)
        snippet = Snippet.objects.first()

        self.assertEquals(status.HTTP_201_CREATED, response.status_code)
        self.assertEquals(account, snippet.owner)
Ejemplo n.º 6
0
    def test_reports_to_fk(self, account):
        dependent = AccountFactory.create(reports_to=account)

        assert account.reports_to is None
        assert dependent.reports_to == account
Ejemplo n.º 7
0
    def setUp(self):
        super(AccountSerializerTestCase, self).setUp()

        self.account = AccountFactory()
Ejemplo n.º 8
0
 def setUp(self):
     AccountFactory.create(tags=('python', ))
     ProjectFactory.create_batch(2, tags=('python', 'golang'))
Ejemplo n.º 9
0
 def setUp(self):
     AccountFactory.create(tags=('python',))
     ProjectFactory.create_batch(2, tags=('python', 'golang'))
Ejemplo n.º 10
0
    def test_reports_to_fk(self, account):
        dependent = AccountFactory.create(reports_to=account)

        assert account.reports_to is None
        assert dependent.reports_to == account
Ejemplo n.º 11
0
 def setUp(self):
     self.account = AccountFactory()