Skip to content

Commit

Permalink
#24 Added checking method, test, and fixture for the test
Browse files Browse the repository at this point in the history
  • Loading branch information
korvinos committed Jul 29, 2018
1 parent 74fc381 commit 36252dd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
43 changes: 43 additions & 0 deletions sar_doppler/fixtures/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
{
"model": "catalog.dataset",
"pk": 1,
"fields": {
"entry_id": "cbf2b4ef-18eb-442f-8d62-b595ffcabf2e",
"entry_title": "NONE",
"ISO_topic_category": 14,
"data_center": 1397,
"summary": "NONE",
"source": 1,
"time_coverage_start": "2010-01-01T09:16:19.303Z",
"time_coverage_end": "2010-01-01T09:20:58.487Z",
"geographic_location": 1,
"gcmd_location": null,
"access_constraints": null
}
},

{
"model": "catalog.geographiclocation",
"pk": 1,
"fields": {
"geometry": "SRID=4326;POLYGON ((14.338367 72.40146900000001, 14.3528 72.415314, 14.694107 72.377464, 15.01696 72.34078100000001, 15.351787 72.301929, 15.698588 72.26091099999999, 16.057364 72.217726, 16.428114 72.172374, 16.810839 72.124854, 17.205539 72.07516699999999, 17.612212 72.023313, 18.030861 71.969292, 16.281015 70.47048700000001, 14.653276 68.96455400000001, 13.147642 67.451493, 11.764114 65.931303, 10.502692 64.403986, 9.363376000000001 62.869541, 8.346166 61.327967, 7.451061 59.779266, 6.678063 58.223437, 6.02717 56.660479, 5.77593 56.697133, 5.536665 56.731619, 5.309374 56.763939, 5.094057 56.794091, 4.890715 56.822076, 4.699348 56.847894, 4.519955 56.871545, 4.352536 56.893028, 4.197092 56.912345, 4.039934 56.93109, 4.521744 58.511588, 4.86673 59.410372, 4.469692 58.539143, 3.853777 56.962579, 3.715162 56.980462, 3.579383 56.997799, 3.44644 57.014587, 3.316333 57.030828, 3.189063 57.046521, 3.06463 57.061667, 2.943032 57.076265, 2.824271 57.090315, 2.708346 57.103817, 2.597155 57.116534, 2.591639 57.101329, 2.451453 57.118008, 2.313517 57.134221, 2.177828 57.149966, 2.044389 57.165245, 1.913198 57.180057, 1.784255 57.194401, 1.657562 57.208279, 1.533116 57.221689, 1.41092 57.234633, 1.234939 57.252856, 1.239525 57.268712, 1.211758 57.271721, 1.108429 57.2828, 1.006139 57.293645, 0.904886 57.304257, 0.8046720000000001 57.314634, 0.705495 57.324778, 0.607356 57.334689, 0.510256 57.344365, 0.414193 57.353808, 0.329408 57.362007, 0.32644 57.352463, 0.211383 57.364049, 0.097362 57.37538, -0.015622 57.386457, -0.12757 57.39728, -0.238481 57.407848, -0.348356 57.418162, -0.457194 57.428221, -0.564995 57.438026, -0.67176 57.447576, -0.799615 57.458797, -0.396646 59.084404, 0.060306 60.653234, 0.583575 62.219718, 1.173162 63.783855, 1.829067 65.345645, 2.551289 66.90508800000001, 3.339829 68.462183, 4.194687 70.016932, 5.115862 71.569334, 6.103355 73.119389, 6.347801 73.1037, 6.550879 73.090457, 6.754995 73.07696, 6.960147 73.063209, 7.166335 73.04920300000001, 7.37356 73.034943, 7.581822 73.02042899999999, 7.79112 73.00566000000001, 8.001455 72.99063599999999, 8.212826 72.975358, 8.205273999999999 72.96459900000001, 8.296015000000001 72.957825, 8.477098 72.944125, 8.659219 72.93019099999999, 8.842378 72.91602399999999, 9.026574999999999 72.901623, 9.21181 72.886988, 9.398083 72.87212, 9.585394000000001 72.857018, 9.747961999999999 72.84378100000001, 9.758092 72.85629900000001, 10.093675 72.827957, 10.324172 72.808148, 10.556919 72.787871, 10.791913 72.767128, 11.029157 72.74591700000001, 11.268649 72.72423999999999, 11.510389 72.702095, 11.754379 72.679484, 12.000616 72.65640500000001, 12.249103 72.63285999999999, 12.236463 72.61860900000001, 12.371615 72.60538200000001, 12.589102 72.58380200000001, 12.809425 72.561674, 13.032584 72.538999, 13.25858 72.515775, 13.487412 72.49200500000001, 13.71908 72.467686, 13.953584 72.44282, 14.190925 72.417407, 14.338367 72.40146900000001))"}},

{
"model": "catalog.source", "pk": 1,
"fields": {
"platform": 176,
"instrument": 33,
"specs": ""
}
},

{
"model": "catalog.dataseturi",
"pk": 1,
"fields": {
"uri": "/test/path/to/file/test.gsar",
"dataset": 1
}
}
]
8 changes: 8 additions & 0 deletions sar_doppler/management/commands/base_sar_doppler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.core.management.base import BaseCommand, CommandError
from geospaas.catalog.models import DatasetURI
from datetime import datetime


Expand Down Expand Up @@ -116,3 +117,10 @@ def check_extent_pairs(extent, options, param1, param2):
@staticmethod
def parse_date(timestamp):
return datetime.strptime(timestamp, '%Y-%m-%d')

@staticmethod
def file_in_db(uri):
if DatasetURI.objects.filter(uri=uri):
return True
else:
return False
13 changes: 12 additions & 1 deletion sar_doppler/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.test import TestCase

from management.commands.ingest_sar_doppler import Command as IngestCommand
from management.commands.base_sar_doppler import Command as SARBaseCommand
from managers import DatasetManager, gsar, Doppler
from models import Dataset as SARDAtaset
from django.core.management.base import CommandError
Expand Down Expand Up @@ -178,7 +179,6 @@ def test_get_product_path(self):
self.assertEqual(test_ppath, expected_ppath)



class TestIngestCommand(TestCase):

fixtures = ["vocabularies"]
Expand Down Expand Up @@ -287,3 +287,14 @@ def test_parse_time(self):
test_out1 = IngestCommand.parse_date(timestamp1)
self.assertIsInstance(test_out1, datetime)
self.assertEqual(test_out1, datetime(2010, 1, 1))


class TestBaseCommand(TestCase):
fixtures = ["vocabularies", "data"]

def test_file_in_db(self):
res1 = SARBaseCommand.file_in_db('/test/path/to/file/test.gsar')
self.assertIsInstance(res1, bool)
self.assertTrue(res1)
res2 = SARBaseCommand.file_in_db('/uri/is/not/in/db/test.gsar')
self.assertFalse(res2)

0 comments on commit 36252dd

Please sign in to comment.