import pytest

from datetime import datetime, timedelta
from innovation_networks.data_gathering.github import get_data, urls


def test_make_url():
    """GitHub Archive URL creation works"""
    day = 6
    year = 1987
    month = 11
    hour = 8

    url = get_data.make_url(year=year,
                            month=month,
                            day=day,
                            hour=hour)
    test_url = "http://data.githubarchive.org/1987-11-06-08.json.gz"
    assert url == test_url


def test_urls():
    """Correct urls are returned for two year period"""
    urls_list = urls()
    test_url = ("http://data.githubarchive.org/{}.json.gz"
                .format((datetime.now() - timedelta(731)).strftime("%Y-%m-%d")))

    assert len(urls_list) == 731
    assert urls_list[0] == test_url


def test_daterange():
    l = (datetime(2016, 6, 6, 0, 0),
         datetime(2016, 6, 7, 0, 0))

    x = get_data.daterange(start_date=datetime(2016, 6, 6),
                           end_date=datetime(2016, 6, 8))

    assert l == tuple(x)



@@ -1,12 +1,22 @@
+import os%0A
 import pytes
@@ -16,16 +16,27 @@
 t pytest
+%0Aimport sys
 %0A%0Afrom d
@@ -136,14 +136,8 @@
 data
-, urls
 %0A%0A%0Ad
@@ -256,17 +256,16 @@
 our = 8%0A
-%0A
     url 
@@ -599,16 +599,25 @@
 _list = 
+get_data.
 urls()%0A 
@@ -755,17 +755,16 @@
 -%25d%22)))%0A
-%0A
     asse
@@ -844,24 +844,57 @@
 aterange():%0A
+    %22%22%22dateranges are correct%22%22%22%0A
     l = (dat
@@ -955,17 +955,16 @@
  0, 0))%0A
-%0A
     x = 
@@ -1073,17 +1073,16 @@
  6, 8))%0A
-%0A
     asse
@@ -1100,8 +1100,234 @@
 le(x)%0A%0A%0A
+def test_filename():%0A    %22%22%22Filenames are correct format%22%22%22%0A    t = %22%7B%7D%22.format('%7B%7D_github_event_data.json'.format(%0A        datetime.now().strftime(%22%25Y%25m%25d%25S%22)))%0A    assert t == get_data.out_file_name('~/').split('/')%5B-1:%5D%5B0%5D%0A

Add test_filename