def setUp(self):
     self.member = Member.objects.create_member('root',
                                                '*****@*****.**', 'a')
     self.client = ApiClient(self.member.api_key, self.member.api_secret)
     self.app = App.objects.create(name='test',
                                   description='test',
                                   member=self.member)
class TestDevice(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member('root',
                                                   '*****@*****.**', 'a')
        self.app = App.objects.create(name='test',
                                      description='test',
                                      member=self.member)
        self.client = ApiClient(self.member.api_key, self.member.api_secret)

    def test_signup_with_new_device(self):
        old_count_devices = Device.objects.count()
        old_count_app_devices = self.app.devices.count()

        res = self.client.post('/v1/devices/signup/',
                               params={'app_secret': self.app.app_secret},
                               data={
                                   'device_id': 'aaa',
                                   'device_type': 'ipod',
                                   'os': 0,
                                   'os_version': '7.0',
                               })

        self.assertEqual(200, res.status_code)
        data = json.loads(res.content)

        new_count_devices = Device.objects.count()
        self.assertEqual(old_count_devices + 1, new_count_devices)

        new_count_devices = Device.objects.count()
        self.assertEqual(old_count_devices + 1, new_count_devices)

    def test_signup_with_old_device(self):
        Device.objects.create(token='aaa')

        old_count_devices = Device.objects.count()
        old_count_app_devices = self.app.devices.count()

        res = self.client.post('/v1/devices/signup/',
                               params={'app_secret': self.app.app_secret},
                               data={
                                   'device_id': 'aaa',
                                   'device_type': 'ipod',
                                   'os': 0,
                                   'os_version': '7.0',
                               })

        self.assertEqual(200, res.status_code)
        data = json.loads(res.content)

        new_count_devices = Device.objects.count()
        self.assertEqual(old_count_devices, new_count_devices)
class TestDevice(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member(
            'root', '*****@*****.**', 'a')
        self.app = App.objects.create(
            name='test', description='test', member=self.member)
        self.client = ApiClient(self.member.api_key, self.member.api_secret)

    def test_signup_with_new_device(self):
        old_count_devices = Device.objects.count()
        old_count_app_devices = self.app.devices.count()

        res = self.client.post('/v1/devices/signup/', params={
            'app_secret': self.app.app_secret
        }, data={
            'device_id': 'aaa',
            'device_type': 'ipod',
            'os': 0,
            'os_version': '7.0',
        })

        self.assertEqual(200, res.status_code)
        data = json.loads(res.content)

        new_count_devices = Device.objects.count()
        self.assertEqual(old_count_devices + 1, new_count_devices)

        new_count_devices = Device.objects.count()
        self.assertEqual(old_count_devices + 1, new_count_devices)

    def test_signup_with_old_device(self):
        Device.objects.create(token='aaa')

        old_count_devices = Device.objects.count()
        old_count_app_devices = self.app.devices.count()

        res = self.client.post('/v1/devices/signup/', params={
            'app_secret': self.app.app_secret
        }, data={
            'device_id': 'aaa',
            'device_type': 'ipod',
            'os': 0,
            'os_version': '7.0',
        })

        self.assertEqual(200, res.status_code)
        data = json.loads(res.content)

        new_count_devices = Device.objects.count()
        self.assertEqual(old_count_devices, new_count_devices)
예제 #4
0
class TestCategory(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member(
            'root', '*****@*****.**', 'a')
        self.client = ApiClient(self.member.api_key, self.member.api_secret)

    def test_get_categories(self):
        cat = Category.objects.create(name='test', type=Category.CATEGORY)
        for i in xrange(5):
            Category.objects.create(
                name='subtest-%s' % i, type=Category.SUBCATEGORY, parent=cat)

        res = self.client.get('/sms/v1/categories/', params={
            'time': int(time.time())
        })
        self.assertEquals(200, res.status_code)
        data = json.loads(res.content)

        self.assertEqual(1, len(data))
        cate = data[0]
        self.assertEqual(
            sorted(['id', 'name', 'type', 'data', 'image_url', 'index']),
            sorted(cate.keys()))
        subcates = cate['data']
        self.assertEqual(5, len(subcates))
        for item in subcates:
            self.assertEqual(
                sorted(['id', 'name', 'type', 'image_url', 'index']),
                sorted(item.keys()))
class TestApps(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member('root',
                                                   '*****@*****.**', 'a')
        self.client = ApiClient(self.member.api_key, self.member.api_secret)

    def test_get_related(self):
        for i in xrange(10):
            App.objects.create(name='test%s' % i,
                               description='test',
                               member=self.member)
        res = self.client.get('/v1/apps/related/', params={'os': 0})
        self.assertEquals(200, res.status_code)
        data = json.loads(res.content)

        self.assertEquals(10, len(data))
        for item in data:
            self.assertEquals(
                sorted(['pk', 'name', 'description', 'image_url']),
                sorted(item.keys()))
예제 #6
0
class TestApps(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member(
            'root', '*****@*****.**', 'a')
        self.client = ApiClient(self.member.api_key, self.member.api_secret)

    def test_get_related(self):
        for i in xrange(10):
            App.objects.create(
                name='test%s' % i, description='test',
                member=self.member)
        res = self.client.get('/v1/apps/related/', params={'os': 0})
        self.assertEquals(200, res.status_code)
        data = json.loads(res.content)

        self.assertEquals(10, len(data))
        for item in data:
            self.assertEquals(
                sorted(['pk', 'name', 'description', 'image_url']),
                sorted(item.keys()))
예제 #7
0
class TestApp(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member(
            'root', '*****@*****.**', 'a')
        self.client = ApiClient(self.member.api_key, self.member.api_secret)
        self.app = App.objects.create(
            name='test', description='test', member=self.member)


    def test_get_version(self):
        for i in xrange(0, 10):
            AppVersion.objects.create(app=self.app, version=1, subversion=i)

        res = self.client.get('/v1/app/%s/version/' % self.app.app_secret)
        self.assertEqual(200, res.status_code)
        data = json.loads(res.content)

        self.assertEquals(
                sorted(['version', 'subversion', 'is_force_update', 'download_url']),
                sorted(data.keys()))
        self.assertEquals(1, data['version'])
        self.assertEquals(9, data['subversion'])
예제 #8
0
class TestSubCategory(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member(
            'root', '*****@*****.**', 'a')
        self.client = ApiClient(self.member.api_key, self.member.api_secret)

    def test_get_categories(self):
        cat = Category.objects.create(name='test', type=Category.SUBCATEGORY)
        for i in xrange(5):
            SMSContent.objects.create(
                content='content-%i' % i, votes=i, category=cat)

        res = self.client.get('/sms/v1/subcategory/%s/' % cat.pk, params={
                'time': int(time.time())
            })
        self.assertEquals(200, res.status_code)
        data = json.loads(res.content)

        self.assertEqual(5, len(data))
        for item in data:
            self.assertEqual(
                sorted(['id', 'content', 'votes', 'index']),
                sorted(item.keys()))
class TestApp(FastFixtureTestCase):
    def setUp(self):
        self.member = Member.objects.create_member('root',
                                                   '*****@*****.**', 'a')
        self.client = ApiClient(self.member.api_key, self.member.api_secret)
        self.app = App.objects.create(name='test',
                                      description='test',
                                      member=self.member)

    def test_get_version(self):
        for i in xrange(0, 10):
            AppVersion.objects.create(app=self.app, version=1, subversion=i)

        res = self.client.get('/v1/app/%s/version/' % self.app.app_secret)
        self.assertEqual(200, res.status_code)
        data = json.loads(res.content)

        self.assertEquals(
            sorted(
                ['version', 'subversion', 'is_force_update', 'download_url']),
            sorted(data.keys()))
        self.assertEquals(1, data['version'])
        self.assertEquals(9, data['subversion'])
예제 #10
0
 def setUp(self):
     self.member = Member.objects.create_member(
         'root', '*****@*****.**', 'a')
     self.client = ApiClient(self.member.api_key, self.member.api_secret)
예제 #11
0
 def setUp(self):
     self.member = Member.objects.create_member(
         'root', '*****@*****.**', 'a')
     self.client = ApiClient(self.member.api_key, self.member.api_secret)
     self.app = App.objects.create(
         name='test', description='test', member=self.member)