def test_time_index_length(self): this_year = dt.now().year this_month = dt.now().month this_date = dt.now().day d = Data() t = Transform(json.loads(d.get_object())) r = t.create_time_index() assert r[:4] == str(this_year) assert r[4:6] == str(this_month) assert r[6:8] == str(this_date)
def test_flatten(self): d = Data() t = Transform(d.object) f = t.flatten(t.d) for k, v in f.items(): with pytest.raises(AssertionError): assert isinstance(v, dict)
def test_positive_class_format(self): d = Data() assert isinstance(d.temp, int) assert re.search( "([0-z]{8})-([0-z]{4})-([0-z]{4})-([0-z]{4})-([0-z]{12})", d.id) assert d.temp >= 80 or d.temp <= 100 assert d.type == "Sensor" assert isinstance(uuid.UUID(d.id), uuid.UUID) assert isinstance(datetime.datetime.fromisoformat(d.time), datetime.datetime) assert isinstance(d.object, dict)
def test_init(self): d = Data() assert isinstance(d.object, dict)
def test_time_index_format(self): d = Data() t = Transform(json.loads(d.get_object())) assert re.search("([0-9]{14})", t.create_time_index())
def test_time_index(self): d = Data() print(d) t = Transform(json.loads(d.get_object())) assert isinstance(t.d.get('content'), dict) assert isinstance(t.create_time_index(), str)
def test_flatten_content(self): d = Data() t = Transform(json.loads(d.get_object())) f = t.flatten(t.d) with pytest.raises(KeyError): f['content']
def test_negative_id(self): d = Data() d.id = 1 with pytest.raises(AttributeError): assert isinstance(uuid.UUID(d.id), uuid.UUID)
def test_get_object(self): d = Data() assert isinstance(d.get_object(), str)
def test_change_temp(self, fahrenheit, celsius): d = Data() w = Worker(d.get_object()) assert w.fahrenheit_to_celsius(fahrenheit) == celsius
def test_add_t_works(self): d = Data() w = Worker(d.get_object()) w.add_t() assert isinstance(w.data.get('content').get('temperature_c'), float)
def test_add_t_len(self): d = Data() w = Worker(d.get_object()) w.add_t() assert len(w.data.get('content')) == 3
def test_add_t_content(self): d = Data() w = Worker(d.get_object()) assert isinstance(w.data.get('content'), dict)
def test_worker_format(self): d = Data() w = Worker(d.get_object()) assert isinstance(w.data, dict)