コード例 #1
0
ファイル: test_stack.py プロジェクト: pjwerneck/device-mesh
    def setUp(self):
        super(StackTestCase, self).setUp()

        # create a base user
        self.user = User(email='*****@*****.**', password='******')
        self.user.save()

        stack = Stack(user=self.user, name='acme', description='ACME Corporation Stack')
        stack.save()

        stack = Stack(user=self.user, name='tyrell', description='Tyrell Corporation Stack')
        stack.save()
コード例 #2
0
ファイル: test_user.py プロジェクト: pjwerneck/device-mesh
    def test_cached_auth(self):
        user = User(email='*****@*****.**', password='******')
        user.save()

        self.assertTrue(check_user('*****@*****.**', '123456')[1])

        user.password = '******'
        user.save()

        self.assertFalse(check_user('*****@*****.**', '123456')[1])

        self.assertTrue(check_user('*****@*****.**', 'lero')[1])
コード例 #3
0
ファイル: test_stack.py プロジェクト: pjwerneck/device-mesh
class StackTestCase(BaseTestCase):

    def setUp(self):
        super(StackTestCase, self).setUp()

        # create a base user
        self.user = User(email='*****@*****.**', password='******')
        self.user.save()

        stack = Stack(user=self.user, name='acme', description='ACME Corporation Stack')
        stack.save()

        stack = Stack(user=self.user, name='tyrell', description='Tyrell Corporation Stack')
        stack.save()

    def test_list_stacks(self):
        response = self.client.get('/api/1/stacks', auth=('*****@*****.**', '123456'))

        self.assertEquals(response.status_code, 200)

        data = response.json

        self.assertEquals(data['total_items'], 2)
        self.assertEquals(data['stacks'][0]['name'], 'acme')
        self.assertEquals(data['stacks'][1]['name'], 'tyrell')

    def test_get_stack(self):
        response = self.client.get('/api/1/stacks/acme', auth=('*****@*****.**', '123456'))
        self.assertEquals(response.status_code, 200)

        stack = response.json

        self.assertEquals(stack['name'], 'acme')
        self.assertEquals(stack['description'], 'ACME Corporation Stack')

    def test_create_stack(self):
        response = self.client.put('/api/1/stacks/wey-yu',
                                   json={'description': 'Weyland Yutani Corporation Stack'},
                                   auth=('*****@*****.**', '123456'))
        self.assertEquals(response.status_code, 201)

        stack = response.json

        self.assertEquals(stack['name'], 'wey-yu')
        self.assertEquals(stack['description'], 'Weyland Yutani Corporation Stack')

        obj = Stack.query.filter_by(name='wey-yu').first()

        self.assertTrue(obj is not None)
        self.assertTrue(obj.id is not None)
        self.assertEquals(unicode(obj), u'wey-yu')

    def test_update_stack(self):
        response = self.client.put('/api/1/stacks/acme',
                                   json={'description': 'ACME Corporation Stack Updated'},
                                   auth=('*****@*****.**', '123456'))
        self.assertEquals(response.status_code, 200)

        stack = response.json

        self.assertEquals(stack['name'], 'acme')
        self.assertEquals(stack['description'], 'ACME Corporation Stack Updated')

        obj = Stack.query.filter_by(name='acme').first()

        self.assertTrue(obj is not None)
        self.assertTrue(obj.id is not None)
        self.assertEquals(unicode(obj), u'acme')

    def test_delete_stack(self):
        response = self.client.delete('/api/1/stacks/acme', auth=('*****@*****.**', '123456'))

        self.assertEquals(response.status_code, 204)

        obj = Stack.query.filter_by(name='acme').first()
        assert obj is None