Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

"""Tests that we make sure our export functions work""" 

import json 

import logging 

 

import transaction 

import unittest 

import urllib 

 

from nose.tools import ok_ 

from nose.tools import eq_ 

from pyramid import testing 

 

from bookie.models import DBSession 

from bookie.tests import empty_db 

 

 

LOG = logging.getLogger(__name__) 

API_KEY = None 

 

 

class TestExport(unittest.TestCase): 

    """Test the web export""" 

 

    def _get_good_request(self): 

        """Return the basics for a good add bookmark request""" 

        session = DBSession() 

        prms = { 

            'url': u'http://google.com', 

            'description': u'This is my google desc', 

            'extended': u'And some extended notes about it in full form', 

            'tags': u'python search', 

            'api_key': API_KEY 

        } 

 

        req_params = urllib.urlencode(prms) 

        res = self.testapp.post('/api/v1/admin/bmark?api_key=' + API_KEY, 

                                params=req_params,) 

        session.flush() 

        transaction.commit() 

        return res 

 

    def setUp(self): 

        from pyramid.paster import get_app 

        from bookie.tests import BOOKIE_TEST_INI 

        app = get_app(BOOKIE_TEST_INI, 'bookie') 

        from webtest import TestApp 

        self.testapp = TestApp(app) 

        testing.setUp() 

        global API_KEY 

        res = DBSession.execute( 

            "SELECT api_key FROM users WHERE username = 'admin'").fetchone() 

        API_KEY = str(res['api_key']) 

 

    def tearDown(self): 

        """We need to empty the bmarks table on each run""" 

        testing.tearDown() 

        empty_db() 

 

    def test_export(self): 

        """Test that we can upload/import our test file""" 

        self._get_good_request() 

 

        res = self.testapp.get( 

            '/api/v1/admin/bmarks/export?api_key=' + API_KEY, 

            status=200) 

 

        ok_("google.com" in res.body, 

            msg='Google is in the exported body: ' + res.body) 

        data = json.loads(res.body) 

 

        eq_(1, data['count'], 

            "Should be one result: " + str(data['count']))