Skip to content

Commit

Permalink
feat: adding a multi sequence test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaldassin committed Oct 26, 2018
1 parent d55c5d3 commit e19ea87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import json
import os
import urllib
from shutil import copyfile, rmtree
from time import sleep

import requests
from mapillary_messi.assertions.harvest_assertions import HarvestAssertion
from mapillary_messi.db.kafka_base_driver import KafkaBaseDriver
from mapillary_messi.db.psql_base_driver import PsqlMainV2BaseDriver
from mapillary_messi.db.s3_base_driver import S3BaseDriver
from mapillary_messi.fixtures.app_fixture import MapillaryAppFixture
from mapillary_messi.fixtures.user_fixture import UserFixture
from mapillary_messi.matchers.matcher import Eventually
from mapillary_messi.models import User
from testtools import TestCase
from testtools.matchers import NotEquals, Equals

from tests.utils import config

Expand All @@ -27,6 +30,7 @@
API_ENDPOINT = "http://{}".format(os.getenv("API_PROXY_HOST"))
LOGIN_URL = "{}/v2/ua/login?client_id={}".format(API_ENDPOINT, CLIENT_ID)
USER_UPLOAD_URL = API_ENDPOINT + "/v3/users/{}/upload_tokens?client_id={}"
PRIVATE_BUCKET_NAME = os.getenv("AWS_S3_PRIVATE_UPLOAD_BUCKET", "miab_private_images")


class ProcessImagesProviderTestCase(TestCase):
Expand All @@ -41,18 +45,32 @@ def setUp(self):
except Exception as e:
print(e)
self.useFixture(MapillaryAppFixture())
super(ProcessImagesProviderTestCase, self).setUp()

def test_processed_images_are_uploaded_and_harvested(self):
user_a = User(username="mapillary_user")
self.useFixture(UserFixture([user_a]))
self.user = User(username="mapillary_user")
self.useFixture(UserFixture([self.user]))

config.create_config("/mapillary_source/tests/.config/mapillary/config")
config.update_config("/mapillary_source/tests/.config/mapillary/config",
user_a.username, self._get_user_items(user_a))
self.user.username, self._get_user_items(self.user))

super(ProcessImagesProviderTestCase, self).setUp()

def test_processed_images_are_uploaded_and_harvested(self):
copyfile(image_path, new_image_path)
HarvestAssertion(self).assert_test_case(user_a.id)
HarvestAssertion(self).assert_test_case(self.user.id)

def test_process_and_upload_multiple_sequences_images(self):
image1_path = os.path.join(data_dir, 'data/{}'.format("DSC00497.JPG"))
image2_path = os.path.join(data_dir, 'data/{}'.format("DSC00001.JPG"))

new_image1_path = "{}/data/images/{}".format(data_dir, "DSC00497.JPG")
new_image2_path = "{}/data/images/{}".format(data_dir, "DSC00001.JPG")

copyfile(image1_path, new_image1_path)
copyfile(image2_path, new_image2_path)

sql = 'select count(key) from map_images where user_id={}'.format(self.user.id)
self.assertThat(lambda: PsqlMainV2BaseDriver().execute(sql)['count'], Eventually(Equals(2), timeout=180))

def _get_user_items(self, user):
user_items = {}
Expand Down

0 comments on commit e19ea87

Please sign in to comment.