Exemplo n.º 1
0
    def test_builder_converts_filters_to_camel_case(self):
        manager = self.store.query(Post, adapter=adapters.DictAdapter())
        url = 'http://test'

        query = manager.filter(Post.author_id == 1).query
        request = manager.store.build_request(url, query)
        self.assertEqual(request.url, 'http://test/?authorId=1')
Exemplo n.º 2
0
 def test_adapters_converts_attributes_to_snake_case(self):
     payload = {
         'authorId': 3,
         'id': 1,
     }
     adapter = adapters.DictAdapter()
     instance = adapter.parse(payload, Post)
     self.assertEqual(instance.author_id, 3)
Exemplo n.º 3
0
    def test_raise_error_on_get_with_multiple_results(self, m):
        m.get(
            'http://api/posts?author=typicode',
            text=json.dumps(self.db['posts']),
            headers={'Content-Type': 'application/json'},
        )

        manager = self.store.query(Post, adapter=adapters.DictAdapter())

        with self.assertRaises(exceptions.MultipleObjectsReturned):
            result = manager.all().get(author='typicode')
Exemplo n.º 4
0
    def test_can_query_single_instance(self, m):
        m.get(
            'http://api/posts?id=1',
            text=json.dumps([self.db['posts'][0]]),
            headers={'Content-Type': 'application/json'},
        )

        manager = self.store.query(Post, adapter=adapters.DictAdapter())

        result = manager.all().get(id=1)

        self.assertDictEqualsModel(self.db['posts'][0], result)
Exemplo n.º 5
0
    def test_can_query_all_instances(self, m):
        m.get(
            'http://api/posts',
            text=json.dumps(self.db['posts']),
            headers={'Content-Type': 'application/json'},
        )

        manager = self.store.query(Post, adapter=adapters.DictAdapter())

        self.assertEqual(manager.count(), len(self.db['posts']))

        results = list(manager.all())

        self.assertEqual(results[0].title, self.db['posts'][0]['title'])
        self.assertEqual(results[1].title, self.db['posts'][1]['title'])

        for i, r in enumerate(results):
            self.assertTrue(isinstance(r, Post))
            self.assertDictEqualsModel(self.db['posts'][i], r)
Exemplo n.º 6
0
 def test_dict_adapter_works_recursively(self):
     payload = {'id': 1, 'author': {'id': 1, 'name': 'Roger'}}
     adapter = adapters.DictAdapter(recursive=True)
     r = adapter.parse(payload, Post)
     self.assertTrue(isinstance(r.author, models.Model))
Exemplo n.º 7
0
    def test_500_error_raise_store_error(self, m):
        m.get('http://api/posts', text='', status_code=500)
        manager = self.store.query(Post, adapter=adapters.DictAdapter())

        with self.assertRaises(exceptions.StoreError):
            result = manager.all().get(id=1)