Exemple #1
0
    def test_retrieve_all_from_instance(self):
        """
        Test that it is possible to retrieve several people from the instance.
        """

        # create the instance, delete contents and load test fixture
        instance_helpers.delete_api_database()
        instance_helpers.load_test_data()
        instance = ApiInstance.objects.create(
            url=instance_helpers.get_api_url())
        self.assertTrue(instance)

        # Tell the instance to sync data
        instance.fetch_all_from_api()

        # check that the persons expected are loaded
        person = Person.objects.get(name='Joe Bloggs')
        self.assertTrue(person)

        self.assertEqual(person.name, 'Joe Bloggs')
        self.assertEqual(person.summary, 'A very nice man')
        self.assertEqual(person.image, 'http://foo.com/joe.jpg')

        # update the api to use a different fixture and check that the update is
        # applied
        instance_helpers.delete_api_database()
        instance_helpers.load_test_data('rename_joe_bloggs')
        instance.fetch_all_from_api()
        renamed = Person.objects.get(pk=person.id)
        self.assertEqual(renamed.name, 'Josh Blaggs')
def popit_load_data(fixture_name='default'):

    """
    Use the mongofixtures CLI tool provided by the pow-mongodb-fixtures package
    used by popit-api to load some test data into db. Don't use the test fixture
    from popit-api though as we don't want changes to that to break our test
    suite.

        https://github.com/powmedia/pow-mongodb-fixtures#cli-usage

    """
    instance_helpers.delete_api_database()
    project_root = os.path.normpath(os.path.join(os.path.dirname(__file__)))
    
    # gather the args for the call
    mongofixtures_path = os.path.join( project_root, 'popit-api-for-testing/node_modules/.bin/mongofixtures' )
    database_name      = instance_helpers.get_api_database_name()
    test_fixtures_path = os.path.join( project_root, 'nuntium/tests/fixtures/%s.js'%fixture_name )

    # Check that the fixture exists
    if not os.path.exists(test_fixtures_path):
        raise Exception("Could not find fixture for %s at %s" % (fixture_name, test_fixtures_path))

    # Hack to deal with bad handling of absolute paths in mongofixtures.
    # Fix: https://github.com/powmedia/pow-mongodb-fixtures/pull/14
    test_fixtures_path = os.path.relpath( test_fixtures_path )

    # Usage: mongofixtures db_name path/to/fixtures.js
    dev_null = open(os.devnull, 'w')
    exit_code = subprocess.call([mongofixtures_path, database_name, test_fixtures_path], stdout=dev_null)
    if exit_code:
        raise Exception("Error loading fixtures for '%s'" % fixture_name)   
    def test_retrieve_all_from_instance(self):
        """
        Test that it is possible to retrieve several people from the instance.
        """
    
        # create the instance, delete contents and load test fixture
        instance_helpers.delete_api_database()
        instance_helpers.load_test_data()
        instance = ApiInstance.objects.create(url=instance_helpers.get_api_url())
        self.assertTrue(instance)
    
        # Tell the instance to sync data
        instance.fetch_all_from_api()
    
        # check that the persons expected are loaded
        person = Person.objects.get(name='Joe Bloggs')
        self.assertTrue(person)

        self.assertEqual(person.name, 'Joe Bloggs')
        self.assertEqual(person.summary, 'A very nice man')
        self.assertEqual(person.image, 'http://foo.com/joe.jpg')

        # update the api to use a different fixture and check that the update is
        # applied
        instance_helpers.delete_api_database()
        instance_helpers.load_test_data('rename_joe_bloggs')
        instance.fetch_all_from_api()
        renamed = Person.objects.get(pk=person.id)
        self.assertEqual(renamed.name, 'Josh Blaggs')
    def test_pagination(self):

        # create the instance, delete contents and load test fixture
        instance_helpers.delete_api_database()
        instance_helpers.load_test_data('too_many_people')
        instance = ApiInstance.objects.create(url=instance_helpers.get_api_url())
        instance.fetch_all_from_api()

        people_fetched = Person.objects.all()

        self.assertEqual(people_fetched.count(), 65)
Exemple #5
0
    def test_pagination(self):

        # create the instance, delete contents and load test fixture
        instance_helpers.delete_api_database()
        instance_helpers.load_test_data('too_many_people')
        instance = ApiInstance.objects.create(
            url=instance_helpers.get_api_url())
        instance.fetch_all_from_api()

        people_fetched = Person.objects.all()

        self.assertEqual(people_fetched.count(), 65)
 def test_retrieve_all_management_command(self):
     
     # create the instance, delete contents and load test fixture
     instance_helpers.delete_api_database()
     instance_helpers.load_test_data()
     ApiInstance.objects.create(url=instance_helpers.get_api_url())
     
     # call the management command to retrieve all
     call_command('popit_retrieve_all')
     
     # check that the persons expected are loaded
     person = Person.objects.get(name='Joe Bloggs')
     self.assertTrue(person)
Exemple #7
0
    def test_retrieve_all_management_command(self):

        # create the instance, delete contents and load test fixture
        instance_helpers.delete_api_database()
        instance_helpers.load_test_data()
        ApiInstance.objects.create(url=instance_helpers.get_api_url())

        # call the management command to retrieve all
        call_command('popit_retrieve_all')

        # check that the persons expected are loaded
        person = Person.objects.get(name='Joe Bloggs')
        self.assertTrue(person)
 def tearDown(self):
     super(AutomaticCreationOfAWriteitInstance, self).tearDown()
     delete_api_database()
 def setUp(self):
     super(AutomaticCreationOfAWriteitInstance, self).setUp()
     delete_api_database()
 def tearDown(self):
     super(AutomaticCreationOfAPopitPerson, self).tearDown()
     delete_api_database()
 def tearDown(self):
     super(AutomaticCreationOfAWriteitInstance, self).tearDown()
     delete_api_database()
 def setUp(self):
     super(AutomaticCreationOfAWriteitInstance, self).setUp()
     delete_api_database()
 def tearDown(self):
     super(AutomaticCreationOfAPopitPerson, self).tearDown()
     delete_api_database()