Esempio n. 1
0
    def test_model_class(self):
        """
        тестируем Model
        """
        for key, value in models_fields.iteritems():
            record = {}
            for field, type in value.iteritems():
                if type.get('type') == 'int':
                    record[field] = random.randrange(100000)
                if type.get('type') == 'chr':
                    record[field] = u''.join([random.choice(string.letters) for i in xrange(20)])
                if type.get('type') == 'date':
                    record[field] = date(random.randrange(1950, 2020), random.randrange(1, 12), random.randrange(1, 28))

            response = self.client.post('/api/%s/' % key, record, format='json')
            self.assertEqual(response.status_code, status.HTTP_200_OK)

        for key, value in models_fields.iteritems():
            response = self.client.get('/api/%s/' % key, format='json')
            self.assertEqual(response.status_code, status.HTTP_200_OK)
            self.assertDictEqual(response.data[0], value)

            for record in response.data[1]:
                dj_object = models_dict[key].objects.get(pk=record.get('id'))
                for field in record.iterkeys():
                    self.assertEqual(record[field], getattr(dj_object, field))
Esempio n. 2
0
    def test_model_class(self):
        """
        тестируем Model
        """
        for key, value in models_fields.iteritems():
            record = {}
            for field, type in value.iteritems():
                if type.get('type') == 'int':
                    record[field] = random.randrange(100000)
                if type.get('type') == 'chr':
                    record[field] = u''.join(
                        [random.choice(string.letters) for i in xrange(20)])
                if type.get('type') == 'date':
                    record[field] = date(random.randrange(1950, 2020),
                                         random.randrange(1, 12),
                                         random.randrange(1, 28))

            response = self.client.post('/api/%s/' % key,
                                        record,
                                        format='json')
            self.assertEqual(response.status_code, status.HTTP_200_OK)

        for key, value in models_fields.iteritems():
            response = self.client.get('/api/%s/' % key, format='json')
            self.assertEqual(response.status_code, status.HTTP_200_OK)
            self.assertDictEqual(response.data[0], value)

            for record in response.data[1]:
                dj_object = models_dict[key].objects.get(pk=record.get('id'))
                for field in record.iterkeys():
                    self.assertEqual(record[field], getattr(dj_object, field))
Esempio n. 3
0
 def setUp(self):
     record = {}
     #insert values
     for key, value in models_fields.iteritems():
         record = {}
         for field, type in value.iteritems():
             if type.get('type') == 'int':
                 record[field] = random.randrange(100000)
             if type.get('type') == 'chr':
                 record[field] = u''.join([random.choice(string.letters) for i in xrange(20)])
             if type.get('type') == 'date':
                 record[field] = date(random.randrange(1950, 2020), random.randrange(1, 12), random.randrange(1, 28))
         rec = models_dict[key](**record)
         rec.save()
         record['pk'] = rec.pk
         self.inserted[key] = record
Esempio n. 4
0
 def setUp(self):
     record = {}
     #insert values
     for key, value in models_fields.iteritems():
         record = {}
         for field, type in value.iteritems():
             if type.get('type') == 'int':
                 record[field] = random.randrange(100000)
             if type.get('type') == 'chr':
                 record[field] = u''.join(
                     [random.choice(string.letters) for i in xrange(20)])
             if type.get('type') == 'date':
                 record[field] = date(random.randrange(1950, 2020),
                                      random.randrange(1, 12),
                                      random.randrange(1, 28))
         rec = models_dict[key](**record)
         rec.save()
         record['pk'] = rec.pk
         self.inserted[key] = record