Ejemplo n.º 1
0
    def test_shows_starred_pastes(self):
        user_email = u'*****@*****.**'

        paste = Paste(id=1234, created=datetime.datetime(2016, 12, 25))
        paste.put()
        paste.create_star_for_author(user_email)

        url = reverse('api_star_list')

        self.login(user_email)

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-type'], 'application/json')
        self.assertEqual(
            response.json(),
            {
                u'stars': [
                    {
                        u'author': None,
                        u'created': u'2016-12-25T00:00:00',
                        u'description': None,
                        u'filename': 'untitled.txt',
                        u'files': [],
                        u'fork': None,
                        u'id': 1234,
                        u'num_files': 0,
                        u'num_lines': 0,
                        u'preview': None,
                        u'url': u'/1234/',
                    },
                ],
            },
        )
Ejemplo n.º 2
0
    def test_star_a_paste_creates_star(self):
        url = reverse('api_star_create')
        paste = Paste(id=1234)
        paste.put()
        data = {'paste': paste.key.id()}

        self.login('*****@*****.**')
        response = self.client.post(url, data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-type'], 'application/json')
        self.assertEqual(
            sorted(response.json()),
            ['author', 'id', 'paste', 'stars'],
        )
Ejemplo n.º 3
0
    def test_unstar_a_paste_removes_star(self):
        user_email = '*****@*****.**'
        self.login(user_email)

        paste = Paste(id=1234)
        paste.put()
        starred = paste.create_star_for_author(user_email)

        self.assertEqual(get_starred_pastes(user_email), [paste])

        data = {'paste': paste.key.id()}

        url = reverse('api_star_delete')
        response = self.client.post(url, data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-type'], 'application/json')
        self.assertEqual(response.json(), {
            'id': starred.key.id(),
            'stars': [],
        })
Ejemplo n.º 4
0
    def test_to_dict_for_forked_paste(self):
        xmas = datetime.datetime(2016, 12, 25)
        orig_key = Paste(id=1234, created=xmas).put()
        fork = Paste(id=5678, created=xmas, fork=orig_key)
        fork.put()

        result = fork.to_dict()

        self.assertEqual(
            result,
            {
                u'author': None,
                u'created': xmas,
                u'description': None,
                u'filename': 'untitled.txt',
                u'files': [],
                u'fork': 1234,
                u'id': 5678,
                u'num_files': 0,
                u'num_lines': 0,
                u'preview': None,
                u'url': u'/5678/',
            },
        )